session.d.ts 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { type Cache } from "../cache/core/cache.js";
  2. import type { WithCacheConfig } from "../cache/core/types.js";
  3. import { entityKind } from "../entity.js";
  4. import type { Logger } from "../logger.js";
  5. import type { PgDialect } from "../pg-core/dialect.js";
  6. import { PgTransaction } from "../pg-core/index.js";
  7. import type { SelectedFieldsOrdered } from "../pg-core/query-builders/select.types.js";
  8. import type { PgQueryResultHKT, PgTransactionConfig, PreparedQueryConfig } from "../pg-core/session.js";
  9. import { PgPreparedQuery as PreparedQueryBase, PgSession } from "../pg-core/session.js";
  10. import type { RelationalSchemaConfig, TablesRelationalConfig } from "../relations.js";
  11. import type { QueryWithTypings } from "../sql/sql.js";
  12. import { type Assume } from "../utils.js";
  13. import type { RemoteCallback } from "./driver.js";
  14. export interface PgRemoteSessionOptions {
  15. logger?: Logger;
  16. cache?: Cache;
  17. }
  18. export declare class PgRemoteSession<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends PgSession<PgRemoteQueryResultHKT, TFullSchema, TSchema> {
  19. private client;
  20. private schema;
  21. static readonly [entityKind]: string;
  22. private logger;
  23. private cache;
  24. constructor(client: RemoteCallback, dialect: PgDialect, schema: RelationalSchemaConfig<TSchema> | undefined, options?: PgRemoteSessionOptions);
  25. prepareQuery<T extends PreparedQueryConfig>(query: QueryWithTypings, fields: SelectedFieldsOrdered | undefined, name: string | undefined, isResponseInArrayMode: boolean, customResultMapper?: (rows: unknown[][]) => T['execute'], queryMetadata?: {
  26. type: 'select' | 'update' | 'delete' | 'insert';
  27. tables: string[];
  28. }, cacheConfig?: WithCacheConfig): PreparedQuery<T>;
  29. transaction<T>(_transaction: (tx: PgProxyTransaction<TFullSchema, TSchema>) => Promise<T>, _config?: PgTransactionConfig): Promise<T>;
  30. }
  31. export declare class PgProxyTransaction<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends PgTransaction<PgRemoteQueryResultHKT, TFullSchema, TSchema> {
  32. static readonly [entityKind]: string;
  33. transaction<T>(_transaction: (tx: PgProxyTransaction<TFullSchema, TSchema>) => Promise<T>): Promise<T>;
  34. }
  35. export declare class PreparedQuery<T extends PreparedQueryConfig> extends PreparedQueryBase<T> {
  36. private client;
  37. private queryString;
  38. private params;
  39. private typings;
  40. private logger;
  41. private fields;
  42. private _isResponseInArrayMode;
  43. private customResultMapper?;
  44. static readonly [entityKind]: string;
  45. constructor(client: RemoteCallback, queryString: string, params: unknown[], typings: any[] | undefined, logger: Logger, cache: Cache, queryMetadata: {
  46. type: 'select' | 'update' | 'delete' | 'insert';
  47. tables: string[];
  48. } | undefined, cacheConfig: WithCacheConfig | undefined, fields: SelectedFieldsOrdered | undefined, _isResponseInArrayMode: boolean, customResultMapper?: ((rows: unknown[][]) => T["execute"]) | undefined);
  49. execute(placeholderValues?: Record<string, unknown> | undefined): Promise<T['execute']>;
  50. all(): Promise<void>;
  51. }
  52. export interface PgRemoteQueryResultHKT extends PgQueryResultHKT {
  53. type: Assume<this['row'], {
  54. [column: string]: any;
  55. }>[];
  56. }