Merged in feature/clientexternalid (pull request #99)
Client External ID * normalizeexternalid * cleanopenapi * cleanopenapi * changingpublic * noprecommit * testing * precommit * processtest * nodb * tests * tests
This commit is contained in:
@@ -139,9 +139,14 @@ func (q *Queries) ListDocumentIDsBatch(ctx context.Context, arg *ListDocumentIDs
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listDocumentsByClientId = `-- name: ListDocumentsByClientId :many
|
||||
WITH docs as (
|
||||
SELECT id from documents where clientId = $1
|
||||
const listDocumentsByClientExternalId = `-- name: ListDocumentsByClientExternalId :many
|
||||
WITH client as (
|
||||
SELECT id from clients where externalId = $1
|
||||
),
|
||||
docs as (
|
||||
SELECT d.id
|
||||
from documents as d
|
||||
JOIN client as c on d.clientId = c.id
|
||||
),
|
||||
entries as (
|
||||
SELECT
|
||||
@@ -155,16 +160,21 @@ entries as (
|
||||
SELECT documentId as id, bucket, key from entries WHERE rowNumber = 1
|
||||
`
|
||||
|
||||
type ListDocumentsByClientIdRow struct {
|
||||
type ListDocumentsByClientExternalIdRow struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Bucket string `db:"bucket"`
|
||||
Key string `db:"key"`
|
||||
}
|
||||
|
||||
// ListDocumentsByClientId
|
||||
// ListDocumentsByClientExternalId
|
||||
//
|
||||
// WITH docs as (
|
||||
// SELECT id from documents where clientId = $1
|
||||
// WITH client as (
|
||||
// SELECT id from clients where externalId = $1
|
||||
// ),
|
||||
// docs as (
|
||||
// SELECT d.id
|
||||
// from documents as d
|
||||
// JOIN client as c on d.clientId = c.id
|
||||
// ),
|
||||
// entries as (
|
||||
// SELECT
|
||||
@@ -176,15 +186,15 @@ type ListDocumentsByClientIdRow struct {
|
||||
// JOIN documentEntries de on d.id = de.documentId
|
||||
// )
|
||||
// SELECT documentId as id, bucket, key from entries WHERE rowNumber = 1
|
||||
func (q *Queries) ListDocumentsByClientId(ctx context.Context, clientid pgtype.UUID) ([]*ListDocumentsByClientIdRow, error) {
|
||||
rows, err := q.db.Query(ctx, listDocumentsByClientId, clientid)
|
||||
func (q *Queries) ListDocumentsByClientExternalId(ctx context.Context, clientid string) ([]*ListDocumentsByClientExternalIdRow, error) {
|
||||
rows, err := q.db.Query(ctx, listDocumentsByClientExternalId, clientid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []*ListDocumentsByClientIdRow{}
|
||||
items := []*ListDocumentsByClientExternalIdRow{}
|
||||
for rows.Next() {
|
||||
var i ListDocumentsByClientIdRow
|
||||
var i ListDocumentsByClientExternalIdRow
|
||||
if err := rows.Scan(&i.ID, &i.Bucket, &i.Key); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user