db

package
v0.49.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2026 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MigrationsFS embed.FS

MigrationsFS holds Atlas migration files. Embed the entire directory so it works even when no migrations exist yet.

View Source
var (

	// RecallyArticleFTSSchema is exported so recally store tests, which
	// assemble their schema by hand instead of running migrations, can create
	// the index and triggers their search queries depend on.
	//go:embed schemas/tables/recally_article_fts.sql
	RecallyArticleFTSSchema string
)

FTS5 indexes live outside the Atlas migration pipeline because Atlas's embedded dev SQLite lacks the fts5 module. The DDL (virtual tables + sync triggers) is kept in the sqlc schema dir so generated queries can reference the virtual tables, and is applied here at startup instead.

Functions

func OpenDB

func OpenDB(dbPath string) (*sql.DB, error)

OpenDB opens a SQLite database at the given path, configures it (WAL mode, foreign keys, busy timeout) and runs migrations. The parent directory is created if it doesn't exist.

func OpenSerialConn added in v0.41.0

func OpenSerialConn(dbPath string) (*sql.DB, error)

OpenSerialConn opens a second handle to an already-migrated SQLite database capped at a single connection. Write-heavy subsystems (the memory provider) run on this handle so their writes queue in Go as a fast FIFO instead of fighting over SQLite's single write lock across many pooled connections — which otherwise burns the busy_timeout and starves the shared read pool.

The caller must have run OpenDB on the same path first; this handle does not migrate. The DSN carries the same pragmas (WAL, busy_timeout, foreign keys), and WAL lets this writer run concurrently with readers on the main pool.

Types

type AuthStore

type AuthStore struct {
	*OIDCStore
	// contains filtered or unexported fields
}

AuthStore implements auth.AuthStore using sqlc queries backed by SQLite. It embeds OIDCStore to satisfy all new auth store interfaces so that gateway.go can pass a single *AuthStore to all wiring points without knowing about the split between sqlc-backed and raw-SQL-backed stores.

func NewAuthStore

func NewAuthStore(db *sql.DB) *AuthStore

NewAuthStore creates a new AuthStore wrapping the given database connection.

func (*AuthStore) AssignAgent

func (s *AuthStore) AssignAgent(ctx context.Context, userID string, agentID string) error

func (*AuthStore) CreatePolicy

func (s *AuthStore) CreatePolicy(ctx context.Context, p auth.Policy) (auth.Policy, error)

func (*AuthStore) CreateUserToken

func (s *AuthStore) CreateUserToken(ctx context.Context, token auth.UserToken) (auth.UserToken, error)

func (*AuthStore) DeletePolicy

func (s *AuthStore) DeletePolicy(ctx context.Context, id string) error

func (*AuthStore) GetActiveAutoUserToken

func (s *AuthStore) GetActiveAutoUserToken(ctx context.Context, userID string) (auth.UserToken, error)

func (*AuthStore) GetActiveUserTokenByHash

func (s *AuthStore) GetActiveUserTokenByHash(ctx context.Context, tokenHash string) (auth.UserToken, error)

func (*AuthStore) GetPolicy

func (s *AuthStore) GetPolicy(ctx context.Context, id string) (auth.Policy, error)

func (*AuthStore) GetUserTokenByHash

func (s *AuthStore) GetUserTokenByHash(ctx context.Context, tokenHash string) (auth.UserToken, error)

func (*AuthStore) ListAgentUserIDs

func (s *AuthStore) ListAgentUserIDs(ctx context.Context, agentID string) ([]string, error)

func (*AuthStore) ListEnabledPolicies

func (s *AuthStore) ListEnabledPolicies(ctx context.Context) ([]auth.Policy, error)

func (*AuthStore) ListPolicies

func (s *AuthStore) ListPolicies(ctx context.Context) ([]auth.Policy, error)

func (*AuthStore) ListUserAgentIDs

func (s *AuthStore) ListUserAgentIDs(ctx context.Context, userID string) ([]string, error)

func (*AuthStore) RemoveAgent

func (s *AuthStore) RemoveAgent(ctx context.Context, userID string, agentID string) error

func (*AuthStore) RevokeUserToken

func (s *AuthStore) RevokeUserToken(ctx context.Context, id string) (int64, error)

func (*AuthStore) RotateUserToken

func (s *AuthStore) RotateUserToken(ctx context.Context, id string) (int64, error)

func (*AuthStore) UpdatePolicy

func (s *AuthStore) UpdatePolicy(ctx context.Context, p auth.Policy) error

func (*AuthStore) UpdateUserTokenLastUsed

func (s *AuthStore) UpdateUserTokenLastUsed(ctx context.Context, id string) (int64, error)

type OIDCStore added in v0.38.0

type OIDCStore struct {
	// contains filtered or unexported fields
}

OIDCStore implements auth store interfaces using raw SQL against the OIDC tables (auth_user, auth_identity, auth_session, channel_identity, auth_credential).

func NewOIDCStore added in v0.38.0

func NewOIDCStore(db *sql.DB) *OIDCStore

NewOIDCStore creates an OIDCStore backed by the given database connection.

func (*OIDCStore) AssignAgent added in v0.38.0

func (s *OIDCStore) AssignAgent(ctx context.Context, userID, agentID string) error

func (*OIDCStore) BeginAuthTx added in v0.38.0

func (s *OIDCStore) BeginAuthTx(ctx context.Context) (auth.AuthStores, func() error, func(), error)

BeginAuthTx starts a database transaction and returns tx-scoped copies of all auth stores. Implements auth.Transactioner so AuthService.ProcessOIDCLogin can run the entire login flow atomically.

func (*OIDCStore) CountUsers added in v0.38.0

func (s *OIDCStore) CountUsers(ctx context.Context) (int64, error)

func (*OIDCStore) CreateChannelIdentity added in v0.38.0

func (s *OIDCStore) CreateChannelIdentity(ctx context.Context, i auth.ChannelIdentity) (auth.ChannelIdentity, error)

func (*OIDCStore) CreateCredential added in v0.38.0

func (s *OIDCStore) CreateCredential(ctx context.Context, c auth.Credential) (auth.Credential, error)

func (*OIDCStore) CreateLoginIdentity added in v0.38.0

func (s *OIDCStore) CreateLoginIdentity(ctx context.Context, i auth.LoginIdentity) (auth.LoginIdentity, error)

func (*OIDCStore) CreateSession added in v0.38.0

func (s *OIDCStore) CreateSession(ctx context.Context, sess auth.Session) (auth.Session, error)

func (*OIDCStore) CreateUser added in v0.38.0

func (s *OIDCStore) CreateUser(ctx context.Context, u auth.User) (auth.User, error)

func (*OIDCStore) DeleteChannelIdentity added in v0.38.0

func (s *OIDCStore) DeleteChannelIdentity(ctx context.Context, id string) error

func (*OIDCStore) DeleteCredential added in v0.38.0

func (s *OIDCStore) DeleteCredential(ctx context.Context, userID string) error

func (*OIDCStore) DeleteExpiredSessions added in v0.38.0

func (s *OIDCStore) DeleteExpiredSessions(ctx context.Context) error

func (*OIDCStore) DeleteSession added in v0.38.0

func (s *OIDCStore) DeleteSession(ctx context.Context, id string) error

func (*OIDCStore) DeleteUser added in v0.38.0

func (s *OIDCStore) DeleteUser(ctx context.Context, id string) error

func (*OIDCStore) DeleteUserSessions added in v0.38.0

func (s *OIDCStore) DeleteUserSessions(ctx context.Context, userID string) error

func (*OIDCStore) GetChannelIdentity added in v0.38.0

func (s *OIDCStore) GetChannelIdentity(ctx context.Context, id string) (auth.ChannelIdentity, error)

func (*OIDCStore) GetChannelIdentityByPlatform added in v0.38.0

func (s *OIDCStore) GetChannelIdentityByPlatform(ctx context.Context, platform, externalID string) (auth.ChannelIdentity, error)

func (*OIDCStore) GetCredentialByUserID added in v0.38.0

func (s *OIDCStore) GetCredentialByUserID(ctx context.Context, userID string) (auth.Credential, error)

func (*OIDCStore) GetLoginIdentityByProvider added in v0.38.0

func (s *OIDCStore) GetLoginIdentityByProvider(ctx context.Context, provider, providerSubject string) (auth.LoginIdentity, error)

func (*OIDCStore) GetSession added in v0.38.0

func (s *OIDCStore) GetSession(ctx context.Context, id string) (auth.Session, error)

func (*OIDCStore) GetSessionByTokenHash added in v0.38.0

func (s *OIDCStore) GetSessionByTokenHash(ctx context.Context, tokenHash string) (auth.Session, error)

func (*OIDCStore) GetUser added in v0.38.0

func (s *OIDCStore) GetUser(ctx context.Context, id string) (auth.User, error)

func (*OIDCStore) GetUserByEmail added in v0.38.0

func (s *OIDCStore) GetUserByEmail(ctx context.Context, email string) (auth.User, error)

func (*OIDCStore) GetVaultUser added in v0.38.0

func (s *OIDCStore) GetVaultUser(ctx context.Context, id string) (sqlc.VaultUser, error)

GetVaultUser returns the age key fields for a user. Satisfies vault.DB.

func (*OIDCStore) ListActiveUserIDs added in v0.38.0

func (s *OIDCStore) ListActiveUserIDs(ctx context.Context) ([]string, error)

func (*OIDCStore) ListAgentUserIDs added in v0.38.0

func (s *OIDCStore) ListAgentUserIDs(ctx context.Context, agentID string) ([]string, error)

func (*OIDCStore) ListChannelIdentitiesByUser added in v0.38.0

func (s *OIDCStore) ListChannelIdentitiesByUser(ctx context.Context, userID string) ([]auth.ChannelIdentity, error)

func (*OIDCStore) ListLoginIdentitiesByUser added in v0.38.0

func (s *OIDCStore) ListLoginIdentitiesByUser(ctx context.Context, userID string) ([]auth.LoginIdentity, error)

func (*OIDCStore) ListSessionsByUser added in v0.38.0

func (s *OIDCStore) ListSessionsByUser(ctx context.Context, userID string) ([]auth.Session, error)

func (*OIDCStore) ListUserAgentIDs added in v0.38.0

func (s *OIDCStore) ListUserAgentIDs(ctx context.Context, userID string) ([]string, error)

func (*OIDCStore) ListUsers added in v0.38.0

func (s *OIDCStore) ListUsers(ctx context.Context) ([]auth.User, error)

func (*OIDCStore) ListUsersPaged added in v0.38.0

func (s *OIDCStore) ListUsersPaged(ctx context.Context, limit, offset int64) ([]auth.User, error)

func (*OIDCStore) RemoveAgent added in v0.38.0

func (s *OIDCStore) RemoveAgent(ctx context.Context, userID, agentID string) error

func (*OIDCStore) UpdateChannelIdentityExternalID added in v0.38.0

func (s *OIDCStore) UpdateChannelIdentityExternalID(ctx context.Context, id, externalID string) error

func (*OIDCStore) UpdateCredentialHash added in v0.38.0

func (s *OIDCStore) UpdateCredentialHash(ctx context.Context, userID, passwordHash string) error

func (*OIDCStore) UpdateLoginIdentity added in v0.38.0

func (s *OIDCStore) UpdateLoginIdentity(ctx context.Context, i auth.LoginIdentity) error

func (*OIDCStore) UpdateSessionExpiry added in v0.38.0

func (s *OIDCStore) UpdateSessionExpiry(ctx context.Context, id string, expiresAt time.Time) error

func (*OIDCStore) UpdateUser added in v0.38.0

func (s *OIDCStore) UpdateUser(ctx context.Context, u auth.User) error

func (*OIDCStore) UpdateUserActive added in v0.38.0

func (s *OIDCStore) UpdateUserActive(ctx context.Context, userID string, isActive bool) error

func (*OIDCStore) UpdateUserAgeKeys added in v0.38.0

func (s *OIDCStore) UpdateUserAgeKeys(ctx context.Context, userID, publicKey, privateKey string) error

func (*OIDCStore) UpdateUserDefaultAgent added in v0.38.0

func (s *OIDCStore) UpdateUserDefaultAgent(ctx context.Context, userID, agentID string) error

func (*OIDCStore) UpdateUserNotifyIdentity added in v0.38.0

func (s *OIDCStore) UpdateUserNotifyIdentity(ctx context.Context, userID string, identityID *string) error

func (*OIDCStore) UpdateUserRole added in v0.38.0

func (s *OIDCStore) UpdateUserRole(ctx context.Context, userID string, role string) error

Directories

Path Synopsis
Package ftsquery builds safe FTS5 MATCH expressions from free text.
Package ftsquery builds safe FTS5 MATCH expressions from free text.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL