return index on get magifest
This commit is contained in:
+39
-16
@@ -19,12 +19,13 @@ func (db *Database) InsertManifest(ctx context.Context, manifest *descr.Manifest
|
||||
var err error
|
||||
var request string
|
||||
request = `INSERT INTO manifests(id, name, reference, contentType, payload, digest,
|
||||
created_at, updated_at, created_by, updated_by)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)`
|
||||
created_at, updated_at, created_by, updated_by, architecture, os, variant)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)`
|
||||
_, err = db.db.Exec(request, manifest.ID, manifest.Name, manifest.Reference,
|
||||
manifest.ContentType, manifest.Payload, manifest.Digest,
|
||||
manifest.CreatedAt, manifest.UpdatedAt,
|
||||
manifest.CreatedBy, manifest.UpdatedBy)
|
||||
manifest.CreatedBy, manifest.UpdatedBy,
|
||||
manifest.Architecture, manifest.OS, manifest.Variant)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -39,12 +40,14 @@ func (db *Database) InsertManifests(ctx context.Context, manifests []*descr.Mani
|
||||
for _, manifest := range manifests {
|
||||
var request string
|
||||
request = `INSERT INTO manifests(id, name, reference, contentType, payload, digest,
|
||||
created_at, updated_at, created_by, updated_by)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)`
|
||||
created_at, updated_at, created_by, updated_by,
|
||||
architecture, os, variant)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)`
|
||||
_, err = tx.Exec(request, manifest.ID, manifest.Name, manifest.Reference,
|
||||
manifest.ContentType, manifest.Payload, manifest.Digest,
|
||||
manifest.CreatedAt, manifest.UpdatedAt,
|
||||
manifest.CreatedBy, manifest.UpdatedBy)
|
||||
manifest.CreatedBy, manifest.UpdatedBy,
|
||||
manifest.Architecture, manifest.OS, manifest.Variant)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -62,9 +65,10 @@ func (db *Database) UpdateManifest(ctx context.Context, manifest *descr.Manifest
|
||||
var request string
|
||||
// Manifest
|
||||
request = `UPDATE manifests SET contentType = $1, payload = $2, digest = $3, updated_at = $4
|
||||
WHERE name = $5 AND reference = $6`
|
||||
WHERE name = $5 AND reference = $6, architecture = $7, os = $8, variant = $9`
|
||||
_, err = db.db.Exec(request, manifest.ContentType, manifest.Payload, manifest.Digest,
|
||||
manifest.UpdatedAt, manifest.Name, manifest.Reference)
|
||||
manifest.UpdatedAt, manifest.Name, manifest.Reference,
|
||||
manifest.Architecture, manifest.OS, manifest.Variant)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -80,12 +84,13 @@ func (db *Database) InsertManifestWithLayers(ctx context.Context, manifest *desc
|
||||
// Manifest
|
||||
request = `
|
||||
INSERT INTO manifests(id, name, reference, contentType, payload, digest,
|
||||
created_at, updated_at, created_by, updated_by)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);`
|
||||
created_at, updated_at, created_by, updated_by, architecture, os, variant)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13);`
|
||||
_, err = tx.Exec(request, manifest.ID, manifest.Name, manifest.Reference,
|
||||
manifest.ContentType, manifest.Payload, manifest.Digest,
|
||||
manifest.CreatedAt, manifest.UpdatedAt,
|
||||
manifest.CreatedBy, manifest.UpdatedBy)
|
||||
manifest.CreatedBy, manifest.UpdatedBy,
|
||||
manifest.Architecture, manifest.OS, manifest.Variant)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -124,10 +129,11 @@ func (db *Database) UpdateManifestWithBlobs(ctx context.Context, manifest *descr
|
||||
|
||||
// Manifest
|
||||
request = `UPDATE manifests SET contentType = $1, payload = $2, digest = $3, updated_at = $4, updated_by = $5
|
||||
WHERE name = $6 AND reference = $7`
|
||||
WHERE name = $6 AND reference = $7, architecture = $8, os = $9, variant = $10`
|
||||
_, err = tx.Exec(request, manifest.ContentType, manifest.Payload, manifest.Digest,
|
||||
manifest.UpdatedAt, manifest.UpdatedBy,
|
||||
manifest.Name, manifest.Reference)
|
||||
manifest.Name, manifest.Reference,
|
||||
manifest.Architecture, manifest.OS, manifest.Variant)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -202,20 +208,37 @@ func (db *Database) GetManifestByDigest(ctx context.Context, name, digest string
|
||||
return exists, manifest, err
|
||||
}
|
||||
|
||||
func (db *Database) GetManifestByReference(ctx context.Context, name, reference string) (bool, descr.Manifest, error) {
|
||||
func (db *Database) GetManifestsByReference(ctx context.Context, name, reference string) (bool, []descr.Manifest, error) {
|
||||
var err error
|
||||
manifest := descr.Manifest{}
|
||||
exists := false
|
||||
manifests := make([]descr.Manifest, 0)
|
||||
request := `SELECT * FROM manifests WHERE name = $1 AND reference = $2 LIMIT 1`
|
||||
err = db.db.Select(&manifests, request, name, reference)
|
||||
if err != nil {
|
||||
return exists, manifest, err
|
||||
return exists, manifests, err
|
||||
}
|
||||
|
||||
if len(manifests) > 0 {
|
||||
exists = true
|
||||
}
|
||||
return exists, manifests, err
|
||||
}
|
||||
|
||||
func (db *Database) GetManifestsByReferenceArchitecture(ctx context.Context, name, reference, architecture, os, variant string) (bool, descr.Manifest, error) {
|
||||
var err error
|
||||
exists := false
|
||||
manifest := descr.Manifest{}
|
||||
manifests := make([]descr.Manifest, 0)
|
||||
request := `SELECT * FROM manifests WHERE name = $1 AND reference = $2
|
||||
AND architecture = $3 AND os = $4 AND variant = $5 LIMIT 1000`
|
||||
err = db.db.Select(&manifests, request, name, reference, architecture, os, variant)
|
||||
if err != nil {
|
||||
return exists, manifest, err
|
||||
}
|
||||
|
||||
if len(manifests) > 0 {
|
||||
manifest = manifests[0]
|
||||
exists = true
|
||||
}
|
||||
return exists, manifest, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user