Skip to main content

Interface: DatabaseReader<DataModel>

server.DatabaseReader

An interface to read from the database within Convex query functions.

The two entry points are get, which fetches a single document by its GenericId, or query, which starts building a query.

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

NameType
DataModelextends GenericDataModel

Hierarchy

Methods

get

get<TableName>(id): Promise<null | DocumentByName<DataModel, TableName>>

Fetch a single document from the database by its GenericId.

Type parameters

NameType
TableNameextends string

Parameters

NameTypeDescription
idGenericId<TableName>The GenericId of the document to fetch from the database.

Returns

Promise<null | DocumentByName<DataModel, TableName>>


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

NameType
TableNameextends string

Parameters

NameTypeDescription
tableNameTableNameThe name of the table to query.

Returns

QueryInitializer<NamedTableInfo<DataModel, TableName>>