Skip to main content

Module db

Module db 

Source
Expand description

Shared database schema and query definitions. Used by: Axum server, Cloudflare Worker, TUI local DB.

Constants§

INVITATIONS_SCHEMA
Schema for team invitations (provider-agnostic).
INVITATION_COLUMNS
Column list for invitation SELECT queries.
INVITATION_DUP_CHECK_EMAIL
Check for duplicate pending invitation by email.
INVITATION_DUP_CHECK_OAUTH
Check for duplicate pending invitation by OAuth provider.
INVITATION_INSERT
INSERT a new invitation (8 params).
INVITATION_LOOKUP
Lookup an invitation by id.
INVITATION_UPDATE_STATUS
Update an invitation’s status.
LOCAL_SCHEMA
Local-only SQLite schema for TUI + Daemon (not on the server).
MEMBER_COLUMNS
Column list for member SELECT queries (joins with users table).
MEMBER_DELETE
DELETE a team member.
MEMBER_INSERT
INSERT a team member.
MEMBER_JOINED_AT
Get a team member’s joined_at timestamp.
OAUTH_IDENTITIES_SCHEMA
Schema for the generic OAuth identities table (used by migration).
OAUTH_IDENTITY_FIND_BY_PROVIDER
Find a user by OAuth identity.
OAUTH_IDENTITY_FIND_BY_USER
Find all OAuth identities for a user.
OAUTH_IDENTITY_MATCH
Check if a user has a matching OAuth identity.
OAUTH_IDENTITY_UPSERT
UPSERT an OAuth identity (link or update).
OAUTH_STATES_SCHEMA
Schema for OAuth state tokens (CSRF protection).
OAUTH_STATE_DELETE
Delete a used OAuth state token.
OAUTH_STATE_INSERT
Insert an OAuth state token.
OAUTH_STATE_VALIDATE
Validate and retrieve an OAuth state token.
REFRESH_TOKENS_SCHEMA
Schema for refresh tokens.
REFRESH_TOKEN_DELETE
Delete refresh token by hash.
REFRESH_TOKEN_INSERT
Insert refresh token.
REFRESH_TOKEN_LOOKUP
Lookup refresh token with user join.
SCHEMA
SQLite schema (compatible with D1). Does NOT include FTS5 (Axum-only).
SESSION_COLUMNS
Column list for session SELECT queries (joins with users table).
SESSION_INSERT
INSERT a new session (17 params).
SESSION_LINKS_BY_SESSION
SELECT all links for a session (both directions).
SESSION_LINKS_SCHEMA
Session links schema (shared: server, worker, local).
SESSION_LINK_INSERT
INSERT a session link.
TEAM_COLUMNS
Column list for team SELECT queries.
TEAM_CREATED_AT
Get a team’s created_at timestamp.
TEAM_EXISTS
Check if a team exists.
TEAM_INSERT
INSERT a new team (5 params: id, name, description, is_public, created_by).
TEAM_MEMBER_COUNT
Count members in a team.
TEAM_MEMBER_EXISTS
Check if a user is a member of a team.
TEAM_MEMBER_ROLE
Get a team member’s role.
TEAM_NAME_BY_ID
Get a team’s name by id.
TEAM_UPDATE_DESCRIPTION
Update a team’s description.
TEAM_UPDATE_NAME
Update a team’s name.
TEAM_UPDATE_VISIBILITY
Update a team’s visibility.
USER_BY_API_KEY
Find user by API key (for Bearer osk_xxx auth).
USER_BY_EMAIL_FOR_LOGIN
Find user by email (for login).
USER_BY_ID
Find user by id (for JWT auth).
USER_BY_NICKNAME
Find a user by nickname (returns id).
USER_COUNT
Count users (for first-user-is-admin check).
USER_EMAIL_AVATAR
Get user email and avatar (for settings).
USER_EMAIL_EXISTS
Check email existence.
USER_INSERT
Insert user (legacy, no email).
USER_INSERT_WITH_EMAIL
Insert user with email/password.
USER_PASSWORD_FIELDS
Get password hash/salt for a user.
USER_SETTINGS_FIELDS
Get user API key and created_at (for settings).
USER_UPDATE_API_KEY
Regenerate API key.
USER_UPDATE_PASSWORD
Update password.

Statics§

INVITATION_LIST_MY
List pending, non-expired invitations for a user by email or OAuth identity. Params: ?1 = email, ?2 = user_id (for OAuth identity lookup).
MEMBER_LIST
List members of a team (joins with users table).
SESSION_GET
SELECT a single session by id.
SESSION_LIST_BASE
Base SELECT for session listings. Append WHERE / ORDER BY / LIMIT at call site.
TEAM_GET
SELECT a single team by id.
TEAM_LIST_MY
List teams for a user (via team_members join).