session.d.ts 3.7 KB

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