session.d.cts 4.2 KB

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