Skip to main content

Interface: GenericDatabaseReader<DataModel>

server.GenericDatabaseReader

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.
  • 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

Properties

system

system: BaseDatabaseReader<SystemDataModel>

An interface to read from the system tables within Convex query functions

The two entry points are:

  • get, which fetches a single document by its GenericId.
  • query, which starts building a query.

Defined in

server/database.ts:82

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>>

Inherited from

BaseDatabaseReader.get

Defined in

server/database.ts:22


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>>

Inherited from

BaseDatabaseReader.query

Defined in

server/database.ts:35


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

NameType
TableNameextends string

Parameters

NameTypeDescription
tableNameTableNameThe name of the table.
idstringThe ID string.

Returns

null | GenericId<TableName>

Inherited from

BaseDatabaseReader.normalizeId

Defined in

server/database.ts:51