session.d.cts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import type { BatchItem } from "../batch.cjs";
  2. import { type Cache } from "../cache/core/index.cjs";
  3. import type { WithCacheConfig } from "../cache/core/types.cjs";
  4. import { entityKind } from "../entity.cjs";
  5. import type { Logger } from "../logger.cjs";
  6. import type { RelationalSchemaConfig, TablesRelationalConfig } from "../relations.cjs";
  7. import { type Query } from "../sql/sql.cjs";
  8. import type { SQLiteAsyncDialect } from "../sqlite-core/dialect.cjs";
  9. import { SQLiteTransaction } from "../sqlite-core/index.cjs";
  10. import type { SelectedFieldsOrdered } from "../sqlite-core/query-builders/select.types.cjs";
  11. import type { PreparedQueryConfig as PreparedQueryConfigBase, SQLiteExecuteMethod, SQLiteTransactionConfig } from "../sqlite-core/session.cjs";
  12. import { SQLitePreparedQuery, SQLiteSession } from "../sqlite-core/session.cjs";
  13. import type { AsyncBatchRemoteCallback, RemoteCallback, SqliteRemoteResult } from "./driver.cjs";
  14. export interface SQLiteRemoteSessionOptions {
  15. logger?: Logger;
  16. cache?: Cache;
  17. }
  18. export type PreparedQueryConfig = Omit<PreparedQueryConfigBase, 'statement' | 'run'>;
  19. export declare class SQLiteRemoteSession<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends SQLiteSession<'async', SqliteRemoteResult, TFullSchema, TSchema> {
  20. private client;
  21. private schema;
  22. private batchCLient?;
  23. static readonly [entityKind]: string;
  24. private logger;
  25. private cache;
  26. constructor(client: RemoteCallback, dialect: SQLiteAsyncDialect, schema: RelationalSchemaConfig<TSchema> | undefined, batchCLient?: AsyncBatchRemoteCallback | undefined, options?: SQLiteRemoteSessionOptions);
  27. prepareQuery<T extends Omit<PreparedQueryConfig, 'run'>>(query: Query, fields: SelectedFieldsOrdered | undefined, executeMethod: SQLiteExecuteMethod, isResponseInArrayMode: boolean, customResultMapper?: (rows: unknown[][]) => unknown, queryMetadata?: {
  28. type: 'select' | 'update' | 'delete' | 'insert';
  29. tables: string[];
  30. }, cacheConfig?: WithCacheConfig): RemotePreparedQuery<T>;
  31. batch<T extends BatchItem<'sqlite'>[] | readonly BatchItem<'sqlite'>[]>(queries: T): Promise<unknown[]>;
  32. transaction<T>(transaction: (tx: SQLiteProxyTransaction<TFullSchema, TSchema>) => Promise<T>, config?: SQLiteTransactionConfig): Promise<T>;
  33. extractRawAllValueFromBatchResult(result: unknown): unknown;
  34. extractRawGetValueFromBatchResult(result: unknown): unknown;
  35. extractRawValuesValueFromBatchResult(result: unknown): unknown;
  36. }
  37. export declare class SQLiteProxyTransaction<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends SQLiteTransaction<'async', SqliteRemoteResult, TFullSchema, TSchema> {
  38. static readonly [entityKind]: string;
  39. transaction<T>(transaction: (tx: SQLiteProxyTransaction<TFullSchema, TSchema>) => Promise<T>): Promise<T>;
  40. }
  41. export declare class RemotePreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig> extends SQLitePreparedQuery<{
  42. type: 'async';
  43. run: SqliteRemoteResult;
  44. all: T['all'];
  45. get: T['get'];
  46. values: T['values'];
  47. execute: T['execute'];
  48. }> {
  49. private client;
  50. private logger;
  51. private fields;
  52. private _isResponseInArrayMode;
  53. static readonly [entityKind]: string;
  54. private method;
  55. constructor(client: RemoteCallback, query: Query, logger: Logger, cache: Cache, queryMetadata: {
  56. type: 'select' | 'update' | 'delete' | 'insert';
  57. tables: string[];
  58. } | undefined, cacheConfig: WithCacheConfig | undefined, fields: SelectedFieldsOrdered | undefined, executeMethod: SQLiteExecuteMethod, _isResponseInArrayMode: boolean,
  59. /** @internal */ customResultMapper?: ((rows: unknown[][], mapColumnValue?: (value: unknown) => unknown) => unknown) | undefined);
  60. getQuery(): Query & {
  61. method: SQLiteExecuteMethod;
  62. };
  63. run(placeholderValues?: Record<string, unknown>): Promise<SqliteRemoteResult>;
  64. mapAllResult(rows: unknown, isFromBatch?: boolean): unknown;
  65. all(placeholderValues?: Record<string, unknown>): Promise<T['all']>;
  66. get(placeholderValues?: Record<string, unknown>): Promise<T['get']>;
  67. mapGetResult(rows: unknown, isFromBatch?: boolean): unknown;
  68. values<T extends any[] = unknown[]>(placeholderValues?: Record<string, unknown>): Promise<T[]>;
  69. }