session.d.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 { RelationalSchemaConfig, TablesRelationalConfig } from "../relations.js";
  5. import { type Query, type SQL } from "../sql/sql.js";
  6. import type { Assume, Equal } from "../utils.js";
  7. import { SingleStoreDatabase } from "./db.js";
  8. import type { SingleStoreDialect } from "./dialect.js";
  9. import type { SelectedFieldsOrdered } from "./query-builders/select.types.js";
  10. export interface SingleStoreQueryResultHKT {
  11. readonly $brand: 'SingleStoreQueryResultHKT';
  12. readonly row: unknown;
  13. readonly type: unknown;
  14. }
  15. export interface AnySingleStoreQueryResultHKT extends SingleStoreQueryResultHKT {
  16. readonly type: any;
  17. }
  18. export type SingleStoreQueryResultKind<TKind extends SingleStoreQueryResultHKT, TRow> = (TKind & {
  19. readonly row: TRow;
  20. })['type'];
  21. export interface SingleStorePreparedQueryConfig {
  22. execute: unknown;
  23. iterator: unknown;
  24. }
  25. export interface SingleStorePreparedQueryHKT {
  26. readonly $brand: 'SingleStorePreparedQueryHKT';
  27. readonly config: unknown;
  28. readonly type: unknown;
  29. }
  30. export type PreparedQueryKind<TKind extends SingleStorePreparedQueryHKT, TConfig extends SingleStorePreparedQueryConfig, TAssume extends boolean = false> = Equal<TAssume, true> extends true ? Assume<(TKind & {
  31. readonly config: TConfig;
  32. })['type'], SingleStorePreparedQuery<TConfig>> : (TKind & {
  33. readonly config: TConfig;
  34. })['type'];
  35. export declare abstract class SingleStorePreparedQuery<T extends SingleStorePreparedQueryConfig> {
  36. private cache?;
  37. private queryMetadata?;
  38. private cacheConfig?;
  39. static readonly [entityKind]: string;
  40. constructor(cache?: Cache | undefined, queryMetadata?: {
  41. type: 'select' | 'update' | 'delete' | 'insert';
  42. tables: string[];
  43. } | undefined, cacheConfig?: WithCacheConfig | undefined);
  44. abstract execute(placeholderValues?: Record<string, unknown>): Promise<T['execute']>;
  45. abstract iterator(placeholderValues?: Record<string, unknown>): AsyncGenerator<T['iterator']>;
  46. }
  47. export interface SingleStoreTransactionConfig {
  48. withConsistentSnapshot?: boolean;
  49. accessMode?: 'read only' | 'read write';
  50. isolationLevel: 'read committed';
  51. }
  52. export declare abstract class SingleStoreSession<TQueryResult extends SingleStoreQueryResultHKT = SingleStoreQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends TablesRelationalConfig = Record<string, never>> {
  53. protected dialect: SingleStoreDialect;
  54. static readonly [entityKind]: string;
  55. constructor(dialect: SingleStoreDialect);
  56. abstract prepareQuery<T extends SingleStorePreparedQueryConfig, TPreparedQueryHKT extends SingleStorePreparedQueryHKT>(query: Query, fields: SelectedFieldsOrdered | undefined, customResultMapper?: (rows: unknown[][]) => T['execute'], generatedIds?: Record<string, unknown>[], returningIds?: SelectedFieldsOrdered, queryMetadata?: {
  57. type: 'select' | 'update' | 'delete' | 'insert';
  58. tables: string[];
  59. }, cacheConfig?: WithCacheConfig): PreparedQueryKind<TPreparedQueryHKT, T>;
  60. execute<T>(query: SQL): Promise<T>;
  61. abstract all<T = unknown>(query: SQL): Promise<T[]>;
  62. count(sql: SQL): Promise<number>;
  63. abstract transaction<T>(transaction: (tx: SingleStoreTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>) => Promise<T>, config?: SingleStoreTransactionConfig): Promise<T>;
  64. protected getSetTransactionSQL(config: SingleStoreTransactionConfig): SQL | undefined;
  65. protected getStartTransactionSQL(config: SingleStoreTransactionConfig): SQL | undefined;
  66. }
  67. export declare abstract class SingleStoreTransaction<TQueryResult extends SingleStoreQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends TablesRelationalConfig = Record<string, never>> extends SingleStoreDatabase<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema> {
  68. protected schema: RelationalSchemaConfig<TSchema> | undefined;
  69. protected readonly nestedIndex: number;
  70. static readonly [entityKind]: string;
  71. constructor(dialect: SingleStoreDialect, session: SingleStoreSession, schema: RelationalSchemaConfig<TSchema> | undefined, nestedIndex: number);
  72. rollback(): never;
  73. /** Nested transactions (aka savepoints) only work with InnoDB engine. */
  74. abstract transaction<T>(transaction: (tx: SingleStoreTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>) => Promise<T>): Promise<T>;
  75. }
  76. export interface PreparedQueryHKTBase extends SingleStorePreparedQueryHKT {
  77. type: SingleStorePreparedQuery<Assume<this['config'], SingleStorePreparedQueryConfig>>;
  78. }