// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: query.sql package database import ( "context" "database/sql" "mediarr/ident" ) const createAccount = `-- name: CreateAccount :one INSERT INTO account ( principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at ) VALUES ( ?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11 ) RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at ` type CreateAccountParams struct { PrincipalID ident.UUID Login string LoginKey string PasswordHash sql.NullString PasswordChangedAt sql.NullInt64 MustChangePassword int64 State string FailedAttempts int64 LockedUntil sql.NullInt64 LastLoginAt sql.NullInt64 CreatedAt int64 } // ============================================================================ // account // ============================================================================ func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (Account, error) { row := q.db.QueryRowContext(ctx, createAccount, arg.PrincipalID, arg.Login, arg.LoginKey, arg.PasswordHash, arg.PasswordChangedAt, arg.MustChangePassword, arg.State, arg.FailedAttempts, arg.LockedUntil, arg.LastLoginAt, arg.CreatedAt, ) var i Account err := row.Scan( &i.PrincipalID, &i.Login, &i.LoginKey, &i.PasswordHash, &i.PasswordChangedAt, &i.MustChangePassword, &i.State, &i.FailedAttempts, &i.LockedUntil, &i.LastLoginAt, &i.CreatedAt, ) return i, err } const createBlob = `-- name: CreateBlob :exec INSERT INTO blob ( root, size, state, role, unit_size, tree_state, encryption, created_at ) VALUES ( ?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8 ) ` type CreateBlobParams struct { Root []byte Size int64 State string Role string UnitSize int64 TreeState string Encryption string CreatedAt int64 } func (q *Queries) CreateBlob(ctx context.Context, arg CreateBlobParams) error { _, err := q.db.ExecContext(ctx, createBlob, arg.Root, arg.Size, arg.State, arg.Role, arg.UnitSize, arg.TreeState, arg.Encryption, arg.CreatedAt, ) return err } const createBlobLocation = `-- name: CreateBlobLocation :exec INSERT INTO blob_location ( root, backend_id, locator, state, created_at ) VALUES ( ?1, ?2, ?3, ?4, ?5 ) ` type CreateBlobLocationParams struct { Root []byte BackendID ident.UUID Locator string State string CreatedAt int64 } func (q *Queries) CreateBlobLocation(ctx context.Context, arg CreateBlobLocationParams) error { _, err := q.db.ExecContext(ctx, createBlobLocation, arg.Root, arg.BackendID, arg.Locator, arg.State, arg.CreatedAt, ) return 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 createDocumentVersion = `-- name: CreateDocumentVersion :one INSERT INTO document_version ( id, document_id, seq, content_root, size, mime, author_id, device_id, origin, message, pinned, created_at ) VALUES ( ?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12 ) RETURNING id, document_id, seq, content_root, size, mime, author_id, device_id, origin, message, pinned, content_purged_at, created_at ` type CreateDocumentVersionParams struct { ID ident.UUID DocumentID ident.UUID Seq int64 ContentRoot []byte Size int64 Mime sql.NullString AuthorID ident.UUID DeviceID *ident.UUID Origin string Message sql.NullString Pinned int64 CreatedAt int64 } func (q *Queries) CreateDocumentVersion(ctx context.Context, arg CreateDocumentVersionParams) (DocumentVersion, error) { row := q.db.QueryRowContext(ctx, createDocumentVersion, arg.ID, arg.DocumentID, arg.Seq, arg.ContentRoot, arg.Size, arg.Mime, arg.AuthorID, arg.DeviceID, arg.Origin, arg.Message, arg.Pinned, arg.CreatedAt, ) var i DocumentVersion err := row.Scan( &i.ID, &i.DocumentID, &i.Seq, &i.ContentRoot, &i.Size, &i.Mime, &i.AuthorID, &i.DeviceID, &i.Origin, &i.Message, &i.Pinned, &i.ContentPurgedAt, &i.CreatedAt, ) return i, err } const createMembership = `-- name: CreateMembership :one INSERT INTO membership ( group_id, member_id, role, created_at ) VALUES ( ?1, ?2, ?3, ?4 ) RETURNING group_id, member_id, role, created_at ` type CreateMembershipParams struct { GroupID ident.UUID MemberID ident.UUID Role string CreatedAt int64 } // ============================================================================ // membership // ============================================================================ func (q *Queries) CreateMembership(ctx context.Context, arg CreateMembershipParams) (Membership, error) { row := q.db.QueryRowContext(ctx, createMembership, arg.GroupID, arg.MemberID, arg.Role, arg.CreatedAt, ) var i Membership err := row.Scan( &i.GroupID, &i.MemberID, &i.Role, &i.CreatedAt, ) return i, err } const createPrincipal = `-- name: CreatePrincipal :one INSERT INTO principal ( id, kind, name, public_key, status, successor_id, created_at, disabled_at ) VALUES ( ?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8 ) RETURNING id, kind, name, public_key, status, successor_id, created_at, disabled_at ` type CreatePrincipalParams struct { ID ident.UUID Kind string Name string PublicKey []byte Status string SuccessorID *ident.UUID CreatedAt int64 DisabledAt sql.NullInt64 } // ============================================================================ // principal // ============================================================================ func (q *Queries) CreatePrincipal(ctx context.Context, arg CreatePrincipalParams) (Principal, error) { row := q.db.QueryRowContext(ctx, createPrincipal, arg.ID, arg.Kind, arg.Name, arg.PublicKey, arg.Status, arg.SuccessorID, arg.CreatedAt, arg.DisabledAt, ) var i Principal err := row.Scan( &i.ID, &i.Kind, &i.Name, &i.PublicKey, &i.Status, &i.SuccessorID, &i.CreatedAt, &i.DisabledAt, ) return i, err } const createSession = `-- name: CreateSession :one INSERT INTO session ( id, token_hash, principal_id, kind, label, user_agent, ip_prefix, created_at, last_seen_at, expires_at, idle_expires_at ) VALUES ( ?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11 ) RETURNING id, token_hash, principal_id, kind, label, user_agent, ip_prefix, created_at, last_seen_at, expires_at, idle_expires_at, revoked_at ` type CreateSessionParams struct { ID ident.UUID TokenHash []byte PrincipalID ident.UUID Kind string Label sql.NullString UserAgent sql.NullString IpPrefix sql.NullString CreatedAt int64 LastSeenAt int64 ExpiresAt int64 IdleExpiresAt int64 } // ============================================================================ // session // ============================================================================ func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) (Session, error) { row := q.db.QueryRowContext(ctx, createSession, arg.ID, arg.TokenHash, arg.PrincipalID, arg.Kind, arg.Label, arg.UserAgent, arg.IpPrefix, arg.CreatedAt, arg.LastSeenAt, arg.ExpiresAt, arg.IdleExpiresAt, ) var i Session err := row.Scan( &i.ID, &i.TokenHash, &i.PrincipalID, &i.Kind, &i.Label, &i.UserAgent, &i.IpPrefix, &i.CreatedAt, &i.LastSeenAt, &i.ExpiresAt, &i.IdleExpiresAt, &i.RevokedAt, ) return i, err } const createStagingItem = `-- name: CreateStagingItem :exec INSERT INTO staging_item ( id, origin, job_ref, locator, size, state, created_at, updated_at ) VALUES ( ?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8 ) ` type CreateStagingItemParams struct { ID ident.UUID Origin string JobRef sql.NullString Locator string Size sql.NullInt64 State string CreatedAt int64 UpdatedAt int64 } // ============================================================================ // staging_item // ============================================================================ func (q *Queries) CreateStagingItem(ctx context.Context, arg CreateStagingItemParams) error { _, err := q.db.ExecContext(ctx, createStagingItem, arg.ID, arg.Origin, arg.JobRef, arg.Locator, arg.Size, arg.State, arg.CreatedAt, arg.UpdatedAt, ) return err } const createStorageBackend = `-- name: CreateStorageBackend :exec INSERT INTO storage_backend ( id, kind, name, config, enabled, state, created_at ) VALUES ( ?1, ?2, ?3, ?4, ?5, ?6, ?7 ) ` type CreateStorageBackendParams struct { ID ident.UUID Kind string Name string Config string Enabled int64 State string CreatedAt int64 } func (q *Queries) CreateStorageBackend(ctx context.Context, arg CreateStorageBackendParams) error { _, err := q.db.ExecContext(ctx, createStorageBackend, arg.ID, arg.Kind, arg.Name, arg.Config, arg.Enabled, arg.State, arg.CreatedAt, ) return err } const deleteAccount = `-- name: DeleteAccount :exec DELETE FROM account WHERE principal_id = ?1 ` func (q *Queries) DeleteAccount(ctx context.Context, principalID ident.UUID) error { _, err := q.db.ExecContext(ctx, deleteAccount, principalID) return err } const deleteBlob = `-- name: DeleteBlob :exec DELETE FROM blob WHERE root = ?1 ` func (q *Queries) DeleteBlob(ctx context.Context, root []byte) error { _, err := q.db.ExecContext(ctx, deleteBlob, root) return err } const deleteExpiredSessions = `-- name: DeleteExpiredSessions :execrows DELETE FROM session WHERE expires_at <= ?1 OR idle_expires_at <= ?1 ` func (q *Queries) DeleteExpiredSessions(ctx context.Context, now int64) (int64, error) { result, err := q.db.ExecContext(ctx, deleteExpiredSessions, now) if err != nil { return 0, err } return result.RowsAffected() } const deleteMembership = `-- name: DeleteMembership :exec DELETE FROM membership WHERE group_id = ?1 AND member_id = ?2 ` type DeleteMembershipParams struct { GroupID ident.UUID MemberID ident.UUID } func (q *Queries) DeleteMembership(ctx context.Context, arg DeleteMembershipParams) error { _, err := q.db.ExecContext(ctx, deleteMembership, arg.GroupID, arg.MemberID) return err } const deletePrincipal = `-- name: DeletePrincipal :exec DELETE FROM principal WHERE id = ?1 ` func (q *Queries) DeletePrincipal(ctx context.Context, id ident.UUID) error { _, err := q.db.ExecContext(ctx, deletePrincipal, id) return err } const getAccount = `-- name: GetAccount :one SELECT principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at FROM account WHERE principal_id = ?1 ` func (q *Queries) GetAccount(ctx context.Context, principalID ident.UUID) (Account, error) { row := q.db.QueryRowContext(ctx, getAccount, principalID) var i Account err := row.Scan( &i.PrincipalID, &i.Login, &i.LoginKey, &i.PasswordHash, &i.PasswordChangedAt, &i.MustChangePassword, &i.State, &i.FailedAttempts, &i.LockedUntil, &i.LastLoginAt, &i.CreatedAt, ) return i, err } const getAccountByLoginKey = `-- name: GetAccountByLoginKey :one SELECT principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at FROM account WHERE login_key = ?1 ` func (q *Queries) GetAccountByLoginKey(ctx context.Context, loginKey string) (Account, error) { row := q.db.QueryRowContext(ctx, getAccountByLoginKey, loginKey) var i Account err := row.Scan( &i.PrincipalID, &i.Login, &i.LoginKey, &i.PasswordHash, &i.PasswordChangedAt, &i.MustChangePassword, &i.State, &i.FailedAttempts, &i.LockedUntil, &i.LastLoginAt, &i.CreatedAt, ) return i, err } const getBlob = `-- name: GetBlob :one SELECT root, size, state, role, unit_size, have, tree_state, encryption, last_verified_at, verify_error, last_access_at, created_at FROM blob WHERE root = ?1 ` // ============================================================================ // blob // ============================================================================ func (q *Queries) GetBlob(ctx context.Context, root []byte) (Blob, error) { row := q.db.QueryRowContext(ctx, getBlob, root) var i Blob err := row.Scan( &i.Root, &i.Size, &i.State, &i.Role, &i.UnitSize, &i.Have, &i.TreeState, &i.Encryption, &i.LastVerifiedAt, &i.VerifyError, &i.LastAccessAt, &i.CreatedAt, ) return i, err } const getBlobLocation = `-- name: GetBlobLocation :one SELECT root, backend_id, locator, state, created_at FROM blob_location WHERE root = ?1 AND backend_id = ?2 ` type GetBlobLocationParams struct { Root []byte BackendID ident.UUID } func (q *Queries) GetBlobLocation(ctx context.Context, arg GetBlobLocationParams) (BlobLocation, error) { row := q.db.QueryRowContext(ctx, getBlobLocation, arg.Root, arg.BackendID) var i BlobLocation err := row.Scan( &i.Root, &i.BackendID, &i.Locator, &i.State, &i.CreatedAt, ) return i, err } const getClusterPrincipal = `-- name: GetClusterPrincipal :one SELECT id, kind, name, public_key, status, successor_id, created_at, disabled_at FROM principal WHERE kind = 'cluster' LIMIT 1 ` func (q *Queries) GetClusterPrincipal(ctx context.Context) (Principal, error) { row := q.db.QueryRowContext(ctx, getClusterPrincipal) var i Principal err := row.Scan( &i.ID, &i.Kind, &i.Name, &i.PublicKey, &i.Status, &i.SuccessorID, &i.CreatedAt, &i.DisabledAt, ) return i, err } const getDocument = `-- name: GetDocument :one 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 id = ?1 ` // ============================================================================ // document // ============================================================================ func (q *Queries) GetDocument(ctx context.Context, id ident.UUID) (Document, error) { row := q.db.QueryRowContext(ctx, getDocument, 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 getDocumentKind = `-- name: GetDocumentKind :one SELECT kind, provider, has_content, hidden, metadata_schema FROM document_kind WHERE kind = ?1 ` // ============================================================================ // document_kind // ============================================================================ func (q *Queries) GetDocumentKind(ctx context.Context, kind string) (DocumentKind, error) { row := q.db.QueryRowContext(ctx, getDocumentKind, kind) var i DocumentKind err := row.Scan( &i.Kind, &i.Provider, &i.HasContent, &i.Hidden, &i.MetadataSchema, ) return i, err } const getDocumentVersion = `-- name: GetDocumentVersion :one SELECT id, document_id, seq, content_root, size, mime, author_id, device_id, origin, message, pinned, content_purged_at, created_at FROM document_version WHERE id = ?1 ` // ============================================================================ // document_version // ============================================================================ func (q *Queries) GetDocumentVersion(ctx context.Context, id ident.UUID) (DocumentVersion, error) { row := q.db.QueryRowContext(ctx, getDocumentVersion, id) var i DocumentVersion err := row.Scan( &i.ID, &i.DocumentID, &i.Seq, &i.ContentRoot, &i.Size, &i.Mime, &i.AuthorID, &i.DeviceID, &i.Origin, &i.Message, &i.Pinned, &i.ContentPurgedAt, &i.CreatedAt, ) return i, err } const getEffectiveDocumentPolicy = `-- name: GetEffectiveDocumentPolicy :one WITH RECURSIVE chain(id, policy_id, parent_id) AS ( SELECT d.id, d.policy_id, d.parent_id FROM document d WHERE d.id = ?1 UNION ALL SELECT d.id, COALESCE(d.policy_id, chain.policy_id), d.parent_id FROM document d JOIN chain ON d.id = chain.parent_id ) SELECT policy_id FROM chain WHERE policy_id IS NOT NULL LIMIT 1 ` func (q *Queries) GetEffectiveDocumentPolicy(ctx context.Context, id ident.UUID) ([]byte, error) { row := q.db.QueryRowContext(ctx, getEffectiveDocumentPolicy, id) var policy_id []byte err := row.Scan(&policy_id) return policy_id, err } const getMembership = `-- name: GetMembership :one SELECT group_id, member_id, role, created_at FROM membership WHERE group_id = ?1 AND member_id = ?2 ` type GetMembershipParams struct { GroupID ident.UUID MemberID ident.UUID } func (q *Queries) GetMembership(ctx context.Context, arg GetMembershipParams) (Membership, error) { row := q.db.QueryRowContext(ctx, getMembership, arg.GroupID, arg.MemberID) var i Membership err := row.Scan( &i.GroupID, &i.MemberID, &i.Role, &i.CreatedAt, ) return i, err } const getPrincipal = `-- name: GetPrincipal :one SELECT id, kind, name, public_key, status, successor_id, created_at, disabled_at FROM principal WHERE id = ?1 ` func (q *Queries) GetPrincipal(ctx context.Context, id ident.UUID) (Principal, error) { row := q.db.QueryRowContext(ctx, getPrincipal, id) var i Principal err := row.Scan( &i.ID, &i.Kind, &i.Name, &i.PublicKey, &i.Status, &i.SuccessorID, &i.CreatedAt, &i.DisabledAt, ) return i, err } const getPrincipalByName = `-- name: GetPrincipalByName :one SELECT id, kind, name, public_key, status, successor_id, created_at, disabled_at FROM principal WHERE name = ?1 ` func (q *Queries) GetPrincipalByName(ctx context.Context, name string) (Principal, error) { row := q.db.QueryRowContext(ctx, getPrincipalByName, name) var i Principal err := row.Scan( &i.ID, &i.Kind, &i.Name, &i.PublicKey, &i.Status, &i.SuccessorID, &i.CreatedAt, &i.DisabledAt, ) return i, err } const getPrincipalByNameAndKind = `-- name: GetPrincipalByNameAndKind :one SELECT id, kind, name, public_key, status, successor_id, created_at, disabled_at FROM principal WHERE kind = ?1 AND name = ?2 ` type GetPrincipalByNameAndKindParams struct { Kind string Name string } func (q *Queries) GetPrincipalByNameAndKind(ctx context.Context, arg GetPrincipalByNameAndKindParams) (Principal, error) { row := q.db.QueryRowContext(ctx, getPrincipalByNameAndKind, arg.Kind, arg.Name) var i Principal err := row.Scan( &i.ID, &i.Kind, &i.Name, &i.PublicKey, &i.Status, &i.SuccessorID, &i.CreatedAt, &i.DisabledAt, ) return i, err } const getSession = `-- name: GetSession :one SELECT id, token_hash, principal_id, kind, label, user_agent, ip_prefix, created_at, last_seen_at, expires_at, idle_expires_at, revoked_at FROM session WHERE id = ?1 ` func (q *Queries) GetSession(ctx context.Context, id ident.UUID) (Session, error) { row := q.db.QueryRowContext(ctx, getSession, id) var i Session err := row.Scan( &i.ID, &i.TokenHash, &i.PrincipalID, &i.Kind, &i.Label, &i.UserAgent, &i.IpPrefix, &i.CreatedAt, &i.LastSeenAt, &i.ExpiresAt, &i.IdleExpiresAt, &i.RevokedAt, ) return i, err } const getSessionByTokenHash = `-- name: GetSessionByTokenHash :one SELECT id, token_hash, principal_id, kind, label, user_agent, ip_prefix, created_at, last_seen_at, expires_at, idle_expires_at, revoked_at FROM session WHERE token_hash = ?1 ` func (q *Queries) GetSessionByTokenHash(ctx context.Context, tokenHash []byte) (Session, error) { row := q.db.QueryRowContext(ctx, getSessionByTokenHash, tokenHash) var i Session err := row.Scan( &i.ID, &i.TokenHash, &i.PrincipalID, &i.Kind, &i.Label, &i.UserAgent, &i.IpPrefix, &i.CreatedAt, &i.LastSeenAt, &i.ExpiresAt, &i.IdleExpiresAt, &i.RevokedAt, ) return i, err } const getStorageBackend = `-- name: GetStorageBackend :one SELECT id, kind, name, config, secret_ref, enabled, capacity_bytes, state, last_ok_at, last_error, created_at FROM storage_backend WHERE id = ?1 ` // ============================================================================ // storage_backend // ============================================================================ func (q *Queries) GetStorageBackend(ctx context.Context, id ident.UUID) (StorageBackend, error) { row := q.db.QueryRowContext(ctx, getStorageBackend, id) var i StorageBackend err := row.Scan( &i.ID, &i.Kind, &i.Name, &i.Config, &i.SecretRef, &i.Enabled, &i.CapacityBytes, &i.State, &i.LastOkAt, &i.LastError, &i.CreatedAt, ) 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 WHERE principal_id = ?1 RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at ` func (q *Queries) IncrementFailedAttempts(ctx context.Context, principalID ident.UUID) (Account, error) { row := q.db.QueryRowContext(ctx, incrementFailedAttempts, principalID) var i Account err := row.Scan( &i.PrincipalID, &i.Login, &i.LoginKey, &i.PasswordHash, &i.PasswordChangedAt, &i.MustChangePassword, &i.State, &i.FailedAttempts, &i.LockedUntil, &i.LastLoginAt, &i.CreatedAt, ) return i, err } const listActiveACLEntriesForDocument = `-- name: ListActiveACLEntriesForDocument :many SELECT id, document_id, subject_id, permissions, propagate, expires_at, granted_by, created_at, revoked_at FROM acl_entry WHERE document_id = ?1 AND revoked_at IS NULL AND (expires_at IS NULL OR expires_at > CAST(?2 AS INTEGER)) ORDER BY created_at ` type ListActiveACLEntriesForDocumentParams struct { DocumentID ident.UUID Now int64 } func (q *Queries) ListActiveACLEntriesForDocument(ctx context.Context, arg ListActiveACLEntriesForDocumentParams) ([]AclEntry, error) { rows, err := q.db.QueryContext(ctx, listActiveACLEntriesForDocument, arg.DocumentID, arg.Now) if err != nil { return nil, err } defer rows.Close() var items []AclEntry for rows.Next() { var i AclEntry if err := rows.Scan( &i.ID, &i.DocumentID, &i.SubjectID, &i.Permissions, &i.Propagate, &i.ExpiresAt, &i.GrantedBy, &i.CreatedAt, &i.RevokedAt, ); 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 listActivePrincipals = `-- name: ListActivePrincipals :many SELECT id, kind, name, public_key, status, successor_id, created_at, disabled_at FROM principal WHERE status = 'active' ORDER BY name ` func (q *Queries) ListActivePrincipals(ctx context.Context) ([]Principal, error) { rows, err := q.db.QueryContext(ctx, listActivePrincipals) if err != nil { return nil, err } defer rows.Close() var items []Principal for rows.Next() { var i Principal if err := rows.Scan( &i.ID, &i.Kind, &i.Name, &i.PublicKey, &i.Status, &i.SuccessorID, &i.CreatedAt, &i.DisabledAt, ); 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 listBlobLocations = `-- name: ListBlobLocations :many SELECT root, backend_id, locator, state, created_at FROM blob_location WHERE root = ?1 ORDER BY created_at ` func (q *Queries) ListBlobLocations(ctx context.Context, root []byte) ([]BlobLocation, error) { rows, err := q.db.QueryContext(ctx, listBlobLocations, root) if err != nil { return nil, err } defer rows.Close() var items []BlobLocation for rows.Next() { var i BlobLocation if err := rows.Scan( &i.Root, &i.BackendID, &i.Locator, &i.State, &i.CreatedAt, ); 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 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 listDocumentVersions = `-- name: ListDocumentVersions :many SELECT id, document_id, seq, content_root, size, mime, author_id, device_id, origin, message, pinned, content_purged_at, created_at FROM document_version WHERE document_id = ?1 ORDER BY seq DESC ` func (q *Queries) ListDocumentVersions(ctx context.Context, documentID ident.UUID) ([]DocumentVersion, error) { rows, err := q.db.QueryContext(ctx, listDocumentVersions, documentID) if err != nil { return nil, err } defer rows.Close() var items []DocumentVersion for rows.Next() { var i DocumentVersion if err := rows.Scan( &i.ID, &i.DocumentID, &i.Seq, &i.ContentRoot, &i.Size, &i.Mime, &i.AuthorID, &i.DeviceID, &i.Origin, &i.Message, &i.Pinned, &i.ContentPurgedAt, &i.CreatedAt, ); 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 JOIN principal p ON p.id = m.member_id WHERE m.group_id = ?1 ORDER BY p.name ` func (q *Queries) ListGroupMembers(ctx context.Context, groupID ident.UUID) ([]Principal, error) { rows, err := q.db.QueryContext(ctx, listGroupMembers, groupID) if err != nil { return nil, err } defer rows.Close() var items []Principal for rows.Next() { var i Principal if err := rows.Scan( &i.ID, &i.Kind, &i.Name, &i.PublicKey, &i.Status, &i.SuccessorID, &i.CreatedAt, &i.DisabledAt, ); 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 listGroupMembersWithRole = `-- name: ListGroupMembersWithRole :many SELECT p.id, p.name, p.kind, m.role FROM membership m JOIN principal p ON p.id = m.member_id WHERE m.group_id = ?1 ORDER BY p.name ` type ListGroupMembersWithRoleRow struct { ID ident.UUID Name string Kind string Role string } func (q *Queries) ListGroupMembersWithRole(ctx context.Context, groupID ident.UUID) ([]ListGroupMembersWithRoleRow, error) { rows, err := q.db.QueryContext(ctx, listGroupMembersWithRole, groupID) if err != nil { return nil, err } defer rows.Close() var items []ListGroupMembersWithRoleRow for rows.Next() { var i ListGroupMembersWithRoleRow if err := rows.Scan( &i.ID, &i.Name, &i.Kind, &i.Role, ); 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 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 JOIN principal p ON p.id = m.group_id WHERE m.member_id = ?1 ORDER BY p.name ` func (q *Queries) ListMemberGroups(ctx context.Context, memberID ident.UUID) ([]Principal, error) { rows, err := q.db.QueryContext(ctx, listMemberGroups, memberID) if err != nil { return nil, err } defer rows.Close() var items []Principal for rows.Next() { var i Principal if err := rows.Scan( &i.ID, &i.Kind, &i.Name, &i.PublicKey, &i.Status, &i.SuccessorID, &i.CreatedAt, &i.DisabledAt, ); 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 listMemberGroupsWithRole = `-- name: ListMemberGroupsWithRole :many SELECT p.id, p.name, p.status, m.role FROM membership m JOIN principal p ON p.id = m.group_id WHERE m.member_id = ?1 ORDER BY p.name ` type ListMemberGroupsWithRoleRow struct { ID ident.UUID Name string Status string Role string } func (q *Queries) ListMemberGroupsWithRole(ctx context.Context, memberID ident.UUID) ([]ListMemberGroupsWithRoleRow, error) { rows, err := q.db.QueryContext(ctx, listMemberGroupsWithRole, memberID) if err != nil { return nil, err } defer rows.Close() var items []ListMemberGroupsWithRoleRow for rows.Next() { var i ListMemberGroupsWithRoleRow if err := rows.Scan( &i.ID, &i.Name, &i.Status, &i.Role, ); 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 listMembershipsByGroup = `-- name: ListMembershipsByGroup :many SELECT group_id, member_id, role, created_at FROM membership WHERE group_id = ?1 ORDER BY created_at ` func (q *Queries) ListMembershipsByGroup(ctx context.Context, groupID ident.UUID) ([]Membership, error) { rows, err := q.db.QueryContext(ctx, listMembershipsByGroup, groupID) if err != nil { return nil, err } defer rows.Close() var items []Membership for rows.Next() { var i Membership if err := rows.Scan( &i.GroupID, &i.MemberID, &i.Role, &i.CreatedAt, ); 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 listMembershipsByMember = `-- name: ListMembershipsByMember :many SELECT group_id, member_id, role, created_at FROM membership WHERE member_id = ?1 ORDER BY created_at ` func (q *Queries) ListMembershipsByMember(ctx context.Context, memberID ident.UUID) ([]Membership, error) { rows, err := q.db.QueryContext(ctx, listMembershipsByMember, memberID) if err != nil { return nil, err } defer rows.Close() var items []Membership for rows.Next() { var i Membership if err := rows.Scan( &i.GroupID, &i.MemberID, &i.Role, &i.CreatedAt, ); 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 listPrincipals = `-- name: ListPrincipals :many SELECT id, kind, name, public_key, status, successor_id, created_at, disabled_at FROM principal ORDER BY name ` func (q *Queries) ListPrincipals(ctx context.Context) ([]Principal, error) { rows, err := q.db.QueryContext(ctx, listPrincipals) if err != nil { return nil, err } defer rows.Close() var items []Principal for rows.Next() { var i Principal if err := rows.Scan( &i.ID, &i.Kind, &i.Name, &i.PublicKey, &i.Status, &i.SuccessorID, &i.CreatedAt, &i.DisabledAt, ); 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 listPrincipalsByKind = `-- name: ListPrincipalsByKind :many SELECT id, kind, name, public_key, status, successor_id, created_at, disabled_at FROM principal WHERE kind = ?1 ORDER BY name ` func (q *Queries) ListPrincipalsByKind(ctx context.Context, kind string) ([]Principal, error) { rows, err := q.db.QueryContext(ctx, listPrincipalsByKind, kind) if err != nil { return nil, err } defer rows.Close() var items []Principal for rows.Next() { var i Principal if err := rows.Scan( &i.ID, &i.Kind, &i.Name, &i.PublicKey, &i.Status, &i.SuccessorID, &i.CreatedAt, &i.DisabledAt, ); 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 listSessionsByPrincipal = `-- name: ListSessionsByPrincipal :many SELECT id, token_hash, principal_id, kind, label, user_agent, ip_prefix, created_at, last_seen_at, expires_at, idle_expires_at, revoked_at FROM session WHERE principal_id = ?1 ORDER BY created_at DESC ` func (q *Queries) ListSessionsByPrincipal(ctx context.Context, principalID ident.UUID) ([]Session, error) { rows, err := q.db.QueryContext(ctx, listSessionsByPrincipal, principalID) if err != nil { return nil, err } defer rows.Close() var items []Session for rows.Next() { var i Session if err := rows.Scan( &i.ID, &i.TokenHash, &i.PrincipalID, &i.Kind, &i.Label, &i.UserAgent, &i.IpPrefix, &i.CreatedAt, &i.LastSeenAt, &i.ExpiresAt, &i.IdleExpiresAt, &i.RevokedAt, ); 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 listUnreferencedBlobs = `-- name: ListUnreferencedBlobs :many SELECT b.root, b.size, b.state, b.role, b.unit_size, b.have, b.tree_state, b.encryption, b.last_verified_at, b.verify_error, b.last_access_at, b.created_at FROM blob b WHERE NOT EXISTS ( SELECT 1 FROM document_version v WHERE v.content_root = b.root AND v.content_purged_at IS NULL ) AND NOT EXISTS ( SELECT 1 FROM export_link e WHERE e.blob_root = b.root AND e.state <> 'stale' ) ORDER BY b.created_at ` func (q *Queries) ListUnreferencedBlobs(ctx context.Context) ([]Blob, error) { rows, err := q.db.QueryContext(ctx, listUnreferencedBlobs) if err != nil { return nil, err } defer rows.Close() var items []Blob for rows.Next() { var i Blob if err := rows.Scan( &i.Root, &i.Size, &i.State, &i.Role, &i.UnitSize, &i.Have, &i.TreeState, &i.Encryption, &i.LastVerifiedAt, &i.VerifyError, &i.LastAccessAt, &i.CreatedAt, ); 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 lockAccount = `-- name: LockAccount :one UPDATE account SET state = 'locked', locked_until = ?1 WHERE principal_id = ?2 RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at ` type LockAccountParams struct { LockedUntil sql.NullInt64 PrincipalID ident.UUID } func (q *Queries) LockAccount(ctx context.Context, arg LockAccountParams) (Account, error) { row := q.db.QueryRowContext(ctx, lockAccount, arg.LockedUntil, arg.PrincipalID) var i Account err := row.Scan( &i.PrincipalID, &i.Login, &i.LoginKey, &i.PasswordHash, &i.PasswordChangedAt, &i.MustChangePassword, &i.State, &i.FailedAttempts, &i.LockedUntil, &i.LastLoginAt, &i.CreatedAt, ) 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 nextDocumentVersionSeq = `-- name: NextDocumentVersionSeq :one SELECT COALESCE(MAX(seq), 0) + 1 AS seq FROM document_version WHERE document_id = ?1 ` func (q *Queries) NextDocumentVersionSeq(ctx context.Context, documentID ident.UUID) (int64, error) { row := q.db.QueryRowContext(ctx, nextDocumentVersionSeq, documentID) var seq int64 err := row.Scan(&seq) return seq, err } const purgeDocumentVersion = `-- name: PurgeDocumentVersion :execrows UPDATE document_version SET content_purged_at = ?1 WHERE document_version.id = ?2 AND document_version.content_purged_at IS NULL AND NOT EXISTS ( SELECT 1 FROM document d WHERE d.id = document_version.document_id AND d.head_version_id = document_version.id ) ` type PurgeDocumentVersionParams struct { PurgedAt sql.NullInt64 ID ident.UUID } func (q *Queries) PurgeDocumentVersion(ctx context.Context, arg PurgeDocumentVersionParams) (int64, error) { result, err := q.db.ExecContext(ctx, purgeDocumentVersion, arg.PurgedAt, arg.ID) if err != nil { return 0, err } return result.RowsAffected() } const recordLogin = `-- name: RecordLogin :one UPDATE account SET last_login_at = ?1, failed_attempts = 0, locked_until = NULL WHERE principal_id = ?2 RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at ` type RecordLoginParams struct { LastLoginAt sql.NullInt64 PrincipalID ident.UUID } func (q *Queries) RecordLogin(ctx context.Context, arg RecordLoginParams) (Account, error) { row := q.db.QueryRowContext(ctx, recordLogin, arg.LastLoginAt, arg.PrincipalID) var i Account err := row.Scan( &i.PrincipalID, &i.Login, &i.LoginKey, &i.PasswordHash, &i.PasswordChangedAt, &i.MustChangePassword, &i.State, &i.FailedAttempts, &i.LockedUntil, &i.LastLoginAt, &i.CreatedAt, ) return i, err } const registerFailedLogin = `-- name: RegisterFailedLogin :one UPDATE account SET failed_attempts = failed_attempts + 1, state = CASE WHEN failed_attempts + 1 >= ?1 THEN 'locked' ELSE state END, locked_until = CASE WHEN failed_attempts + 1 >= ?1 THEN ?2 ELSE locked_until END WHERE principal_id = ?3 RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at ` type RegisterFailedLoginParams struct { MaxAttempts int64 LockedUntil sql.NullInt64 PrincipalID ident.UUID } func (q *Queries) RegisterFailedLogin(ctx context.Context, arg RegisterFailedLoginParams) (Account, error) { row := q.db.QueryRowContext(ctx, registerFailedLogin, arg.MaxAttempts, arg.LockedUntil, arg.PrincipalID) var i Account err := row.Scan( &i.PrincipalID, &i.Login, &i.LoginKey, &i.PasswordHash, &i.PasswordChangedAt, &i.MustChangePassword, &i.State, &i.FailedAttempts, &i.LockedUntil, &i.LastLoginAt, &i.CreatedAt, ) return i, err } const resetFailedAttempts = `-- name: ResetFailedAttempts :one UPDATE account SET failed_attempts = 0, locked_until = NULL WHERE principal_id = ?1 RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at ` func (q *Queries) ResetFailedAttempts(ctx context.Context, principalID ident.UUID) (Account, error) { row := q.db.QueryRowContext(ctx, resetFailedAttempts, principalID) var i Account err := row.Scan( &i.PrincipalID, &i.Login, &i.LoginKey, &i.PasswordHash, &i.PasswordChangedAt, &i.MustChangePassword, &i.State, &i.FailedAttempts, &i.LockedUntil, &i.LastLoginAt, &i.CreatedAt, ) 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 WHERE document_id = ?2 AND subject_id = ?3 AND revoked_at IS NULL RETURNING id, document_id, subject_id, permissions, propagate, expires_at, granted_by, created_at, revoked_at ` type RevokeACLEntryParams struct { RevokedAt sql.NullInt64 DocumentID ident.UUID SubjectID ident.UUID } func (q *Queries) RevokeACLEntry(ctx context.Context, arg RevokeACLEntryParams) (AclEntry, error) { row := q.db.QueryRowContext(ctx, revokeACLEntry, arg.RevokedAt, arg.DocumentID, arg.SubjectID) var i AclEntry err := row.Scan( &i.ID, &i.DocumentID, &i.SubjectID, &i.Permissions, &i.Propagate, &i.ExpiresAt, &i.GrantedBy, &i.CreatedAt, &i.RevokedAt, ) return i, err } const revokeSession = `-- name: RevokeSession :one UPDATE session SET revoked_at = ?1 WHERE id = ?2 RETURNING id, token_hash, principal_id, kind, label, user_agent, ip_prefix, created_at, last_seen_at, expires_at, idle_expires_at, revoked_at ` type RevokeSessionParams struct { RevokedAt sql.NullInt64 ID ident.UUID } func (q *Queries) RevokeSession(ctx context.Context, arg RevokeSessionParams) (Session, error) { row := q.db.QueryRowContext(ctx, revokeSession, arg.RevokedAt, arg.ID) var i Session err := row.Scan( &i.ID, &i.TokenHash, &i.PrincipalID, &i.Kind, &i.Label, &i.UserAgent, &i.IpPrefix, &i.CreatedAt, &i.LastSeenAt, &i.ExpiresAt, &i.IdleExpiresAt, &i.RevokedAt, ) return i, err } const revokeSessionByTokenHash = `-- name: RevokeSessionByTokenHash :one UPDATE session SET revoked_at = ?1 WHERE token_hash = ?2 RETURNING id, token_hash, principal_id, kind, label, user_agent, ip_prefix, created_at, last_seen_at, expires_at, idle_expires_at, revoked_at ` type RevokeSessionByTokenHashParams struct { RevokedAt sql.NullInt64 TokenHash []byte } func (q *Queries) RevokeSessionByTokenHash(ctx context.Context, arg RevokeSessionByTokenHashParams) (Session, error) { row := q.db.QueryRowContext(ctx, revokeSessionByTokenHash, arg.RevokedAt, arg.TokenHash) var i Session err := row.Scan( &i.ID, &i.TokenHash, &i.PrincipalID, &i.Kind, &i.Label, &i.UserAgent, &i.IpPrefix, &i.CreatedAt, &i.LastSeenAt, &i.ExpiresAt, &i.IdleExpiresAt, &i.RevokedAt, ) return i, err } const setDocumentHeadVersion = `-- name: SetDocumentHeadVersion :execrows UPDATE document SET head_version_id = ?1, rev = rev + 1, updated_at = ?2 WHERE id = ?3 AND deleted_at IS NULL ` type SetDocumentHeadVersionParams struct { HeadVersionID *ident.UUID UpdatedAt int64 ID ident.UUID } func (q *Queries) SetDocumentHeadVersion(ctx context.Context, arg SetDocumentHeadVersionParams) (int64, error) { result, err := q.db.ExecContext(ctx, setDocumentHeadVersion, arg.HeadVersionID, arg.UpdatedAt, arg.ID) if err != nil { return 0, err } return result.RowsAffected() } const touchSession = `-- name: TouchSession :one UPDATE session SET last_seen_at = ?1, idle_expires_at = ?2 WHERE id = ?3 RETURNING id, token_hash, principal_id, kind, label, user_agent, ip_prefix, created_at, last_seen_at, expires_at, idle_expires_at, revoked_at ` type TouchSessionParams struct { LastSeenAt int64 IdleExpiresAt int64 ID ident.UUID } func (q *Queries) TouchSession(ctx context.Context, arg TouchSessionParams) (Session, error) { row := q.db.QueryRowContext(ctx, touchSession, arg.LastSeenAt, arg.IdleExpiresAt, arg.ID) var i Session err := row.Scan( &i.ID, &i.TokenHash, &i.PrincipalID, &i.Kind, &i.Label, &i.UserAgent, &i.IpPrefix, &i.CreatedAt, &i.LastSeenAt, &i.ExpiresAt, &i.IdleExpiresAt, &i.RevokedAt, ) 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', failed_attempts = 0, locked_until = NULL WHERE principal_id = ?1 RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at ` func (q *Queries) UnlockAccount(ctx context.Context, principalID ident.UUID) (Account, error) { row := q.db.QueryRowContext(ctx, unlockAccount, principalID) var i Account err := row.Scan( &i.PrincipalID, &i.Login, &i.LoginKey, &i.PasswordHash, &i.PasswordChangedAt, &i.MustChangePassword, &i.State, &i.FailedAttempts, &i.LockedUntil, &i.LastLoginAt, &i.CreatedAt, ) return i, err } const updateAccountState = `-- name: UpdateAccountState :one UPDATE account SET state = ?1 WHERE principal_id = ?2 RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at ` type UpdateAccountStateParams struct { State string PrincipalID ident.UUID } func (q *Queries) UpdateAccountState(ctx context.Context, arg UpdateAccountStateParams) (Account, error) { row := q.db.QueryRowContext(ctx, updateAccountState, arg.State, arg.PrincipalID) var i Account err := row.Scan( &i.PrincipalID, &i.Login, &i.LoginKey, &i.PasswordHash, &i.PasswordChangedAt, &i.MustChangePassword, &i.State, &i.FailedAttempts, &i.LockedUntil, &i.LastLoginAt, &i.CreatedAt, ) return i, err } const updateBlobLocationState = `-- name: UpdateBlobLocationState :exec UPDATE blob_location SET state = ?1 WHERE root = ?2 AND backend_id = ?3 ` type UpdateBlobLocationStateParams struct { State string Root []byte BackendID ident.UUID } func (q *Queries) UpdateBlobLocationState(ctx context.Context, arg UpdateBlobLocationStateParams) error { _, err := q.db.ExecContext(ctx, updateBlobLocationState, arg.State, arg.Root, arg.BackendID) return err } const updateBlobVerification = `-- name: UpdateBlobVerification :exec UPDATE blob SET state = ?1, last_verified_at = ?2, verify_error = ?3 WHERE root = ?4 ` type UpdateBlobVerificationParams struct { State string LastVerifiedAt sql.NullInt64 VerifyError sql.NullString Root []byte } func (q *Queries) UpdateBlobVerification(ctx context.Context, arg UpdateBlobVerificationParams) error { _, err := q.db.ExecContext(ctx, updateBlobVerification, arg.State, arg.LastVerifiedAt, arg.VerifyError, arg.Root, ) return 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 updateDocumentMetadata = `-- name: UpdateDocumentMetadata :one UPDATE document SET metadata = ?1, rev = rev + 1, updated_at = ?2 WHERE id = ?3 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 UpdateDocumentMetadataParams struct { Metadata string UpdatedAt int64 ID ident.UUID } func (q *Queries) UpdateDocumentMetadata(ctx context.Context, arg UpdateDocumentMetadataParams) (Document, error) { row := q.db.QueryRowContext(ctx, updateDocumentMetadata, arg.Metadata, 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 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 WHERE group_id = ?2 AND member_id = ?3 RETURNING group_id, member_id, role, created_at ` type UpdateMembershipRoleParams struct { Role string GroupID ident.UUID MemberID ident.UUID } func (q *Queries) UpdateMembershipRole(ctx context.Context, arg UpdateMembershipRoleParams) (Membership, error) { row := q.db.QueryRowContext(ctx, updateMembershipRole, arg.Role, arg.GroupID, arg.MemberID) var i Membership err := row.Scan( &i.GroupID, &i.MemberID, &i.Role, &i.CreatedAt, ) return i, err } const updatePassword = `-- name: UpdatePassword :one UPDATE account SET password_hash = ?1, password_changed_at = ?2, must_change_password = 0, failed_attempts = 0, locked_until = NULL WHERE principal_id = ?3 RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at ` type UpdatePasswordParams struct { PasswordHash sql.NullString PasswordChangedAt sql.NullInt64 PrincipalID ident.UUID } func (q *Queries) UpdatePassword(ctx context.Context, arg UpdatePasswordParams) (Account, error) { row := q.db.QueryRowContext(ctx, updatePassword, arg.PasswordHash, arg.PasswordChangedAt, arg.PrincipalID) var i Account err := row.Scan( &i.PrincipalID, &i.Login, &i.LoginKey, &i.PasswordHash, &i.PasswordChangedAt, &i.MustChangePassword, &i.State, &i.FailedAttempts, &i.LockedUntil, &i.LastLoginAt, &i.CreatedAt, ) return i, err } const updatePrincipalName = `-- name: UpdatePrincipalName :one UPDATE principal SET name = ?1 WHERE id = ?2 RETURNING id, kind, name, public_key, status, successor_id, created_at, disabled_at ` type UpdatePrincipalNameParams struct { Name string ID ident.UUID } func (q *Queries) UpdatePrincipalName(ctx context.Context, arg UpdatePrincipalNameParams) (Principal, error) { row := q.db.QueryRowContext(ctx, updatePrincipalName, arg.Name, arg.ID) var i Principal err := row.Scan( &i.ID, &i.Kind, &i.Name, &i.PublicKey, &i.Status, &i.SuccessorID, &i.CreatedAt, &i.DisabledAt, ) return i, err } const updatePrincipalPublicKey = `-- name: UpdatePrincipalPublicKey :one UPDATE principal SET public_key = ?1 WHERE id = ?2 RETURNING id, kind, name, public_key, status, successor_id, created_at, disabled_at ` type UpdatePrincipalPublicKeyParams struct { PublicKey []byte ID ident.UUID } func (q *Queries) UpdatePrincipalPublicKey(ctx context.Context, arg UpdatePrincipalPublicKeyParams) (Principal, error) { row := q.db.QueryRowContext(ctx, updatePrincipalPublicKey, arg.PublicKey, arg.ID) var i Principal err := row.Scan( &i.ID, &i.Kind, &i.Name, &i.PublicKey, &i.Status, &i.SuccessorID, &i.CreatedAt, &i.DisabledAt, ) return i, err } const updatePrincipalStatus = `-- name: UpdatePrincipalStatus :one UPDATE principal SET status = ?1, disabled_at = ?2 WHERE id = ?3 RETURNING id, kind, name, public_key, status, successor_id, created_at, disabled_at ` type UpdatePrincipalStatusParams struct { Status string DisabledAt sql.NullInt64 ID ident.UUID } func (q *Queries) UpdatePrincipalStatus(ctx context.Context, arg UpdatePrincipalStatusParams) (Principal, error) { row := q.db.QueryRowContext(ctx, updatePrincipalStatus, arg.Status, arg.DisabledAt, arg.ID) var i Principal err := row.Scan( &i.ID, &i.Kind, &i.Name, &i.PublicKey, &i.Status, &i.SuccessorID, &i.CreatedAt, &i.DisabledAt, ) return i, err } const updatePrincipalSuccessor = `-- name: UpdatePrincipalSuccessor :one UPDATE principal SET successor_id = ?1 WHERE id = ?2 RETURNING id, kind, name, public_key, status, successor_id, created_at, disabled_at ` type UpdatePrincipalSuccessorParams struct { SuccessorID *ident.UUID ID ident.UUID } func (q *Queries) UpdatePrincipalSuccessor(ctx context.Context, arg UpdatePrincipalSuccessorParams) (Principal, error) { row := q.db.QueryRowContext(ctx, updatePrincipalSuccessor, arg.SuccessorID, arg.ID) var i Principal err := row.Scan( &i.ID, &i.Kind, &i.Name, &i.PublicKey, &i.Status, &i.SuccessorID, &i.CreatedAt, &i.DisabledAt, ) return i, err } const updateStagingItemState = `-- name: UpdateStagingItemState :exec UPDATE staging_item SET state = ?1, updated_at = ?2 WHERE id = ?3 ` type UpdateStagingItemStateParams struct { State string UpdatedAt int64 ID ident.UUID } func (q *Queries) UpdateStagingItemState(ctx context.Context, arg UpdateStagingItemStateParams) error { _, err := q.db.ExecContext(ctx, updateStagingItemState, arg.State, arg.UpdatedAt, arg.ID) return err } const upsertACLEntry = `-- name: UpsertACLEntry :one INSERT INTO acl_entry ( id, document_id, subject_id, permissions, propagate, expires_at, granted_by, created_at ) VALUES ( ?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8 ) ON CONFLICT(document_id, subject_id) DO UPDATE SET permissions = excluded.permissions, propagate = excluded.propagate, expires_at = excluded.expires_at, granted_by = excluded.granted_by, revoked_at = NULL RETURNING id, document_id, subject_id, permissions, propagate, expires_at, granted_by, created_at, revoked_at ` type UpsertACLEntryParams struct { ID ident.UUID DocumentID ident.UUID SubjectID ident.UUID Permissions int64 Propagate int64 ExpiresAt sql.NullInt64 GrantedBy ident.UUID CreatedAt int64 } // ============================================================================ // acl_entry // ============================================================================ func (q *Queries) UpsertACLEntry(ctx context.Context, arg UpsertACLEntryParams) (AclEntry, error) { row := q.db.QueryRowContext(ctx, upsertACLEntry, arg.ID, arg.DocumentID, arg.SubjectID, arg.Permissions, arg.Propagate, arg.ExpiresAt, arg.GrantedBy, arg.CreatedAt, ) var i AclEntry err := row.Scan( &i.ID, &i.DocumentID, &i.SubjectID, &i.Permissions, &i.Propagate, &i.ExpiresAt, &i.GrantedBy, &i.CreatedAt, &i.RevokedAt, ) return i, err }