add document service and acitons
This commit is contained in:
@@ -90,6 +90,118 @@ func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (A
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createDocument = `-- name: CreateDocument :one
|
||||
INSERT INTO document (
|
||||
id,
|
||||
kind,
|
||||
owner_id,
|
||||
created_by,
|
||||
parent_id,
|
||||
name,
|
||||
name_key,
|
||||
path,
|
||||
depth,
|
||||
position,
|
||||
head_version_id,
|
||||
metadata,
|
||||
policy_id,
|
||||
visibility,
|
||||
acl_inherit,
|
||||
rev,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
?1,
|
||||
?2,
|
||||
?3,
|
||||
?4,
|
||||
?5,
|
||||
?6,
|
||||
?7,
|
||||
?8,
|
||||
?9,
|
||||
?10,
|
||||
?11,
|
||||
?12,
|
||||
?13,
|
||||
?14,
|
||||
?15,
|
||||
?16,
|
||||
?17,
|
||||
?18
|
||||
)
|
||||
RETURNING id, kind, owner_id, created_by, parent_id, name, name_key, path, depth, position, head_version_id, metadata, policy_id, visibility, acl_inherit, rev, created_at, updated_at, deleted_at, deleted_by, trash_batch
|
||||
`
|
||||
|
||||
type CreateDocumentParams struct {
|
||||
ID ident.UUID
|
||||
Kind string
|
||||
OwnerID ident.UUID
|
||||
CreatedBy ident.UUID
|
||||
ParentID *ident.UUID
|
||||
Name string
|
||||
NameKey string
|
||||
Path string
|
||||
Depth int64
|
||||
Position sql.NullString
|
||||
HeadVersionID *ident.UUID
|
||||
Metadata string
|
||||
PolicyID *ident.UUID
|
||||
Visibility sql.NullString
|
||||
AclInherit int64
|
||||
Rev int64
|
||||
CreatedAt int64
|
||||
UpdatedAt int64
|
||||
}
|
||||
|
||||
func (q *Queries) CreateDocument(ctx context.Context, arg CreateDocumentParams) (Document, error) {
|
||||
row := q.db.QueryRowContext(ctx, createDocument,
|
||||
arg.ID,
|
||||
arg.Kind,
|
||||
arg.OwnerID,
|
||||
arg.CreatedBy,
|
||||
arg.ParentID,
|
||||
arg.Name,
|
||||
arg.NameKey,
|
||||
arg.Path,
|
||||
arg.Depth,
|
||||
arg.Position,
|
||||
arg.HeadVersionID,
|
||||
arg.Metadata,
|
||||
arg.PolicyID,
|
||||
arg.Visibility,
|
||||
arg.AclInherit,
|
||||
arg.Rev,
|
||||
arg.CreatedAt,
|
||||
arg.UpdatedAt,
|
||||
)
|
||||
var i Document
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Kind,
|
||||
&i.OwnerID,
|
||||
&i.CreatedBy,
|
||||
&i.ParentID,
|
||||
&i.Name,
|
||||
&i.NameKey,
|
||||
&i.Path,
|
||||
&i.Depth,
|
||||
&i.Position,
|
||||
&i.HeadVersionID,
|
||||
&i.Metadata,
|
||||
&i.PolicyID,
|
||||
&i.Visibility,
|
||||
&i.AclInherit,
|
||||
&i.Rev,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
&i.DeletedBy,
|
||||
&i.TrashBatch,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createMembership = `-- name: CreateMembership :one
|
||||
|
||||
INSERT INTO membership (
|
||||
@@ -585,6 +697,33 @@ func (q *Queries) GetSessionByTokenHash(ctx context.Context, tokenHash []byte) (
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getStoragePolicy = `-- name: GetStoragePolicy :one
|
||||
|
||||
SELECT id, name, mode, min_remote_replicas, replicate_history, cache_ttl_s, cache_max_bytes, version_retention, created_at
|
||||
FROM storage_policy
|
||||
WHERE id = ?1
|
||||
`
|
||||
|
||||
// ============================================================================
|
||||
// storage_policy
|
||||
// ============================================================================
|
||||
func (q *Queries) GetStoragePolicy(ctx context.Context, id ident.UUID) (StoragePolicy, error) {
|
||||
row := q.db.QueryRowContext(ctx, getStoragePolicy, id)
|
||||
var i StoragePolicy
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Mode,
|
||||
&i.MinRemoteReplicas,
|
||||
&i.ReplicateHistory,
|
||||
&i.CacheTtlS,
|
||||
&i.CacheMaxBytes,
|
||||
&i.VersionRetention,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const incrementFailedAttempts = `-- name: IncrementFailedAttempts :one
|
||||
UPDATE account
|
||||
SET failed_attempts = failed_attempts + 1
|
||||
@@ -697,6 +836,117 @@ func (q *Queries) ListActivePrincipals(ctx context.Context) ([]Principal, error)
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listDocumentChildren = `-- name: ListDocumentChildren :many
|
||||
SELECT id, kind, owner_id, created_by, parent_id, name, name_key, path, depth, position, head_version_id, metadata, policy_id, visibility, acl_inherit, rev, created_at, updated_at, deleted_at, deleted_by, trash_batch
|
||||
FROM document
|
||||
WHERE parent_id = ?1
|
||||
AND deleted_at IS NULL
|
||||
ORDER BY COALESCE(position, ''), name_key
|
||||
`
|
||||
|
||||
func (q *Queries) ListDocumentChildren(ctx context.Context, parentID *ident.UUID) ([]Document, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listDocumentChildren, parentID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Document
|
||||
for rows.Next() {
|
||||
var i Document
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Kind,
|
||||
&i.OwnerID,
|
||||
&i.CreatedBy,
|
||||
&i.ParentID,
|
||||
&i.Name,
|
||||
&i.NameKey,
|
||||
&i.Path,
|
||||
&i.Depth,
|
||||
&i.Position,
|
||||
&i.HeadVersionID,
|
||||
&i.Metadata,
|
||||
&i.PolicyID,
|
||||
&i.Visibility,
|
||||
&i.AclInherit,
|
||||
&i.Rev,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
&i.DeletedBy,
|
||||
&i.TrashBatch,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listDocumentDescendants = `-- name: ListDocumentDescendants :many
|
||||
SELECT id, kind, owner_id, created_by, parent_id, name, name_key, path, depth, position, head_version_id, metadata, policy_id, visibility, acl_inherit, rev, created_at, updated_at, deleted_at, deleted_by, trash_batch
|
||||
FROM document
|
||||
WHERE path LIKE CAST(?1 AS TEXT) || '%'
|
||||
AND id <> ?2
|
||||
ORDER BY depth
|
||||
`
|
||||
|
||||
type ListDocumentDescendantsParams struct {
|
||||
Prefix string
|
||||
RootID ident.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) ListDocumentDescendants(ctx context.Context, arg ListDocumentDescendantsParams) ([]Document, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listDocumentDescendants, arg.Prefix, arg.RootID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Document
|
||||
for rows.Next() {
|
||||
var i Document
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Kind,
|
||||
&i.OwnerID,
|
||||
&i.CreatedBy,
|
||||
&i.ParentID,
|
||||
&i.Name,
|
||||
&i.NameKey,
|
||||
&i.Path,
|
||||
&i.Depth,
|
||||
&i.Position,
|
||||
&i.HeadVersionID,
|
||||
&i.Metadata,
|
||||
&i.PolicyID,
|
||||
&i.Visibility,
|
||||
&i.AclInherit,
|
||||
&i.Rev,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
&i.DeletedBy,
|
||||
&i.TrashBatch,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listGroupMembers = `-- name: ListGroupMembers :many
|
||||
SELECT p.id, p.kind, p.name, p.public_key, p.status, p.successor_id, p.created_at, p.disabled_at
|
||||
FROM membership m
|
||||
@@ -780,6 +1030,59 @@ func (q *Queries) ListGroupMembersWithRole(ctx context.Context, groupID ident.UU
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listLibraries = `-- name: ListLibraries :many
|
||||
SELECT id, kind, owner_id, created_by, parent_id, name, name_key, path, depth, position, head_version_id, metadata, policy_id, visibility, acl_inherit, rev, created_at, updated_at, deleted_at, deleted_by, trash_batch
|
||||
FROM document
|
||||
WHERE parent_id IS NULL
|
||||
AND deleted_at IS NULL
|
||||
ORDER BY name_key
|
||||
`
|
||||
|
||||
func (q *Queries) ListLibraries(ctx context.Context) ([]Document, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listLibraries)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Document
|
||||
for rows.Next() {
|
||||
var i Document
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Kind,
|
||||
&i.OwnerID,
|
||||
&i.CreatedBy,
|
||||
&i.ParentID,
|
||||
&i.Name,
|
||||
&i.NameKey,
|
||||
&i.Path,
|
||||
&i.Depth,
|
||||
&i.Position,
|
||||
&i.HeadVersionID,
|
||||
&i.Metadata,
|
||||
&i.PolicyID,
|
||||
&i.Visibility,
|
||||
&i.AclInherit,
|
||||
&i.Rev,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
&i.DeletedBy,
|
||||
&i.TrashBatch,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listMemberGroups = `-- name: ListMemberGroups :many
|
||||
SELECT p.id, p.kind, p.name, p.public_key, p.status, p.successor_id, p.created_at, p.disabled_at
|
||||
FROM membership m
|
||||
@@ -1085,6 +1388,61 @@ func (q *Queries) LockAccount(ctx context.Context, arg LockAccountParams) (Accou
|
||||
return i, err
|
||||
}
|
||||
|
||||
const moveDocument = `-- name: MoveDocument :one
|
||||
UPDATE document
|
||||
SET parent_id = ?1,
|
||||
path = ?2,
|
||||
depth = ?3,
|
||||
rev = rev + 1,
|
||||
updated_at = ?4
|
||||
WHERE id = ?5
|
||||
AND deleted_at IS NULL
|
||||
RETURNING id, kind, owner_id, created_by, parent_id, name, name_key, path, depth, position, head_version_id, metadata, policy_id, visibility, acl_inherit, rev, created_at, updated_at, deleted_at, deleted_by, trash_batch
|
||||
`
|
||||
|
||||
type MoveDocumentParams struct {
|
||||
ParentID *ident.UUID
|
||||
Path string
|
||||
Depth int64
|
||||
UpdatedAt int64
|
||||
ID ident.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) MoveDocument(ctx context.Context, arg MoveDocumentParams) (Document, error) {
|
||||
row := q.db.QueryRowContext(ctx, moveDocument,
|
||||
arg.ParentID,
|
||||
arg.Path,
|
||||
arg.Depth,
|
||||
arg.UpdatedAt,
|
||||
arg.ID,
|
||||
)
|
||||
var i Document
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Kind,
|
||||
&i.OwnerID,
|
||||
&i.CreatedBy,
|
||||
&i.ParentID,
|
||||
&i.Name,
|
||||
&i.NameKey,
|
||||
&i.Path,
|
||||
&i.Depth,
|
||||
&i.Position,
|
||||
&i.HeadVersionID,
|
||||
&i.Metadata,
|
||||
&i.PolicyID,
|
||||
&i.Visibility,
|
||||
&i.AclInherit,
|
||||
&i.Rev,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
&i.DeletedBy,
|
||||
&i.TrashBatch,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const recordLogin = `-- name: RecordLogin :one
|
||||
UPDATE account
|
||||
SET last_login_at = ?1,
|
||||
@@ -1185,6 +1543,30 @@ func (q *Queries) ResetFailedAttempts(ctx context.Context, principalID ident.UUI
|
||||
return i, err
|
||||
}
|
||||
|
||||
const restoreDocumentBatch = `-- name: RestoreDocumentBatch :execrows
|
||||
UPDATE document
|
||||
SET deleted_at = NULL,
|
||||
deleted_by = NULL,
|
||||
trash_batch = NULL,
|
||||
rev = rev + 1,
|
||||
updated_at = ?1
|
||||
WHERE trash_batch = ?2
|
||||
AND deleted_at IS NOT NULL
|
||||
`
|
||||
|
||||
type RestoreDocumentBatchParams struct {
|
||||
UpdatedAt int64
|
||||
TrashBatch []byte
|
||||
}
|
||||
|
||||
func (q *Queries) RestoreDocumentBatch(ctx context.Context, arg RestoreDocumentBatchParams) (int64, error) {
|
||||
result, err := q.db.ExecContext(ctx, restoreDocumentBatch, arg.UpdatedAt, arg.TrashBatch)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected()
|
||||
}
|
||||
|
||||
const revokeACLEntry = `-- name: RevokeACLEntry :one
|
||||
UPDATE acl_entry
|
||||
SET revoked_at = ?1
|
||||
@@ -1315,6 +1697,39 @@ func (q *Queries) TouchSession(ctx context.Context, arg TouchSessionParams) (Ses
|
||||
return i, err
|
||||
}
|
||||
|
||||
const trashDocumentSubtree = `-- name: TrashDocumentSubtree :execrows
|
||||
UPDATE document
|
||||
SET deleted_at = ?1,
|
||||
deleted_by = ?2,
|
||||
trash_batch = ?3,
|
||||
rev = rev + 1,
|
||||
updated_at = ?4
|
||||
WHERE path LIKE CAST(?5 AS TEXT) || '%'
|
||||
AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
type TrashDocumentSubtreeParams struct {
|
||||
DeletedAt sql.NullInt64
|
||||
DeletedBy *ident.UUID
|
||||
TrashBatch []byte
|
||||
UpdatedAt int64
|
||||
Prefix string
|
||||
}
|
||||
|
||||
func (q *Queries) TrashDocumentSubtree(ctx context.Context, arg TrashDocumentSubtreeParams) (int64, error) {
|
||||
result, err := q.db.ExecContext(ctx, trashDocumentSubtree,
|
||||
arg.DeletedAt,
|
||||
arg.DeletedBy,
|
||||
arg.TrashBatch,
|
||||
arg.UpdatedAt,
|
||||
arg.Prefix,
|
||||
)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected()
|
||||
}
|
||||
|
||||
const unlockAccount = `-- name: UnlockAccount :one
|
||||
UPDATE account
|
||||
SET state = 'active',
|
||||
@@ -1374,6 +1789,84 @@ func (q *Queries) UpdateAccountState(ctx context.Context, arg UpdateAccountState
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateDocumentLocation = `-- name: UpdateDocumentLocation :exec
|
||||
UPDATE document
|
||||
SET path = ?1,
|
||||
depth = ?2,
|
||||
rev = rev + 1,
|
||||
updated_at = ?3
|
||||
WHERE id = ?4
|
||||
`
|
||||
|
||||
type UpdateDocumentLocationParams struct {
|
||||
Path string
|
||||
Depth int64
|
||||
UpdatedAt int64
|
||||
ID ident.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateDocumentLocation(ctx context.Context, arg UpdateDocumentLocationParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateDocumentLocation,
|
||||
arg.Path,
|
||||
arg.Depth,
|
||||
arg.UpdatedAt,
|
||||
arg.ID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateDocumentName = `-- name: UpdateDocumentName :one
|
||||
UPDATE document
|
||||
SET name = ?1,
|
||||
name_key = ?2,
|
||||
rev = rev + 1,
|
||||
updated_at = ?3
|
||||
WHERE id = ?4
|
||||
AND deleted_at IS NULL
|
||||
RETURNING id, kind, owner_id, created_by, parent_id, name, name_key, path, depth, position, head_version_id, metadata, policy_id, visibility, acl_inherit, rev, created_at, updated_at, deleted_at, deleted_by, trash_batch
|
||||
`
|
||||
|
||||
type UpdateDocumentNameParams struct {
|
||||
Name string
|
||||
NameKey string
|
||||
UpdatedAt int64
|
||||
ID ident.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateDocumentName(ctx context.Context, arg UpdateDocumentNameParams) (Document, error) {
|
||||
row := q.db.QueryRowContext(ctx, updateDocumentName,
|
||||
arg.Name,
|
||||
arg.NameKey,
|
||||
arg.UpdatedAt,
|
||||
arg.ID,
|
||||
)
|
||||
var i Document
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Kind,
|
||||
&i.OwnerID,
|
||||
&i.CreatedBy,
|
||||
&i.ParentID,
|
||||
&i.Name,
|
||||
&i.NameKey,
|
||||
&i.Path,
|
||||
&i.Depth,
|
||||
&i.Position,
|
||||
&i.HeadVersionID,
|
||||
&i.Metadata,
|
||||
&i.PolicyID,
|
||||
&i.Visibility,
|
||||
&i.AclInherit,
|
||||
&i.Rev,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
&i.DeletedBy,
|
||||
&i.TrashBatch,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateMembershipRole = `-- name: UpdateMembershipRole :one
|
||||
UPDATE membership
|
||||
SET role = ?1
|
||||
|
||||
@@ -352,6 +352,15 @@ DELETE FROM session
|
||||
WHERE expires_at <= sqlc.arg(now)
|
||||
OR idle_expires_at <= sqlc.arg(now);
|
||||
|
||||
-- ============================================================================
|
||||
-- storage_policy
|
||||
-- ============================================================================
|
||||
|
||||
-- name: GetStoragePolicy :one
|
||||
SELECT *
|
||||
FROM storage_policy
|
||||
WHERE id = sqlc.arg(id);
|
||||
|
||||
-- ============================================================================
|
||||
-- document
|
||||
-- ============================================================================
|
||||
@@ -361,6 +370,118 @@ SELECT *
|
||||
FROM document
|
||||
WHERE id = sqlc.arg(id);
|
||||
|
||||
-- name: CreateDocument :one
|
||||
INSERT INTO document (
|
||||
id,
|
||||
kind,
|
||||
owner_id,
|
||||
created_by,
|
||||
parent_id,
|
||||
name,
|
||||
name_key,
|
||||
path,
|
||||
depth,
|
||||
position,
|
||||
head_version_id,
|
||||
metadata,
|
||||
policy_id,
|
||||
visibility,
|
||||
acl_inherit,
|
||||
rev,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
sqlc.arg(id),
|
||||
sqlc.arg(kind),
|
||||
sqlc.arg(owner_id),
|
||||
sqlc.arg(created_by),
|
||||
sqlc.narg(parent_id),
|
||||
sqlc.arg(name),
|
||||
sqlc.arg(name_key),
|
||||
sqlc.arg(path),
|
||||
sqlc.arg(depth),
|
||||
sqlc.narg(position),
|
||||
sqlc.narg(head_version_id),
|
||||
sqlc.arg(metadata),
|
||||
sqlc.narg(policy_id),
|
||||
sqlc.narg(visibility),
|
||||
sqlc.arg(acl_inherit),
|
||||
sqlc.arg(rev),
|
||||
sqlc.arg(created_at),
|
||||
sqlc.arg(updated_at)
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
-- name: ListDocumentChildren :many
|
||||
SELECT *
|
||||
FROM document
|
||||
WHERE parent_id = sqlc.arg(parent_id)
|
||||
AND deleted_at IS NULL
|
||||
ORDER BY COALESCE(position, ''), name_key;
|
||||
|
||||
-- name: ListLibraries :many
|
||||
SELECT *
|
||||
FROM document
|
||||
WHERE parent_id IS NULL
|
||||
AND deleted_at IS NULL
|
||||
ORDER BY name_key;
|
||||
|
||||
-- name: UpdateDocumentName :one
|
||||
UPDATE document
|
||||
SET name = sqlc.arg(name),
|
||||
name_key = sqlc.arg(name_key),
|
||||
rev = rev + 1,
|
||||
updated_at = sqlc.arg(updated_at)
|
||||
WHERE id = sqlc.arg(id)
|
||||
AND deleted_at IS NULL
|
||||
RETURNING *;
|
||||
|
||||
-- name: MoveDocument :one
|
||||
UPDATE document
|
||||
SET parent_id = sqlc.arg(parent_id),
|
||||
path = sqlc.arg(path),
|
||||
depth = sqlc.arg(depth),
|
||||
rev = rev + 1,
|
||||
updated_at = sqlc.arg(updated_at)
|
||||
WHERE id = sqlc.arg(id)
|
||||
AND deleted_at IS NULL
|
||||
RETURNING *;
|
||||
|
||||
-- name: ListDocumentDescendants :many
|
||||
SELECT *
|
||||
FROM document
|
||||
WHERE path LIKE CAST(sqlc.arg(prefix) AS TEXT) || '%'
|
||||
AND id <> sqlc.arg(root_id)
|
||||
ORDER BY depth;
|
||||
|
||||
-- name: UpdateDocumentLocation :exec
|
||||
UPDATE document
|
||||
SET path = sqlc.arg(path),
|
||||
depth = sqlc.arg(depth),
|
||||
rev = rev + 1,
|
||||
updated_at = sqlc.arg(updated_at)
|
||||
WHERE id = sqlc.arg(id);
|
||||
|
||||
-- name: TrashDocumentSubtree :execrows
|
||||
UPDATE document
|
||||
SET deleted_at = sqlc.arg(deleted_at),
|
||||
deleted_by = sqlc.arg(deleted_by),
|
||||
trash_batch = sqlc.arg(trash_batch),
|
||||
rev = rev + 1,
|
||||
updated_at = sqlc.arg(updated_at)
|
||||
WHERE path LIKE CAST(sqlc.arg(prefix) AS TEXT) || '%'
|
||||
AND deleted_at IS NULL;
|
||||
|
||||
-- name: RestoreDocumentBatch :execrows
|
||||
UPDATE document
|
||||
SET deleted_at = NULL,
|
||||
deleted_by = NULL,
|
||||
trash_batch = NULL,
|
||||
rev = rev + 1,
|
||||
updated_at = sqlc.arg(updated_at)
|
||||
WHERE trash_batch = sqlc.arg(trash_batch)
|
||||
AND deleted_at IS NOT NULL;
|
||||
|
||||
-- ============================================================================
|
||||
-- acl_entry
|
||||
-- ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user