ctx.db in queries (read-only) and mutations (read-write).
You should generally use the DatabaseReader type from
"./_generated/server".
The two entry points are:
- get, which fetches a single document by table name and GenericId.
- query, which starts building a query.
Example
.withIndex() instead of .filter() for efficient
queries. Define indexes in your schema for fields you query frequently.
See
https://docs.bijection.com/database/reading-data
Type parameters
Hierarchy
-
BaseDatabaseReader<DataModel> ↳GenericDatabaseReader↳↳GenericDatabaseWriter
Properties
system
• system:BaseDatabaseReader<SystemDataModel>
An interface to read from the system tables within Bijection query functions.
System tables include _storage (file metadata) and
_scheduled_functions (scheduled function state). Use ctx.db.system.get()
and ctx.db.system.query() just like regular tables.
Example
Methods
get
▸ get<TableName, Fields>(table, id, options): Promise<null | SelectedDocument<DocumentByName<DataModel, TableName>, Fields>>
Fetch selected top-level properties, retaining _id and _creationTime.
Property and object access is enforced before disclosure. Null means the
document is absent; refused access is an error, never a redacted document.
Type parameters
Parameters
Returns
Promise<null | SelectedDocument<DocumentByName<DataModel, TableName>, Fields>>
Inherited from
BaseDatabaseReader.get ▸ get<TableName>(table, id): Promise<null | DocumentByName<DataModel, TableName>>
Fetch a single document from the database by table name and
GenericId.
Example
Type parameters
Parameters
Returns
Promise<null | DocumentByName<DataModel, TableName>>
- The GenericDocument of the document at the given GenericId, or
nullif it no longer exists.
Inherited from
BaseDatabaseReader.get ▸ get<TableName>(id): Promise<null | DocumentByName<DataModel, TableName>>
Fetch a single document from the database by its GenericId.
Supported for backwards compatibility. Prefer db.get(tableName, id) in
new code, or db.system.get(tableName, id) for system tables.
Type parameters
Parameters
Returns
Promise<null | DocumentByName<DataModel, TableName>>
- The GenericDocument of the document at the given GenericId, or
nullif it no longer exists.
Inherited from
BaseDatabaseReader.getquery
▸ query<TableName>(tableName): SelectableQueryInitializer<NamedTableInfo<DataModel, TableName>>
Begin a query for the given table name.
Queries don’t execute immediately, so calling this method and extending its
query are free until the results are actually used.
Type parameters
Parameters
Returns
SelectableQueryInitializer<NamedTableInfo<DataModel, TableName>>
- A QueryInitializer object to start building a query.
Inherited from
BaseDatabaseReader.querynormalizeId
▸ normalizeId<TableName>(tableName, id): null | TableKey<DataModel, TableName>
Returns the string ID format for the ID in a given table, or null if the ID
is from a different table or is not a valid ID.
This accepts the string ID format as well as the .toString() representation
of the legacy class-based ID format.
This does not guarantee that the ID exists (i.e. db.get(tableName, id) may return null).
Type parameters
Parameters
Returns
null | TableKey<DataModel, TableName>