Merged in feature/preserve-folder-paths (pull request #179)

support folder paths

* support folder paths

* s3 storage docs
This commit is contained in:
Jay Brown
2025-09-05 18:25:31 +00:00
parent 0ad41de26b
commit 730f3ba11a
27 changed files with 8281 additions and 63 deletions
+134 -5
View File
@@ -31,7 +31,7 @@ func (q *Queries) AddDocumentEntry(ctx context.Context, arg *AddDocumentEntryPar
}
const addDocumentUpload = `-- name: AddDocumentUpload :exec
INSERT INTO documentUploads (id, clientId, bucket, key, part, createdAt) VALUES ($1, $2, $3, $4, $5, $6)
INSERT INTO documentUploads (id, clientId, bucket, key, part, createdAt, filename, batch_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
`
type AddDocumentUploadParams struct {
@@ -41,11 +41,13 @@ type AddDocumentUploadParams struct {
Key string `db:"key"`
Part uint16 `db:"part"`
Createdat pgtype.Timestamp `db:"createdat"`
Filename *string `db:"filename"`
BatchID *uuid.UUID `db:"batch_id"`
}
// AddDocumentUpload
//
// INSERT INTO documentUploads (id, clientId, bucket, key, part, createdAt) VALUES ($1, $2, $3, $4, $5, $6)
// INSERT INTO documentUploads (id, clientId, bucket, key, part, createdAt, filename, batch_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
func (q *Queries) AddDocumentUpload(ctx context.Context, arg *AddDocumentUploadParams) error {
_, err := q.db.Exec(ctx, addDocumentUpload,
arg.ID,
@@ -54,25 +56,33 @@ func (q *Queries) AddDocumentUpload(ctx context.Context, arg *AddDocumentUploadP
arg.Key,
arg.Part,
arg.Createdat,
arg.Filename,
arg.BatchID,
)
return err
}
const createDocument = `-- name: CreateDocument :one
INSERT INTO documents (clientId, hash, batch_id) VALUES ($1, $2, $3) RETURNING id
INSERT INTO documents (clientId, hash, batch_id, filename) VALUES ($1, $2, $3, $4) RETURNING id
`
type CreateDocumentParams struct {
Clientid string `db:"clientid"`
Hash string `db:"hash"`
BatchID *uuid.UUID `db:"batch_id"`
Filename *string `db:"filename"`
}
// CreateDocument
//
// INSERT INTO documents (clientId, hash, batch_id) VALUES ($1, $2, $3) RETURNING id
// INSERT INTO documents (clientId, hash, batch_id, filename) VALUES ($1, $2, $3, $4) RETURNING id
func (q *Queries) CreateDocument(ctx context.Context, arg *CreateDocumentParams) (uuid.UUID, error) {
row := q.db.QueryRow(ctx, createDocument, arg.Clientid, arg.Hash, arg.BatchID)
row := q.db.QueryRow(ctx, createDocument,
arg.Clientid,
arg.Hash,
arg.BatchID,
arg.Filename,
)
var id uuid.UUID
err := row.Scan(&id)
return id, err
@@ -209,6 +219,45 @@ func (q *Queries) GetDocumentSummary(ctx context.Context, id uuid.UUID) (*GetDoc
return &i, err
}
const getDocumentUploadByKey = `-- name: GetDocumentUploadByKey :one
SELECT id, clientId, bucket, key, part, createdAt, filename, batch_id FROM documentUploads WHERE bucket = $1 AND key = $2 LIMIT 1
`
type GetDocumentUploadByKeyParams struct {
Bucket string `db:"bucket"`
Key string `db:"key"`
}
type GetDocumentUploadByKeyRow struct {
ID uuid.UUID `db:"id"`
Clientid string `db:"clientid"`
Bucket string `db:"bucket"`
Key string `db:"key"`
Part uint16 `db:"part"`
Createdat pgtype.Timestamp `db:"createdat"`
Filename *string `db:"filename"`
BatchID *uuid.UUID `db:"batch_id"`
}
// GetDocumentUploadByKey
//
// SELECT id, clientId, bucket, key, part, createdAt, filename, batch_id FROM documentUploads WHERE bucket = $1 AND key = $2 LIMIT 1
func (q *Queries) GetDocumentUploadByKey(ctx context.Context, arg *GetDocumentUploadByKeyParams) (*GetDocumentUploadByKeyRow, error) {
row := q.db.QueryRow(ctx, getDocumentUploadByKey, arg.Bucket, arg.Key)
var i GetDocumentUploadByKeyRow
err := row.Scan(
&i.ID,
&i.Clientid,
&i.Bucket,
&i.Key,
&i.Part,
&i.Createdat,
&i.Filename,
&i.BatchID,
)
return &i, err
}
const getDocumentUploadCurrentPart = `-- name: GetDocumentUploadCurrentPart :one
WITH client as (
select clientId from clients where clientId = $1
@@ -305,6 +354,86 @@ func (q *Queries) ListDocumentIDsBatch(ctx context.Context, arg *ListDocumentIDs
return items, nil
}
const listDocumentUploads = `-- name: ListDocumentUploads :many
SELECT id, clientId, bucket, key, part, createdAt, filename, batch_id FROM documentUploads WHERE clientId = $1 ORDER BY createdAt
`
type ListDocumentUploadsRow struct {
ID uuid.UUID `db:"id"`
Clientid string `db:"clientid"`
Bucket string `db:"bucket"`
Key string `db:"key"`
Part uint16 `db:"part"`
Createdat pgtype.Timestamp `db:"createdat"`
Filename *string `db:"filename"`
BatchID *uuid.UUID `db:"batch_id"`
}
// ListDocumentUploads
//
// SELECT id, clientId, bucket, key, part, createdAt, filename, batch_id FROM documentUploads WHERE clientId = $1 ORDER BY createdAt
func (q *Queries) ListDocumentUploads(ctx context.Context, clientid string) ([]*ListDocumentUploadsRow, error) {
rows, err := q.db.Query(ctx, listDocumentUploads, clientid)
if err != nil {
return nil, err
}
defer rows.Close()
items := []*ListDocumentUploadsRow{}
for rows.Next() {
var i ListDocumentUploadsRow
if err := rows.Scan(
&i.ID,
&i.Clientid,
&i.Bucket,
&i.Key,
&i.Part,
&i.Createdat,
&i.Filename,
&i.BatchID,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listDocumentsByBatch = `-- name: ListDocumentsByBatch :many
SELECT id, hash, filename from documents where batch_id = $1
`
type ListDocumentsByBatchRow struct {
ID uuid.UUID `db:"id"`
Hash string `db:"hash"`
Filename *string `db:"filename"`
}
// ListDocumentsByBatch
//
// SELECT id, hash, filename from documents where batch_id = $1
func (q *Queries) ListDocumentsByBatch(ctx context.Context, batchID *uuid.UUID) ([]*ListDocumentsByBatchRow, error) {
rows, err := q.db.Query(ctx, listDocumentsByBatch, batchID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []*ListDocumentsByBatchRow{}
for rows.Next() {
var i ListDocumentsByBatchRow
if err := rows.Scan(&i.ID, &i.Hash, &i.Filename); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listDocumentsByClient = `-- name: ListDocumentsByClient :many
SELECT id, hash from documents where clientId = $1
`