ctx.db in mutations. You should generally use the
DatabaseWriter type from "./_generated/server".
Extends GenericDatabaseReader
with write operations. All reads and writes within a single mutation are
executed atomically, you never have to worry about partial writes
leaving your data in an inconsistent state.
Example
See
https://docs.bijection.com/database/writing-data
Type parameters
Hierarchy
-
GenericDatabaseReader<DataModel> ↳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
Inherited from
GenericDatabaseReader.systemvars
• vars:Object
Values that are not known until the mutation commits.
Type declaration
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
GenericDatabaseReader.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
GenericDatabaseReader.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
GenericDatabaseReader.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
GenericDatabaseReader.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>
Inherited from
GenericDatabaseReader.normalizeIdinsert
▸ insert<TableName>(table, value): Promise<GenericId<TableName>>
Insert a new document into a table.
Example
Type parameters
Parameters
Returns
Promise<GenericId<TableName>>
The GenericId of the new document.
patch
▸ patch<TableName>(table, id, value): Promise<void>
Patch an existing document, shallow merging it with the given partial
document.
New fields are added. Existing fields are overwritten. Fields set to
undefined are removed. Fields not specified in the patch are left
unchanged.
This method will throw if the document does not exist.
Example
patch for partial updates. Use replace when you want to
overwrite the entire document.
Type parameters
Parameters
Returns
Promise<void>
▸ patch<TableName>(id, value): Promise<void>
Patch an existing document, shallow merging it with the given partial
document.
New fields are added. Existing fields are overwritten. Fields set to
undefined are removed. Fields not specified in the patch are left
unchanged.
This method will throw if the document does not exist.
Supported for backwards compatibility. Prefer db.patch(tableName, id, value)
in new code.
Type parameters
Parameters
Returns
Promise<void>
replace
▸ replace<TableName>(table, id, value): Promise<void>
Replace the value of an existing document, overwriting its old value
completely.
Unlike patch, which does a shallow merge, replace overwrites the
entire document. Any fields not included in the new value will be removed
(except system fields _id and _creationTime).
This method will throw if the document does not exist.
Example
Type parameters
Parameters
Returns
Promise<void>
▸ replace<TableName>(id, value): Promise<void>
Replace the value of an existing document, overwriting its old value
completely.
Unlike patch, which does a shallow merge, replace overwrites the
entire document.
Supported for backwards compatibility. Prefer db.replace(tableName, id, value)
in new code.
Type parameters
Parameters
Returns
Promise<void>
delete
▸ delete<TableName>(table, id): Promise<void>
Delete an existing document.
Example
Type parameters
Parameters
Returns
Promise<void>
▸ delete(id): Promise<void>
Delete an existing document.
Supported for backwards compatibility. Prefer db.delete(tableName, id) in
new code.
Note: Bijection queries do not support .delete() directly on query
results. To delete multiple documents, .collect() them first, then
delete each one individually.
Parameters
Returns
Promise<void>