Interface: GenericDatabaseReader<DataModel>
server.GenericDatabaseReader
An interface to read from the database within Convex query functions.
The two entry points are:
If you're using code generation, use the DatabaseReader
type in
convex/_generated/server.d.ts
which is typed for your data model.
Type parameters
Name | Type |
---|---|
DataModel | extends GenericDataModel |
Hierarchy
-
BaseDatabaseReader
<DataModel
>↳
GenericDatabaseReader
Properties
system
• system: BaseDatabaseReader
<SystemDataModel
>
An interface to read from the system tables within Convex query functions
The two entry points are:
Defined in
Methods
get
▸ get<TableName
>(id
): Promise
<null
| DocumentByName
<DataModel
, TableName
>>
Fetch a single document from the database by its GenericId.
Type parameters
Name | Type |
---|---|
TableName | extends string |
Parameters
Name | Type | Description |
---|---|---|
id | GenericId <TableName > | The GenericId of the document to fetch from the database. |
Returns
Promise
<null
| DocumentByName
<DataModel
, TableName
>>
- The GenericDocument of the document at the given GenericId, or
null
if it no longer exists.
Inherited from
BaseDatabaseReader.get
Defined in
query
▸ query<TableName
>(tableName
): QueryInitializer
<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
Name | Type |
---|---|
TableName | extends string |
Parameters
Name | Type | Description |
---|---|---|
tableName | TableName | The name of the table to query. |
Returns
QueryInitializer
<NamedTableInfo
<DataModel
, TableName
>>
- A QueryInitializer object to start building a query.
Inherited from
BaseDatabaseReader.query
Defined in
normalizeId
▸ normalizeId<TableName
>(tableName
, id
): null
| GenericId
<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(id)
may return null
).
Type parameters
Name | Type |
---|---|
TableName | extends string |
Parameters
Name | Type | Description |
---|---|---|
tableName | TableName | The name of the table. |
id | string | The ID string. |
Returns
null
| GenericId
<TableName
>
Inherited from
BaseDatabaseReader.normalizeId