Skip to content

Repository

Defined in: repository.ts:90

A thin, database-agnostic data-access layer for a single protobuf message type. Handles serialization, filtering, field masking, and etag generation so callers work with strongly-typed messages.

Desc extends DescMessage

readonly schema: Desc

Defined in: repository.ts:92

The protobuf message descriptor this repository manages.


readonly tableName: string

Defined in: repository.ts:95

The database table or collection name.

batchCreate(resources, options?): Promise<MessageShape<Desc>[]>

Defined in: repository.ts:190

Create multiple resources atomically. All resources are validated before any writes occur. If any validation fails, no resources are created.

MessageInitShape<Desc>[]

The fully-formed messages to insert.

BatchCreateOptions

Optional read mask, validateOnly, and transaction.

Promise<MessageShape<Desc>[]>

If any resource with the same IDENTIFIER fields already exists.

https://google.aip.dev/233


batchDelete(queries, options?): Promise<void>

Defined in: repository.ts:222

Delete multiple resources atomically. All resources must exist — if any is missing, a NotFoundError is thrown and no resources are deleted.

QueryInput<Desc>[]

An array of AIP-160 filter strings or partial resource objects identifying the resources to delete.

BatchDeleteOptions

Optional validateOnly and transaction.

Promise<void>

If any resource is not found.

https://google.aip.dev/235


batchGet(queries, options?): Promise<MessageShape<Desc>[]>

Defined in: repository.ts:177

Retrieve multiple resources matching the given queries. All resources must exist — if any is missing, a NotFoundError is thrown and no partial results are returned.

Results are returned in the same order as the input queries.

QueryInput<Desc>[]

An array of AIP-160 filter strings or partial resource objects.

BatchGetOptions

Optional read mask and transaction.

Promise<MessageShape<Desc>[]>

If any matching resource is not found.

https://google.aip.dev/231


batchUpdate(updates, options?): Promise<MessageShape<Desc>[]>

Defined in: repository.ts:206

Update multiple existing resources atomically. Each update item specifies the query to identify the resource, the fields to update, and an optional per-item update mask.

BatchUpdateItem<Desc>[]

The update items, each with query, resource, and optional updateMask.

BatchUpdateOptions

Optional read mask, validateOnly, and transaction.

Promise<MessageShape<Desc>[]>

If any resource is not found.

https://google.aip.dev/234


count(query?, options?): Promise<number>

Defined in: repository.ts:162

Count resources matching an optional query.

QueryInput<Desc>

An AIP-160 filter string, a partial resource object, or undefined to count all resources.

CountOptions

Optional transaction.

Promise<number>


create(resource, options?): Promise<MessageShape<Desc>>

Defined in: repository.ts:116

Create a new resource. The message is serialized, an etag is computed (if the schema has an etag field), and the row is inserted into the database.

MessageInitShape<Desc>

The fully-formed message to insert.

CreateOptions

Optional read mask and transaction.

Promise<MessageShape<Desc>>


delete(query, options?): Promise<void>

Defined in: repository.ts:153

Delete a resource matching the query.

QueryInput<Desc>

An AIP-160 filter string or partial resource to identify the resource to delete.

DeleteOptions

Optional transaction.

Promise<void>

If no matching resource is found.


get(query, options?): Promise<MessageShape<Desc>>

Defined in: repository.ts:106

Retrieve a single resource matching the query.

QueryInput<Desc>

An AIP-160 filter string or a partial resource object. Partial objects are converted to equality filters (e.g. { uid: "abc" }uid = "abc").

GetOptions

Optional read mask and transaction.

Promise<MessageShape<Desc>>

If no matching resource is found.


list(query?, options?): Promise<ListResult<Desc>>

Defined in: repository.ts:126

List resources matching an optional query with pagination and ordering support.

QueryInput<Desc>

An AIP-160 filter string, a partial resource object, or undefined to match all resources.

ListOptions

Pagination, ordering, read mask, and transaction.

Promise<ListResult<Desc>>


update(query, resource, options?): Promise<MessageShape<Desc>>

Defined in: repository.ts:139

Update an existing resource. The resource is fetched, merged with the update according to the update mask, and persisted. An etag is recomputed if the schema has an etag field.

QueryInput<Desc>

An AIP-160 filter string or partial resource to identify the resource to update.

MessageInitShape<Desc>

The fields to update.

UpdateOptions

Update mask, read mask, validateOnly, and transaction.

Promise<MessageShape<Desc>>

If no matching resource is found.