// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.29.0 // source: collections.sql package db import ( "context" "github.com/google/uuid" "github.com/jackc/pgx/v5/pgtype" ) const countDocuments = `-- name: CountDocuments :one SELECT COUNT(*) FROM core.documents WHERE collection_id = $1 ` func (q *Queries) CountDocuments(ctx context.Context, collectionID uuid.UUID) (int64, error) { row := q.db.QueryRow(ctx, countDocuments, collectionID) var count int64 err := row.Scan(&count) return count, err } const createCollection = `-- name: CreateCollection :one INSERT INTO core.collections ( project_id, slug, name, description, schema, created_by_user_id ) VALUES ( $1, $2, $3, $4, $5, $6 ) RETURNING id, project_id, slug, name, description, schema, created_by_user_id, created_at, updated_at ` type CreateCollectionParams struct { ProjectID uuid.UUID `json:"project_id"` Slug string `json:"slug"` Name string `json:"name"` Description *string `json:"description"` Schema []byte `json:"schema"` CreatedByUserID pgtype.UUID `json:"created_by_user_id"` } func (q *Queries) CreateCollection(ctx context.Context, arg CreateCollectionParams) (CoreCollection, error) { row := q.db.QueryRow(ctx, createCollection, arg.ProjectID, arg.Slug, arg.Name, arg.Description, arg.Schema, arg.CreatedByUserID, ) var i CoreCollection err := row.Scan( &i.ID, &i.ProjectID, &i.Slug, &i.Name, &i.Description, &i.Schema, &i.CreatedByUserID, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const createDocument = `-- name: CreateDocument :one INSERT INTO core.documents ( collection_id, data, created_by_user_id ) VALUES ( $1, $2, $3 ) RETURNING id, collection_id, data, created_by_user_id, created_at, updated_at ` type CreateDocumentParams struct { CollectionID uuid.UUID `json:"collection_id"` Data []byte `json:"data"` CreatedByUserID pgtype.UUID `json:"created_by_user_id"` } func (q *Queries) CreateDocument(ctx context.Context, arg CreateDocumentParams) (CoreDocument, error) { row := q.db.QueryRow(ctx, createDocument, arg.CollectionID, arg.Data, arg.CreatedByUserID) var i CoreDocument err := row.Scan( &i.ID, &i.CollectionID, &i.Data, &i.CreatedByUserID, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const deleteCollection = `-- name: DeleteCollection :exec DELETE FROM core.collections WHERE id = $1 AND project_id = $2 ` type DeleteCollectionParams struct { ID uuid.UUID `json:"id"` ProjectID uuid.UUID `json:"project_id"` } func (q *Queries) DeleteCollection(ctx context.Context, arg DeleteCollectionParams) error { _, err := q.db.Exec(ctx, deleteCollection, arg.ID, arg.ProjectID) return err } const deleteDocument = `-- name: DeleteDocument :exec DELETE FROM core.documents WHERE id = $1 AND collection_id = $2 ` type DeleteDocumentParams struct { ID uuid.UUID `json:"id"` CollectionID uuid.UUID `json:"collection_id"` } func (q *Queries) DeleteDocument(ctx context.Context, arg DeleteDocumentParams) error { _, err := q.db.Exec(ctx, deleteDocument, arg.ID, arg.CollectionID) return err } const getCollectionByID = `-- name: GetCollectionByID :one SELECT id, project_id, slug, name, description, schema, created_by_user_id, created_at, updated_at FROM core.collections WHERE id = $1 ` func (q *Queries) GetCollectionByID(ctx context.Context, id uuid.UUID) (CoreCollection, error) { row := q.db.QueryRow(ctx, getCollectionByID, id) var i CoreCollection err := row.Scan( &i.ID, &i.ProjectID, &i.Slug, &i.Name, &i.Description, &i.Schema, &i.CreatedByUserID, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const getCollectionBySlug = `-- name: GetCollectionBySlug :one SELECT id, project_id, slug, name, description, schema, created_by_user_id, created_at, updated_at FROM core.collections WHERE project_id = $1 AND slug = $2 ` type GetCollectionBySlugParams struct { ProjectID uuid.UUID `json:"project_id"` Slug string `json:"slug"` } func (q *Queries) GetCollectionBySlug(ctx context.Context, arg GetCollectionBySlugParams) (CoreCollection, error) { row := q.db.QueryRow(ctx, getCollectionBySlug, arg.ProjectID, arg.Slug) var i CoreCollection err := row.Scan( &i.ID, &i.ProjectID, &i.Slug, &i.Name, &i.Description, &i.Schema, &i.CreatedByUserID, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const getDocumentByID = `-- name: GetDocumentByID :one SELECT id, collection_id, data, created_by_user_id, created_at, updated_at FROM core.documents WHERE id = $1 AND collection_id = $2 ` type GetDocumentByIDParams struct { ID uuid.UUID `json:"id"` CollectionID uuid.UUID `json:"collection_id"` } func (q *Queries) GetDocumentByID(ctx context.Context, arg GetDocumentByIDParams) (CoreDocument, error) { row := q.db.QueryRow(ctx, getDocumentByID, arg.ID, arg.CollectionID) var i CoreDocument err := row.Scan( &i.ID, &i.CollectionID, &i.Data, &i.CreatedByUserID, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const listCollections = `-- name: ListCollections :many SELECT id, project_id, slug, name, description, schema, created_by_user_id, created_at, updated_at FROM core.collections WHERE project_id = $1 ORDER BY created_at DESC ` func (q *Queries) ListCollections(ctx context.Context, projectID uuid.UUID) ([]CoreCollection, error) { rows, err := q.db.Query(ctx, listCollections, projectID) if err != nil { return nil, err } defer rows.Close() var items []CoreCollection for rows.Next() { var i CoreCollection if err := rows.Scan( &i.ID, &i.ProjectID, &i.Slug, &i.Name, &i.Description, &i.Schema, &i.CreatedByUserID, &i.CreatedAt, &i.UpdatedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const listDocuments = `-- name: ListDocuments :many SELECT id, collection_id, data, created_by_user_id, created_at, updated_at FROM core.documents WHERE collection_id = $1 ORDER BY created_at DESC LIMIT $2 OFFSET $3 ` type ListDocumentsParams struct { CollectionID uuid.UUID `json:"collection_id"` Limit int32 `json:"limit"` Offset int32 `json:"offset"` } func (q *Queries) ListDocuments(ctx context.Context, arg ListDocumentsParams) ([]CoreDocument, error) { rows, err := q.db.Query(ctx, listDocuments, arg.CollectionID, arg.Limit, arg.Offset) if err != nil { return nil, err } defer rows.Close() var items []CoreDocument for rows.Next() { var i CoreDocument if err := rows.Scan( &i.ID, &i.CollectionID, &i.Data, &i.CreatedByUserID, &i.CreatedAt, &i.UpdatedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const updateCollection = `-- name: UpdateCollection :one UPDATE core.collections SET name = $3, description = $4, schema = $5, updated_at = NOW() WHERE id = $1 AND project_id = $2 RETURNING id, project_id, slug, name, description, schema, created_by_user_id, created_at, updated_at ` type UpdateCollectionParams struct { ID uuid.UUID `json:"id"` ProjectID uuid.UUID `json:"project_id"` Name string `json:"name"` Description *string `json:"description"` Schema []byte `json:"schema"` } func (q *Queries) UpdateCollection(ctx context.Context, arg UpdateCollectionParams) (CoreCollection, error) { row := q.db.QueryRow(ctx, updateCollection, arg.ID, arg.ProjectID, arg.Name, arg.Description, arg.Schema, ) var i CoreCollection err := row.Scan( &i.ID, &i.ProjectID, &i.Slug, &i.Name, &i.Description, &i.Schema, &i.CreatedByUserID, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const updateDocument = `-- name: UpdateDocument :one UPDATE core.documents SET data = $3, updated_at = NOW() WHERE id = $1 AND collection_id = $2 RETURNING id, collection_id, data, created_by_user_id, created_at, updated_at ` type UpdateDocumentParams struct { ID uuid.UUID `json:"id"` CollectionID uuid.UUID `json:"collection_id"` Data []byte `json:"data"` } func (q *Queries) UpdateDocument(ctx context.Context, arg UpdateDocumentParams) (CoreDocument, error) { row := q.db.QueryRow(ctx, updateDocument, arg.ID, arg.CollectionID, arg.Data) var i CoreDocument err := row.Scan( &i.ID, &i.CollectionID, &i.Data, &i.CreatedByUserID, &i.CreatedAt, &i.UpdatedAt, ) return i, err }