// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.26.0 // source: resources.sql package sql import ( "context" "github.com/google/uuid" "github.com/jackc/pgx/v5/pgtype" ) const createResource = `-- name: CreateResource :one INSERT INTO resources( id, owner, parent, name, dir, created, modified ) VALUES ( $1, $2, $3, $4, $5, NOW(), NOW() ) RETURNING id, owner, parent, name, dir, created, modified, deleted, size, etag ` type CreateResourceParams struct { ID uuid.UUID Owner int32 Parent uuid.UUID Name string Dir bool } func (q *Queries) CreateResource(ctx context.Context, arg CreateResourceParams) (Resource, error) { row := q.db.QueryRow(ctx, createResource, arg.ID, arg.Owner, arg.Parent, arg.Name, arg.Dir, ) var i Resource err := row.Scan( &i.ID, &i.Owner, &i.Parent, &i.Name, &i.Dir, &i.Created, &i.Modified, &i.Deleted, &i.Size, &i.Etag, ) return i, err } const deleteRecursive = `-- name: DeleteRecursive :exec WITH RECURSIVE nodes(id, parent) AS ( SELECT r.id, r.parent FROM resources r WHERE r.id = $1::uuid UNION ALL SELECT r.id, r.parent FROM resources r JOIN nodes n on r.parent = n.id WHERE deleted IS NULL ) UPDATE resources SET modified = NOW(), deleted = NOW() WHERE id in (SELECT id FROM nodes) ` func (q *Queries) DeleteRecursive(ctx context.Context, id uuid.UUID) error { _, err := q.db.Exec(ctx, deleteRecursive, id) return err } const hardDeleteRecursive = `-- name: HardDeleteRecursive :many WITH RECURSIVE nodes(id, parent) AS ( SELECT r.id, r.parent FROM resources r WHERE r.id = $1::uuid UNION ALL SELECT r.id, r.parent FROM resources r JOIN nodes n on r.parent = n.id WHERE deleted IS NULL ) DELETE FROM resources WHERE id in (SELECT id FROM nodes) RETURNING id, dir ` type HardDeleteRecursiveRow struct { ID uuid.UUID Dir bool } func (q *Queries) HardDeleteRecursive(ctx context.Context, id uuid.UUID) ([]HardDeleteRecursiveRow, error) { rows, err := q.db.Query(ctx, hardDeleteRecursive, id) if err != nil { return nil, err } defer rows.Close() var items []HardDeleteRecursiveRow for rows.Next() { var i HardDeleteRecursiveRow if err := rows.Scan(&i.ID, &i.Dir); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const resourceById = `-- name: ResourceById :one SELECT id, owner, parent, name, dir, created, modified, deleted, size, etag from resources WHERE id = $1 ` func (q *Queries) ResourceById(ctx context.Context, id uuid.UUID) (Resource, error) { row := q.db.QueryRow(ctx, resourceById, id) var i Resource err := row.Scan( &i.ID, &i.Owner, &i.Parent, &i.Name, &i.Dir, &i.Created, &i.Modified, &i.Deleted, &i.Size, &i.Etag, ) return i, err } const updateResourceContents = `-- name: UpdateResourceContents :exec UPDATE resources SET size = $1, etag = $2, modified = NOW() WHERE id = $3 ` type UpdateResourceContentsParams struct { Size pgtype.Int8 Etag pgtype.Text ID uuid.UUID } func (q *Queries) UpdateResourceContents(ctx context.Context, arg UpdateResourceContentsParams) error { _, err := q.db.Exec(ctx, updateResourceContents, arg.Size, arg.Etag, arg.ID) return err } const updateResourceModified = `-- name: UpdateResourceModified :exec UPDATE resources SET modified = NOW() WHERE id = $1 ` func (q *Queries) UpdateResourceModified(ctx context.Context, id uuid.UUID) error { _, err := q.db.Exec(ctx, updateResourceModified, id) return err } const updateResourceName = `-- name: UpdateResourceName :exec UPDATE resources SET name = CASE WHEN ($1::text = '') THEN name ELSE $1::text END, modified = NOW() WHERE id = $2::uuid ` type UpdateResourceNameParams struct { Name string ID uuid.UUID } func (q *Queries) UpdateResourceName(ctx context.Context, arg UpdateResourceNameParams) error { _, err := q.db.Exec(ctx, updateResourceName, arg.Name, arg.ID) return err } const updateResourceOwner = `-- name: UpdateResourceOwner :exec UPDATE resources SET owner = $1::int, modified = NOW() WHERE id = $2::uuid ` type UpdateResourceOwnerParams struct { Owner int32 ID uuid.UUID } func (q *Queries) UpdateResourceOwner(ctx context.Context, arg UpdateResourceOwnerParams) error { _, err := q.db.Exec(ctx, updateResourceOwner, arg.Owner, arg.ID) return err } const updateResourceParent = `-- name: UpdateResourceParent :exec UPDATE resources SET parent = $1::uuid, modified = NOW() WHERE id = $2::uuid ` type UpdateResourceParentParams struct { Parent uuid.UUID ID uuid.UUID } func (q *Queries) UpdateResourceParent(ctx context.Context, arg UpdateResourceParentParams) error { _, err := q.db.Exec(ctx, updateResourceParent, arg.Parent, arg.ID) return err }