@jokio/datastore
Version:
Helper library for Google Cloud Datastore
21 lines (20 loc) • 1.63 kB
TypeScript
/// <reference types="google-cloud__datastore" />
import * as Datastore from '@google-cloud/datastore';
import { DatastoreTransaction } from '@google-cloud/datastore/transaction';
import { CommitResponse } from '@google-cloud/datastore/request';
import { OneOrMany, DatastoreKey } from '@google-cloud/datastore/entity';
import { DbSetBase } from './db-set-base';
import { Entity } from './types';
import { QueryOptions, Query, QueryInfo } from '@google-cloud/datastore/query';
export declare class DbTransaction<TEntity extends Entity> extends DbSetBase<TEntity> {
protected transaction: DatastoreTransaction;
constructor(kind: string, datastore: Datastore, transaction: DatastoreTransaction);
protected onSave(entities: OneOrMany<object>): Promise<CommitResponse | undefined>;
protected onGet<TResult = any>(key: DatastoreKey, options?: QueryOptions): Promise<TResult | undefined>;
protected onCreateQuery(kind: string): Query;
protected onRunQuery<TResult = any>(query: Query, options?: QueryOptions): Promise<[TResult[], QueryInfo]>;
}
export declare type ProcessTransaction = (tran: DatastoreTransaction, datastore: Datastore) => Promise<void>;
export declare const configureTransaction: (datastore: Datastore) => (process: ProcessTransaction) => Promise<boolean>;
export declare type ProcessDbTransaction<TEntity extends Entity> = (tran: DbTransaction<TEntity>, datastoreTran: DatastoreTransaction) => Promise<void>;
export declare const configureDbTransaction: <TEntity extends Entity>(kind: string, datastore: Datastore) => (process: ProcessDbTransaction<TEntity>) => Promise<void>;