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 table, which starts building a query.

If you're using TypeScript, use the DatabaseReader type in convex/_generated/server.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>>


table

table<TableName>(tableName): Table<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

Table<NamedTableInfo<DataModel, TableName>>

  • A Table object to start building a query.