Merged in feature/removejob (pull request #95)
Remove Job * removejob * rmjob * sync * cleanup * precommit * startslow * startslow * startslow * openapi * clean * test * scripts * littlecleanercmds * mermaid
This commit is contained in:
@@ -30,35 +30,35 @@ func (q *Queries) AddDocumentEntry(ctx context.Context, arg *AddDocumentEntryPar
|
||||
}
|
||||
|
||||
const createDocument = `-- name: CreateDocument :one
|
||||
INSERT INTO documents (jobId, hash) VALUES ($1, $2) RETURNING id
|
||||
INSERT INTO documents (clientId, hash) VALUES ($1, $2) RETURNING id
|
||||
`
|
||||
|
||||
type CreateDocumentParams struct {
|
||||
Jobid pgtype.UUID `db:"jobid"`
|
||||
Hash string `db:"hash"`
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Hash string `db:"hash"`
|
||||
}
|
||||
|
||||
// CreateDocument
|
||||
//
|
||||
// INSERT INTO documents (jobId, hash) VALUES ($1, $2) RETURNING id
|
||||
// INSERT INTO documents (clientId, hash) VALUES ($1, $2) RETURNING id
|
||||
func (q *Queries) CreateDocument(ctx context.Context, arg *CreateDocumentParams) (pgtype.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, createDocument, arg.Jobid, arg.Hash)
|
||||
row := q.db.QueryRow(ctx, createDocument, arg.Clientid, arg.Hash)
|
||||
var id pgtype.UUID
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const getDocument = `-- name: GetDocument :one
|
||||
SELECT id, jobId, hash FROM documents WHERE id = $1 LIMIT 1
|
||||
SELECT id, clientId, hash FROM documents WHERE id = $1 LIMIT 1
|
||||
`
|
||||
|
||||
// GetDocument
|
||||
//
|
||||
// SELECT id, jobId, hash FROM documents WHERE id = $1 LIMIT 1
|
||||
// SELECT id, clientId, hash FROM documents WHERE id = $1 LIMIT 1
|
||||
func (q *Queries) GetDocument(ctx context.Context, id pgtype.UUID) (*Document, error) {
|
||||
row := q.db.QueryRow(ctx, getDocument, id)
|
||||
var i Document
|
||||
err := row.Scan(&i.ID, &i.Jobid, &i.Hash)
|
||||
err := row.Scan(&i.ID, &i.Clientid, &i.Hash)
|
||||
return &i, err
|
||||
}
|
||||
|
||||
@@ -83,27 +83,65 @@ func (q *Queries) GetDocumentEntry(ctx context.Context, documentid pgtype.UUID)
|
||||
}
|
||||
|
||||
const getDocumentIDByHash = `-- name: GetDocumentIDByHash :one
|
||||
SELECT id FROM documents WHERE hash = $1 and jobId = $2
|
||||
SELECT id FROM documents WHERE hash = $1 and clientId = $2
|
||||
`
|
||||
|
||||
type GetDocumentIDByHashParams struct {
|
||||
Hash string `db:"hash"`
|
||||
Jobid pgtype.UUID `db:"jobid"`
|
||||
Hash string `db:"hash"`
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
}
|
||||
|
||||
// GetDocumentIDByHash
|
||||
//
|
||||
// SELECT id FROM documents WHERE hash = $1 and jobId = $2
|
||||
// SELECT id FROM documents WHERE hash = $1 and clientId = $2
|
||||
func (q *Queries) GetDocumentIDByHash(ctx context.Context, arg *GetDocumentIDByHashParams) (pgtype.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, getDocumentIDByHash, arg.Hash, arg.Jobid)
|
||||
row := q.db.QueryRow(ctx, getDocumentIDByHash, arg.Hash, arg.Clientid)
|
||||
var id pgtype.UUID
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const listDocumentsByJobId = `-- name: ListDocumentsByJobId :many
|
||||
const listDocumentIDsBatch = `-- name: ListDocumentIDsBatch :many
|
||||
SELECT id, totalCount FROM listDocumentIDs($1, $2, $3)
|
||||
`
|
||||
|
||||
type ListDocumentIDsBatchParams struct {
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Batchsize int32 `db:"batchsize"`
|
||||
Pageoffset int32 `db:"pageoffset"`
|
||||
}
|
||||
|
||||
type ListDocumentIDsBatchRow struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Totalcount *int64 `db:"totalcount"`
|
||||
}
|
||||
|
||||
// ListDocumentIDsBatch
|
||||
//
|
||||
// SELECT id, totalCount FROM listDocumentIDs($1, $2, $3)
|
||||
func (q *Queries) ListDocumentIDsBatch(ctx context.Context, arg *ListDocumentIDsBatchParams) ([]*ListDocumentIDsBatchRow, error) {
|
||||
rows, err := q.db.Query(ctx, listDocumentIDsBatch, arg.Clientid, arg.Batchsize, arg.Pageoffset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []*ListDocumentIDsBatchRow{}
|
||||
for rows.Next() {
|
||||
var i ListDocumentIDsBatchRow
|
||||
if err := rows.Scan(&i.ID, &i.Totalcount); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, &i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listDocumentsByClientId = `-- name: ListDocumentsByClientId :many
|
||||
WITH docs as (
|
||||
SELECT id from documents where jobId = $1
|
||||
SELECT id from documents where clientId = $1
|
||||
),
|
||||
entries as (
|
||||
SELECT
|
||||
@@ -117,16 +155,16 @@ entries as (
|
||||
SELECT documentId as id, bucket, key from entries WHERE rowNumber = 1
|
||||
`
|
||||
|
||||
type ListDocumentsByJobIdRow struct {
|
||||
type ListDocumentsByClientIdRow struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Bucket string `db:"bucket"`
|
||||
Key string `db:"key"`
|
||||
}
|
||||
|
||||
// ListDocumentsByJobId
|
||||
// ListDocumentsByClientId
|
||||
//
|
||||
// WITH docs as (
|
||||
// SELECT id from documents where jobId = $1
|
||||
// SELECT id from documents where clientId = $1
|
||||
// ),
|
||||
// entries as (
|
||||
// SELECT
|
||||
@@ -138,15 +176,15 @@ type ListDocumentsByJobIdRow struct {
|
||||
// JOIN documentEntries de on d.id = de.documentId
|
||||
// )
|
||||
// SELECT documentId as id, bucket, key from entries WHERE rowNumber = 1
|
||||
func (q *Queries) ListDocumentsByJobId(ctx context.Context, jobid pgtype.UUID) ([]*ListDocumentsByJobIdRow, error) {
|
||||
rows, err := q.db.Query(ctx, listDocumentsByJobId, jobid)
|
||||
func (q *Queries) ListDocumentsByClientId(ctx context.Context, clientid pgtype.UUID) ([]*ListDocumentsByClientIdRow, error) {
|
||||
rows, err := q.db.Query(ctx, listDocumentsByClientId, clientid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []*ListDocumentsByJobIdRow{}
|
||||
items := []*ListDocumentsByClientIdRow{}
|
||||
for rows.Next() {
|
||||
var i ListDocumentsByJobIdRow
|
||||
var i ListDocumentsByClientIdRow
|
||||
if err := rows.Scan(&i.ID, &i.Bucket, &i.Key); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user