@depup/pg-mem 3.0.14-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/README.md +35 -0
  2. package/changes.json +26 -0
  3. package/index.d.ts +1 -0
  4. package/index.js +16547 -0
  5. package/index.js.map +1 -0
  6. package/package.json +196 -0
  7. package/readme.md +297 -0
  8. package/types/adapters/adapters.d.ts +37 -0
  9. package/types/adapters/index.d.ts +2 -0
  10. package/types/adapters/pg-socket-adapter.d.ts +30 -0
  11. package/types/column.d.ts +27 -0
  12. package/types/constraints/foreign-key.d.ts +14 -0
  13. package/types/constraints/generated-from-expr.d.ts +14 -0
  14. package/types/constraints/generated-identity.d.ts +13 -0
  15. package/types/constraints/index-cst.d.ts +9 -0
  16. package/types/constraints/subscription.d.ts +7 -0
  17. package/types/constraints/wrapped.d.ts +9 -0
  18. package/types/datatypes/datatype-base.d.ts +66 -0
  19. package/types/datatypes/datatypes-geometric.d.ts +59 -0
  20. package/types/datatypes/datatypes-geometric.spec.d.ts +2 -0
  21. package/types/datatypes/datatypes.d.ts +101 -0
  22. package/types/datatypes/index.d.ts +2 -0
  23. package/types/datatypes/t-custom-enum.d.ts +21 -0
  24. package/types/datatypes/t-equivalent.d.ts +18 -0
  25. package/types/datatypes/t-inet.d.ts +13 -0
  26. package/types/datatypes/t-interval.d.ts +13 -0
  27. package/types/datatypes/t-jsonb.d.ts +16 -0
  28. package/types/datatypes/t-record.d.ts +17 -0
  29. package/types/datatypes/t-regclass.d.ts +11 -0
  30. package/types/datatypes/t-regtype.d.ts +11 -0
  31. package/types/datatypes/t-time.d.ts +14 -0
  32. package/types/datatypes/t-timestamp.d.ts +18 -0
  33. package/types/db.d.ts +3 -0
  34. package/types/evaluator.d.ts +61 -0
  35. package/types/execution/clean-results.d.ts +5 -0
  36. package/types/execution/exec-utils.d.ts +19 -0
  37. package/types/execution/records-mutations/deletion.d.ts +8 -0
  38. package/types/execution/records-mutations/insert.d.ts +13 -0
  39. package/types/execution/records-mutations/mutation-base.d.ts +31 -0
  40. package/types/execution/records-mutations/truncate-table.d.ts +10 -0
  41. package/types/execution/records-mutations/update.d.ts +10 -0
  42. package/types/execution/schema-amends/alter-enum.d.ts +20 -0
  43. package/types/execution/schema-amends/alter-sequence.d.ts +19 -0
  44. package/types/execution/schema-amends/alter.d.ts +19 -0
  45. package/types/execution/schema-amends/comment.d.ts +19 -0
  46. package/types/execution/schema-amends/create-enum.d.ts +20 -0
  47. package/types/execution/schema-amends/create-function.d.ts +20 -0
  48. package/types/execution/schema-amends/create-index.d.ts +19 -0
  49. package/types/execution/schema-amends/create-materialized-view.d.ts +19 -0
  50. package/types/execution/schema-amends/create-schema.d.ts +19 -0
  51. package/types/execution/schema-amends/create-sequence.d.ts +21 -0
  52. package/types/execution/schema-amends/create-table.d.ts +21 -0
  53. package/types/execution/schema-amends/create-view.d.ts +22 -0
  54. package/types/execution/schema-amends/do.d.ts +9 -0
  55. package/types/execution/schema-amends/drop-index.d.ts +18 -0
  56. package/types/execution/schema-amends/drop-sequence.d.ts +18 -0
  57. package/types/execution/schema-amends/drop-table.d.ts +19 -0
  58. package/types/execution/schema-amends/drop-type.d.ts +18 -0
  59. package/types/execution/select.d.ts +15 -0
  60. package/types/execution/set.d.ts +9 -0
  61. package/types/execution/show.d.ts +8 -0
  62. package/types/execution/statement-exec.d.ts +26 -0
  63. package/types/execution/transaction-statements.d.ts +16 -0
  64. package/types/functions/date.d.ts +3 -0
  65. package/types/functions/index.d.ts +2 -0
  66. package/types/functions/numbers.d.ts +3 -0
  67. package/types/functions/sequence-fns.d.ts +3 -0
  68. package/types/functions/string.d.ts +3 -0
  69. package/types/functions/subquery.d.ts +3 -0
  70. package/types/functions/system.d.ts +3 -0
  71. package/types/index.d.ts +5 -0
  72. package/types/interfaces-private.d.ts +605 -0
  73. package/types/interfaces.d.ts +449 -0
  74. package/types/migrate/migrate-interfaces.d.ts +32 -0
  75. package/types/migrate/migrate.d.ts +8 -0
  76. package/types/misc/buffer-deno.d.ts +7 -0
  77. package/types/misc/buffer-node.d.ts +7 -0
  78. package/types/misc/pg-escape.d.ts +2 -0
  79. package/types/misc/pg-utils.d.ts +3 -0
  80. package/types/parser/context.d.ts +26 -0
  81. package/types/parser/expression-builder.d.ts +8 -0
  82. package/types/parser/function-call.d.ts +4 -0
  83. package/types/parser/parse-cache.d.ts +6 -0
  84. package/types/schema/btree-index.d.ts +48 -0
  85. package/types/schema/consts.d.ts +10 -0
  86. package/types/schema/custom-index.d.ts +31 -0
  87. package/types/schema/function-call-table.d.ts +20 -0
  88. package/types/schema/information-schema/columns-list.d.ts +13 -0
  89. package/types/schema/information-schema/constraint-column-usage.d.ts +10 -0
  90. package/types/schema/information-schema/index.d.ts +3 -0
  91. package/types/schema/information-schema/key-column-usage.d.ts +10 -0
  92. package/types/schema/information-schema/table-constraints.d.ts +10 -0
  93. package/types/schema/information-schema/table-list.d.ts +14 -0
  94. package/types/schema/overload-resolver.d.ts +17 -0
  95. package/types/schema/pg-catalog/binary-operators.d.ts +3 -0
  96. package/types/schema/pg-catalog/index.d.ts +3 -0
  97. package/types/schema/pg-catalog/pg-attribute-list.d.ts +11 -0
  98. package/types/schema/pg-catalog/pg-class.d.ts +13 -0
  99. package/types/schema/pg-catalog/pg-constraints-list.d.ts +13 -0
  100. package/types/schema/pg-catalog/pg-database.d.ts +17 -0
  101. package/types/schema/pg-catalog/pg-enum-list.d.ts +10 -0
  102. package/types/schema/pg-catalog/pg-index-list.d.ts +10 -0
  103. package/types/schema/pg-catalog/pg-namespace-list.d.ts +10 -0
  104. package/types/schema/pg-catalog/pg-proc.d.ts +10 -0
  105. package/types/schema/pg-catalog/pg-range.d.ts +10 -0
  106. package/types/schema/pg-catalog/pg-sequences-list.d.ts +10 -0
  107. package/types/schema/pg-catalog/pg-type-list.d.ts +10 -0
  108. package/types/schema/pg-catalog/pg-user-list.d.ts +10 -0
  109. package/types/schema/pg-catalog/pg_statio_user_tables.d.ts +25 -0
  110. package/types/schema/pg-catalog/sql-function-language.d.ts +3 -0
  111. package/types/schema/prepared-intercepted.d.ts +11 -0
  112. package/types/schema/prepared.d.ts +5 -0
  113. package/types/schema/readonly-table.d.ts +62 -0
  114. package/types/schema/schema.d.ts +73 -0
  115. package/types/schema/sequence.d.ts +27 -0
  116. package/types/schema/table-index.d.ts +32 -0
  117. package/types/schema/values-table.d.ts +16 -0
  118. package/types/schema/view.d.ts +18 -0
  119. package/types/table.d.ts +97 -0
  120. package/types/transaction.d.ts +26 -0
  121. package/types/transforms/aggregation.d.ts +41 -0
  122. package/types/transforms/aggregations/array_agg.d.ts +11 -0
  123. package/types/transforms/aggregations/avg.d.ts +11 -0
  124. package/types/transforms/aggregations/bool-aggregs.d.ts +12 -0
  125. package/types/transforms/aggregations/count.d.ts +19 -0
  126. package/types/transforms/aggregations/json_aggs.d.ts +11 -0
  127. package/types/transforms/aggregations/max-min.d.ts +12 -0
  128. package/types/transforms/aggregations/sum.d.ts +11 -0
  129. package/types/transforms/alias.d.ts +29 -0
  130. package/types/transforms/and-filter.d.ts +15 -0
  131. package/types/transforms/array-filter.d.ts +14 -0
  132. package/types/transforms/between-filter.d.ts +16 -0
  133. package/types/transforms/build-filter.d.ts +4 -0
  134. package/types/transforms/distinct.d.ts +16 -0
  135. package/types/transforms/eq-filter.d.ts +17 -0
  136. package/types/transforms/false-filter.d.ts +11 -0
  137. package/types/transforms/in-filter.d.ts +14 -0
  138. package/types/transforms/ineq-filter.d.ts +16 -0
  139. package/types/transforms/join.d.ts +74 -0
  140. package/types/transforms/limit.d.ts +18 -0
  141. package/types/transforms/not-in-filter.d.ts +15 -0
  142. package/types/transforms/or-filter.d.ts +13 -0
  143. package/types/transforms/order-by.d.ts +26 -0
  144. package/types/transforms/restrictive-index.d.ts +15 -0
  145. package/types/transforms/selection.d.ts +45 -0
  146. package/types/transforms/seq-scan.d.ts +14 -0
  147. package/types/transforms/startswith-filter.d.ts +14 -0
  148. package/types/transforms/transform-base.d.ts +100 -0
  149. package/types/transforms/union.d.ts +32 -0
  150. package/types/utils.d.ts +86 -0
@@ -0,0 +1,449 @@
1
+ import { TableConstraint, CreateColumnDef, NodeLocation, DataTypeDef, FunctionArgumentMode, BinaryOperator, Statement } from 'pgsql-ast-parser';
2
+ import { MigrationParams } from './migrate/migrate-interfaces';
3
+ export type nil = undefined | null;
4
+ export type Schema = {
5
+ name: string;
6
+ fields: SchemaField[];
7
+ constraints?: TableConstraint[];
8
+ };
9
+ export interface SchemaField extends Omit<CreateColumnDef, 'dataType' | 'kind' | 'name'> {
10
+ type: IType | DataType;
11
+ name: string;
12
+ serial?: boolean;
13
+ }
14
+ export interface IType {
15
+ /** Data type */
16
+ readonly primary: DataType;
17
+ readonly name: string;
18
+ toString(): string;
19
+ /** Create an array type of this type */
20
+ asArray(): IType;
21
+ }
22
+ export declare enum DataType {
23
+ inet = "inet",
24
+ record = "record",
25
+ uuid = "uuid",
26
+ text = "text",
27
+ citext = "citext",
28
+ array = "array",
29
+ list = "list",
30
+ bigint = "bigint",
31
+ float = "float",
32
+ decimal = "decimal",
33
+ integer = "integer",
34
+ jsonb = "jsonb",
35
+ regtype = "regtype",
36
+ regclass = "regclass",
37
+ json = "json",
38
+ bytea = "bytea",
39
+ interval = "interval",
40
+ timestamp = "timestamp",
41
+ timestamptz = "timestamptz",
42
+ date = "date",
43
+ time = "time",
44
+ timetz = "timetz",
45
+ null = "null",
46
+ bool = "bool",
47
+ point = "point",
48
+ line = "line",
49
+ lseg = "lseg",
50
+ box = "box",
51
+ path = "path",
52
+ polygon = "polygon",
53
+ circle = "circle"
54
+ }
55
+ export interface MemoryDbOptions {
56
+ /**
57
+ * If set to true, pg-mem will stop embbeding info about the SQL statement
58
+ * that has failed in exception messages.
59
+ */
60
+ noErrorDiagnostic?: boolean;
61
+ /**
62
+ * If set to true, then the query runner will not check that no AST part
63
+ * has been left behind when parsing the request.
64
+ *
65
+ * ... so setting it to true could lead to unnoticed ignored query parts.
66
+ *
67
+ * (advice: only set it to true as a workaround while an issue on https://github.com/oguimbal/pg-mem is being fixed... )
68
+ */
69
+ noAstCoverageCheck?: boolean;
70
+ /**
71
+ * If set to true, this will throw an exception if
72
+ * you try to use an unsupported index type
73
+ * (only BTREE is supported at time of writing)
74
+ */
75
+ noIgnoreUnsupportedIndices?: boolean;
76
+ /**
77
+ * When set to true, this will auto create an index on foreign table when adding a foreign key.
78
+ * 👉 Recommanded when using Typeorm .synchronize(), which creates foreign keys but not indices !
79
+ **/
80
+ readonly autoCreateForeignKeyIndices?: boolean;
81
+ }
82
+ export interface IMemoryDb {
83
+ /**
84
+ * Adapters to create wrappers of this db compatible with known libraries
85
+ */
86
+ readonly adapters: LibAdapters;
87
+ /**
88
+ * The default 'public' schema
89
+ */
90
+ readonly public: ISchema;
91
+ /**
92
+ * Get an existing schema
93
+ */
94
+ getSchema(db?: string | null): ISchema;
95
+ /**
96
+ * Create a schema in this database
97
+ */
98
+ createSchema(name: string): ISchema;
99
+ /**
100
+ * Get a table to inspect it (in the public schema... this is a shortcut for db.public.getTable())
101
+ */
102
+ getTable<T = any>(table: string): IMemoryTable<T>;
103
+ getTable<T = any>(table: string, nullIfNotFound?: boolean): IMemoryTable<T> | null;
104
+ /** Subscribe to a global event */
105
+ on(event: 'query', handler: (query: string) => any): ISubscription;
106
+ on(event: GlobalEvent, handler: () => any): ISubscription;
107
+ on(event: GlobalEvent, handler: () => any): ISubscription;
108
+ /** Subscribe to an event on all tables */
109
+ on(event: TableEvent, handler: (table: string) => any): ISubscription;
110
+ /**
111
+ * Creates a restore point.
112
+ * 👉 This operation is O(1) (instantaneous, even with millions of records).
113
+ * */
114
+ backup(): IBackup;
115
+ /**
116
+ * Registers an extension (that can be installed using the 'create extension' statement)
117
+ * @param name Extension name
118
+ * @param install How to install this extension on a given schema
119
+ */
120
+ registerExtension(name: string, install: (schema: ISchema) => void): this;
121
+ /** Registers a new language, usable in 'DO' blocks, or in 'CREATE FUNCTION' blocks */
122
+ registerLanguage(languageName: string, compiler: LanguageCompiler): this;
123
+ }
124
+ export type QueryInterceptor = (query: string) => any[] | nil;
125
+ export type ArgDef = DataType | IType | ArgDefDetails;
126
+ export interface ArgDefDetails {
127
+ /** Argument type */
128
+ type: IType;
129
+ /** Optional argument name */
130
+ name?: string;
131
+ /**
132
+ * Arguments are 'in' by default, but you can change that.
133
+ */
134
+ mode?: FunctionArgumentMode;
135
+ }
136
+ export type LanguageCompiler = (options: ToCompile) => CompiledFunction;
137
+ export interface ToCompile {
138
+ /** Function being compiled (null for "DO" statements compilations) */
139
+ functionName?: string | nil;
140
+ /** Code to compile */
141
+ code: string;
142
+ /** Schema against which this compilation is performed */
143
+ schema: ISchema;
144
+ /** Expected arguments */
145
+ args: ArgDefDetails[];
146
+ /** Expected return type (if any) */
147
+ returns?: IType | nil;
148
+ }
149
+ export declare class AdvancedResult {
150
+ readonly result: any;
151
+ constructor(result: any, outArgs: any[]);
152
+ }
153
+ export type CompiledFunction = (...inArguments: any[]) => AdvancedResult | PlainResult;
154
+ export type PlainResult = Object | number | Date | null | void;
155
+ export interface CompiledFunctionResult {
156
+ /** The function result, if function "returns" something */
157
+ result?: any;
158
+ /** The functions out arguments, as indexed in the `args` passed to your language compiler function */
159
+ outArgs?: any[];
160
+ }
161
+ export interface IBackup {
162
+ /**
163
+ * Restores data to the state when this backup has been performed.
164
+ * 👉 This operation is O(1).
165
+ * 👉 Schema must not have been changed since then !
166
+ **/
167
+ restore(): void;
168
+ }
169
+ export interface LibAdapters {
170
+ /** Create a PG module that will be equivalent to require('pg') */
171
+ createPg(queryLatency?: number): {
172
+ Pool: any;
173
+ Client: any;
174
+ };
175
+ /** Create a pg-promise instance bound to this db */
176
+ createPgPromise(queryLatency?: number): any;
177
+ /** Create a slonik pool bound to this db */
178
+ createSlonik(opts?: SlonikAdapterOptions): Promise<any>;
179
+ /** Create a pg-native instance bound to this db */
180
+ createPgNative(queryLatency?: number): any;
181
+ /** Create a Typeorm connection bound to this db
182
+ * @deprecated Use `createTypeormDataSource` instead. See https://github.com/oguimbal/pg-mem/pull/238.
183
+ */
184
+ createTypeormConnection(typeOrmConnection: any, queryLatency?: number): any;
185
+ /** Create a Typeorm data source bound to this db */
186
+ createTypeormDataSource(typeOrmConnection: any, queryLatency?: number): any;
187
+ /** Create a Knex.js instance bound to this db */
188
+ createKnex(queryLatency?: number, knexConfig?: object): any;
189
+ /** Create a Kysely instance bound to this db */
190
+ createKysely(queryLatency?: number, kyselyConfig?: object): any;
191
+ /** Create a mikro-orm instance bound to this db */
192
+ createMikroOrm(mikroOrmOptions: any, queryLatency?: number): Promise<any>;
193
+ /** Creates a Postres.js `sql` tag bound to this db */
194
+ createPostgresJsTag(queryLatency?: number): any;
195
+ /** Binds a server to this instance */
196
+ bindServer(opts?: BindServerOptions): Promise<BindServerResult>;
197
+ }
198
+ export interface BindServerResult {
199
+ postgresConnectionString: string;
200
+ connectionSettings: {
201
+ host: string;
202
+ port: number;
203
+ };
204
+ close(): void;
205
+ }
206
+ export interface BindServerOptions {
207
+ /** defaults to a random port */
208
+ port?: number;
209
+ /** defaults to 'localhost' */
210
+ host?: string;
211
+ }
212
+ export interface SlonikAdapterOptions {
213
+ queryLatency?: number;
214
+ /** options you would give to the createPool() function */
215
+ createPoolOptions?: any;
216
+ /** add zod validation interceptor to create pool options, like with https://github.com/gajus/slonik?tab=readme-ov-file#result-parser-interceptor */
217
+ zodValidation?: boolean;
218
+ /** old versions of slonik, this be passed as client configuration */
219
+ clientConfigurationInput?: any;
220
+ }
221
+ export type QueryOrAst = string | Statement | Statement[];
222
+ export interface IPreparedQuery {
223
+ describe(): QueryDescription;
224
+ bind(args?: any[]): IBoundQuery;
225
+ }
226
+ export interface QueryDescription {
227
+ parameters: ParameterInfo[];
228
+ result: FieldInfo[];
229
+ }
230
+ export interface ParameterInfo {
231
+ type: DataType;
232
+ typeId: number;
233
+ }
234
+ export interface IBoundQuery {
235
+ /** Executes all statements */
236
+ executeAll(): QueryResult;
237
+ /**
238
+ * Progressively executes a query that contains multiple statements, yielding results until the end of enumeration (or an exception)
239
+ */
240
+ iterate(): IterableIterator<QueryResult>;
241
+ }
242
+ export interface ISchema {
243
+ /**
244
+ * Another way to create tables (equivalent to "create table" queries")
245
+ */
246
+ declareTable(table: Schema): IMemoryTable<any>;
247
+ /**
248
+ * Execute a query and return many results
249
+ */
250
+ many(query: QueryOrAst): any[];
251
+ /**
252
+ * Execute a query without results
253
+ */
254
+ none(query: QueryOrAst): void;
255
+ /**
256
+ * Execute a query with a single result
257
+ */
258
+ one(query: QueryOrAst): any;
259
+ /**
260
+ * Execute a query that has no argument, and returns the latest query result
261
+ * (shortcut for .prepare(cmd).bind().executeAll())
262
+ */
263
+ query(text: QueryOrAst): QueryResult;
264
+ /**
265
+ * Progressively executes a query that has no argument, yielding results until the end of enumeration (or an exception)
266
+ * (shortcut for .prepare(cmd).bind().iterate())
267
+ */
268
+ queries(text: QueryOrAst): Iterable<QueryResult>;
269
+ /**
270
+ * Prepare a query
271
+ */
272
+ prepare(text: QueryOrAst): IPreparedQuery;
273
+ /**
274
+ * Get a table in this db to inspect it
275
+ */
276
+ getTable(table: string): IMemoryTable<unknown>;
277
+ getTable(table: string, nullIfNotFound?: boolean): IMemoryTable<unknown> | null;
278
+ /**
279
+ * List all tables in this schema
280
+ */
281
+ listTables(): Iterable<IMemoryTable<unknown>>;
282
+ /** Register a function */
283
+ registerFunction(fn: FunctionDefinition, orReplace?: boolean): this;
284
+ /** Register a binary operator */
285
+ registerOperator(fn: OperatorDefinition): this;
286
+ /** Register a simple type, which is equivalent to another */
287
+ registerEquivalentType(type: IEquivalentType): IType;
288
+ /** Register a simple type, which is equivalent to another */
289
+ registerEquivalentSizableType(type: IEquivalentType): IType;
290
+ /** Get an existing type */
291
+ getType(name: DataType): IType;
292
+ /**
293
+ * Registers an enum type on this schema
294
+ * @param name Enum name
295
+ * @param values Possible values
296
+ */
297
+ registerEnum(name: string, values: string[]): void;
298
+ /**
299
+ * Database migration, node-sqlite flavor
300
+ * ⚠ Only working when runnin nodejs !
301
+ */
302
+ migrate(config?: MigrationParams): Promise<void>;
303
+ /**
304
+ * Intecept queries.
305
+ * If your interceptor returns an array, then the query will not be executed.
306
+ * The given result will be returned instead.
307
+ */
308
+ interceptQueries(interceptor: QueryInterceptor): ISubscription;
309
+ }
310
+ export interface FunctionDefinition {
311
+ /** Function name (casing doesnt matter) */
312
+ name: string;
313
+ /** Expected arguments */
314
+ args?: ArgDef[] | nil;
315
+ /** Other arguments type (variadic arguments) */
316
+ argsVariadic?: DataType | IType | nil;
317
+ /** Returned data type */
318
+ returns?: DataType | IType | nil;
319
+ /**
320
+ * If the function is marked as impure, it will not be simplified
321
+ * (ex: "select myFn(1) from myTable" will call myFn() for each row in myTable, even if it does not depend on its result) */
322
+ impure?: boolean;
323
+ /** If true, the function will also be called when passing null arguments */
324
+ allowNullArguments?: boolean;
325
+ /** Actual implementation of the function */
326
+ implementation: CompiledFunction;
327
+ }
328
+ export interface OperatorDefinition {
329
+ /** Function name (casing doesnt matter) */
330
+ operator: BinaryOperator;
331
+ /** Expected left argument */
332
+ left: DataType | IType;
333
+ /** Expected right argument */
334
+ right: DataType | IType;
335
+ /** True if the operator is commutative (if left & right can be inverted) */
336
+ commutative?: boolean;
337
+ /** Returned data type */
338
+ returns: DataType | IType;
339
+ /**
340
+ * If the function is marked as impure, it will not be simplified
341
+ * (ex: "select myFn(1) from myTable" will call myFn() for each row in myTable, even if it does not depend on its result) */
342
+ impure?: boolean;
343
+ /** If true, the function will also be called when passing null arguments */
344
+ allowNullArguments?: boolean;
345
+ /** Actual implementation of the function */
346
+ implementation: CompiledFunction;
347
+ }
348
+ export interface QueryResult {
349
+ /** Last command that has been executed */
350
+ command: string;
351
+ rowCount: number;
352
+ fields: Array<FieldInfo>;
353
+ rows: any[];
354
+ /** Location of the last ";" prior to this statement */
355
+ location: NodeLocation;
356
+ }
357
+ export interface FieldInfo {
358
+ name: string;
359
+ type: DataType;
360
+ typeId: number;
361
+ }
362
+ export type TableEvent = 'seq-scan';
363
+ export type GlobalEvent = 'query' | 'query-failed' | 'catastrophic-join-optimization' | 'schema-change' | 'create-extension';
364
+ export interface IMemoryTable<T> {
365
+ readonly comment?: string | nil;
366
+ readonly name: string;
367
+ readonly primaryIndex: IndexDef | nil;
368
+ /** List columns in this table */
369
+ getColumns(): Iterable<ColumnDef>;
370
+ /** Subscribe to an event on this table */
371
+ on(event: TableEvent, handler: () => any): ISubscription;
372
+ /** List existing indices defined on this table */
373
+ listIndices(): IndexDef[];
374
+ /**
375
+ * Inserts a raw item into this table.
376
+ * ⚠ Neither the record you provided, nor the returned value are the actual item stored. You wont be able to mutate internal state.
377
+ * @returns A copy of the inserted item (with assigned defaults)
378
+ */
379
+ insert(item: Partial<T>): T | null;
380
+ /** Find all items matching a specific template */
381
+ find<keys extends (keyof T)[]>(template?: Partial<T> | nil, columns?: keys): Pick<T, ArrayToUnionOr<keys, keyof T>>[];
382
+ }
383
+ type ArrayToUnionOr<T, Or> = T extends (infer U)[] ? U : Or;
384
+ export interface ColumnDef {
385
+ readonly name: string;
386
+ readonly type: IType;
387
+ readonly comment?: string | nil;
388
+ readonly nullable: boolean;
389
+ readonly generated: boolean;
390
+ readonly hasDefault: boolean;
391
+ }
392
+ export interface ISubscription {
393
+ unsubscribe(): void;
394
+ }
395
+ export interface IndexDef {
396
+ readonly name: string;
397
+ readonly expressions: string[];
398
+ readonly unique: boolean;
399
+ }
400
+ export declare class NotSupported extends Error {
401
+ constructor(what?: string);
402
+ static never(value: never, msg?: string): NotSupported;
403
+ }
404
+ interface ErrorData {
405
+ readonly error: string;
406
+ readonly details?: string;
407
+ readonly hint?: string;
408
+ readonly code?: string;
409
+ }
410
+ export declare class QueryError extends Error {
411
+ readonly data: ErrorData;
412
+ readonly code: string | undefined;
413
+ constructor(err: string | ErrorData, code?: string);
414
+ }
415
+ export declare class CastError extends QueryError {
416
+ constructor(from: string | DataType | IType, to: string | DataType | IType, inWhat?: string);
417
+ }
418
+ export declare class ColumnNotFound extends QueryError {
419
+ constructor(col: string);
420
+ }
421
+ export declare class AmbiguousColumn extends QueryError {
422
+ constructor(col: string);
423
+ }
424
+ export declare class RelationNotFound extends QueryError {
425
+ constructor(tableName: string);
426
+ }
427
+ export declare class TypeNotFound extends QueryError {
428
+ constructor(t: string | number | DataTypeDef);
429
+ }
430
+ export declare class RecordExists extends QueryError {
431
+ constructor();
432
+ }
433
+ export declare class PermissionDeniedError extends QueryError {
434
+ constructor(what?: string);
435
+ }
436
+ export declare function typeDefToStr(t: DataTypeDef): string;
437
+ /** A type definition that is equivalent to another type */
438
+ export interface IEquivalentType {
439
+ /** Type name */
440
+ readonly name: string;
441
+ /** Which underlying type is it equivalent to ? */
442
+ readonly equivalentTo: DataType | IType;
443
+ /**
444
+ * Is this value valid ?
445
+ */
446
+ isValid(value: any): boolean;
447
+ }
448
+ export {};
449
+ //# sourceMappingURL=interfaces.d.ts.map
@@ -0,0 +1,32 @@
1
+ export interface MigrationParams {
2
+ /**
3
+ * If true, will force the migration API to rollback and re-apply the latest migration over
4
+ * again each time when Node.js app launches.
5
+ */
6
+ force?: boolean;
7
+ /**
8
+ * Migrations table name. Default is 'migrations'
9
+ */
10
+ table?: string;
11
+ /**
12
+ * Path to the migrations folder. Default is `path.join(process.cwd(), 'migrations')`
13
+ */
14
+ migrationsPath?: string;
15
+ /**
16
+ * Migration data read from migrations folder. `migrationsPath` will be ignored if this is
17
+ * provided.
18
+ */
19
+ migrations?: readonly MigrationData[];
20
+ }
21
+ export interface MigrationFile {
22
+ id: number;
23
+ name: string;
24
+ filename: string;
25
+ }
26
+ export interface MigrationData {
27
+ id: number;
28
+ name: string;
29
+ up: string;
30
+ down: string;
31
+ }
32
+ //# sourceMappingURL=migrate-interfaces.d.ts.map
@@ -0,0 +1,8 @@
1
+ import { _ISchema } from '../interfaces-private';
2
+ import { MigrationData, MigrationParams } from './migrate-interfaces';
3
+ export declare function readMigrations(migrationPath?: string): Promise<MigrationData[]>;
4
+ /**
5
+ * Migrates database schema to the latest version
6
+ */
7
+ export declare function migrate(db: _ISchema, config?: MigrationParams): Promise<void>;
8
+ //# sourceMappingURL=migrate.d.ts.map
@@ -0,0 +1,7 @@
1
+ export type TBuffer = Uint8Array;
2
+ export declare function bufToString(buf: TBuffer): string;
3
+ export declare function bufCompare(a: TBuffer, b: TBuffer): 0 | 1 | -1;
4
+ export declare function bufFromString(str: string): Uint8Array;
5
+ export declare function isBuf(v: any): v is TBuffer;
6
+ export declare function bufClone(buf: TBuffer): TBuffer;
7
+ //# sourceMappingURL=buffer-deno.d.ts.map
@@ -0,0 +1,7 @@
1
+ export type TBuffer = Buffer;
2
+ export declare function bufToString(buf: TBuffer): string;
3
+ export declare function bufCompare(a: TBuffer, b: TBuffer): 0 | 1 | -1;
4
+ export declare function bufFromString(str: string): Buffer;
5
+ export declare function isBuf(v: any): v is TBuffer;
6
+ export declare function bufClone(buf: TBuffer): TBuffer;
7
+ //# sourceMappingURL=buffer-node.d.ts.map
@@ -0,0 +1,2 @@
1
+ export declare function literal(val: any): string;
2
+ //# sourceMappingURL=pg-escape.d.ts.map
@@ -0,0 +1,3 @@
1
+ export declare function toLiteral(val: any): any;
2
+ export declare function normalizeQueryConfig(config: any, values: any, callback: any): any;
3
+ //# sourceMappingURL=pg-utils.d.ts.map
@@ -0,0 +1,26 @@
1
+ import { _ISchema, _ISelection, _IDb, OnStatementExecuted, nil, _IStatement, IValue, Parameter, _IType } from '../interfaces-private';
2
+ export interface INameResolver {
3
+ /** Try to resolve a name */
4
+ resolve(name: string): IValue | nil;
5
+ /** True if is isolated... meaning that one cannot fetch values from its parent */
6
+ readonly isolated: boolean;
7
+ }
8
+ interface IBuildContext {
9
+ readonly selection: _ISelection;
10
+ readonly db: _IDb;
11
+ readonly schema: _ISchema;
12
+ readonly onFinishExecution: (callback: OnStatementExecuted) => void;
13
+ readonly getTempBinding: (name: string) => _ISelection | nil;
14
+ readonly setTempBinding: (name: string, boundTo: _ISelection) => void;
15
+ readonly getParameter: (nameOrPosition: string | number) => IValue | nil;
16
+ readonly setParameterType: (nameOrPosition: number, type: _IType) => void;
17
+ }
18
+ export declare function buildCtx(): IBuildContext;
19
+ export declare const withSelection: <ret>(value: _ISelection, act: () => ret) => ret;
20
+ export declare const withStatement: <ret>(value: _IStatement, act: () => ret) => ret;
21
+ export declare function withBindingScope<T>(act: () => T): T;
22
+ export declare const withParameters: <ret>(value: Parameter[], act: () => ret) => ret;
23
+ export declare const withNameResolver: <ret>(value: INameResolver, act: () => ret) => ret;
24
+ export declare function resolveName(name: string): IValue | null;
25
+ export {};
26
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1,8 @@
1
+ import { _ISelection, IValue } from '../interfaces-private';
2
+ import { nil } from '../interfaces';
3
+ import { Expr, BinaryOperator } from 'pgsql-ast-parser';
4
+ export declare function buildValue(val: Expr): IValue;
5
+ export declare function uncache(data: _ISelection): void;
6
+ export declare function buildBinaryValue(leftValue: IValue, op: BinaryOperator, rightValue: IValue): IValue;
7
+ export declare function sqlSubstring(value: string, from?: number, len?: number | nil): string | null;
8
+ //# sourceMappingURL=expression-builder.d.ts.map
@@ -0,0 +1,4 @@
1
+ import { IValue } from '../interfaces-private';
2
+ import { QName } from 'pgsql-ast-parser';
3
+ export declare function buildCall(name: string | QName, args: IValue[]): IValue;
4
+ //# sourceMappingURL=function-call.d.ts.map
@@ -0,0 +1,6 @@
1
+ import { Expr, Statement } from 'pgsql-ast-parser';
2
+ export declare function enableStatementLocationTracking(): void;
3
+ /** Parse an AST from SQL */
4
+ export declare function parseSql(sql: string): Statement[];
5
+ export declare function parseSql(sql: string, entry: 'expr'): Expr;
6
+ //# sourceMappingURL=parse-cache.d.ts.map
@@ -0,0 +1,48 @@
1
+ import { IValue, _ITable, IndexKey, CreateIndexColDef, _Transaction, _Explainer, _IndexExplanation, IndexExpression, IndexOp, Stats, _INamedIndex, Reg, _ISchema, Row } from '../interfaces-private';
2
+ import { nil } from '../interfaces';
3
+ export declare class BIndex implements _INamedIndex {
4
+ readonly name: string;
5
+ readonly cols: readonly CreateIndexColDef[];
6
+ readonly onTable: _ITable;
7
+ readonly hash: string;
8
+ readonly unique: boolean;
9
+ readonly notNull: boolean;
10
+ readonly predicate: IValue | nil;
11
+ get type(): 'index';
12
+ readonly reg: Reg;
13
+ expressions: (IndexExpression & IValue)[];
14
+ private treeBinId;
15
+ private treeCountId;
16
+ get ownerSchema(): _ISchema;
17
+ constructor(t: _Transaction, name: string, cols: readonly CreateIndexColDef[], onTable: _ITable, hash: string, unique: boolean, notNull: boolean, predicate: IValue | nil);
18
+ drop(t: _Transaction): void;
19
+ compare(_a: any, _b: any): number;
20
+ buildKey(raw: any, t: _Transaction): any[];
21
+ truncate(t: _Transaction): void;
22
+ dropFromData(t: _Transaction): void;
23
+ private bin;
24
+ private setBin;
25
+ private setCount;
26
+ private getCount;
27
+ hasKey(key: IndexKey[], t: _Transaction): boolean;
28
+ add(raw: Row, t: _Transaction): void;
29
+ delete(raw: any, t: _Transaction): void;
30
+ eqFirst(rawKey: IndexKey, t: _Transaction): Row | null;
31
+ nin(rawKey: IndexKey[], t: _Transaction): Iterable<Row>;
32
+ entropy(op: IndexOp): number;
33
+ stats(t: _Transaction, key?: IndexKey): Stats;
34
+ iterateKeys(t: _Transaction): Iterable<IndexKey>;
35
+ private _keyCount;
36
+ enumerate(op: IndexOp): Iterable<Row>;
37
+ private _enumerate;
38
+ eq(key: IndexKey, t: _Transaction, matchNull: boolean): Iterable<Row>;
39
+ neq(key: IndexKey, t: _Transaction, matchNull: boolean): Iterable<Row>;
40
+ gt(key: IndexKey, t: _Transaction): Iterable<Row>;
41
+ ge(key: IndexKey, t: _Transaction): Iterable<Row>;
42
+ lt(key: IndexKey, t: _Transaction): Iterable<Row>;
43
+ le(key: IndexKey, t: _Transaction): Iterable<Row>;
44
+ outside(lo: IndexKey, hi: IndexKey, t: _Transaction): Iterable<Row>;
45
+ inside(lo: IndexKey, hi: IndexKey, t: _Transaction): Iterable<Row>;
46
+ explain(e: _Explainer): _IndexExplanation;
47
+ }
48
+ //# sourceMappingURL=btree-index.d.ts.map
@@ -0,0 +1,10 @@
1
+ export declare const SCHEMA_NAMESPACE = 11;
2
+ export declare const MAIN_NAMESPACE = 2200;
3
+ type OidType = 'table' | 'index';
4
+ export declare function makeOid(type: OidType, id: string): string;
5
+ export declare function parseOid(oid: string): {
6
+ type: OidType;
7
+ id: string;
8
+ };
9
+ export {};
10
+ //# sourceMappingURL=consts.d.ts.map
@@ -0,0 +1,31 @@
1
+ import { _IIndex, IValue, _ITable, _Transaction, _Explainer, _IndexExplanation, IndexOp, IndexKey, Stats, Row } from '../interfaces-private';
2
+ interface IndexSubject {
3
+ readonly size: number;
4
+ readonly column: IValue;
5
+ byColumnValue(columnValue: string, t: _Transaction): Row[];
6
+ }
7
+ export declare class CustomIndex implements _IIndex {
8
+ readonly onTable: _ITable;
9
+ private subject;
10
+ readonly expressions: IValue[];
11
+ explain(e: _Explainer): _IndexExplanation;
12
+ constructor(onTable: _ITable, subject: IndexSubject);
13
+ get indexName(): string;
14
+ entropy(): number;
15
+ stats(t: _Transaction, key?: IndexKey): Stats | null;
16
+ iterateKeys(): null;
17
+ add(raw: any): void;
18
+ eqFirst([key]: any, t: _Transaction): any;
19
+ enumerate(op: IndexOp): Iterable<Row>;
20
+ eq([rawKey]: any, t: _Transaction): Iterable<any>;
21
+ nin(keys: any[][], t: _Transaction): Generator<any, void, unknown>;
22
+ neq([rawKey]: any, t: _Transaction): Generator<any, void, unknown>;
23
+ gt(rawKey: any, t: _Transaction): Iterable<any>;
24
+ lt(rawKey: any, t: _Transaction): Iterable<any>;
25
+ ge(rawKey: any, t: _Transaction): Iterable<any>;
26
+ le(rawKey: any, t: _Transaction): Iterable<any>;
27
+ outside(lo: IndexKey, hi: IndexKey, t: _Transaction): Iterable<Row>;
28
+ inside(lo: IndexKey, hi: IndexKey, t: _Transaction): Iterable<Row>;
29
+ }
30
+ export {};
31
+ //# sourceMappingURL=custom-index.d.ts.map
@@ -0,0 +1,20 @@
1
+ import { _Transaction, IValue, _Explainer, _IIndex, _SelectExplanation, Stats } from '../interfaces-private';
2
+ import { RecordCol } from '../datatypes';
3
+ import { DataSourceBase } from '../transforms/transform-base';
4
+ export declare class FunctionCallTable extends DataSourceBase {
5
+ private evaluator;
6
+ readonly columns: readonly IValue[];
7
+ private readonly colsByName;
8
+ private symbol;
9
+ get isExecutionWithNoResult(): boolean;
10
+ constructor(cols: readonly RecordCol[], evaluator: IValue);
11
+ entropy(t: _Transaction): number;
12
+ enumerate(t: _Transaction): Iterable<any>;
13
+ hasItem(value: any, t: _Transaction): boolean;
14
+ getColumn(column: string, nullIfNotFound?: boolean | undefined): IValue;
15
+ getIndex(forValue: IValue): _IIndex | null | undefined;
16
+ isOriginOf(value: IValue): boolean;
17
+ explain(e: _Explainer): _SelectExplanation;
18
+ stats(t: _Transaction): Stats | null;
19
+ }
20
+ //# sourceMappingURL=function-call-table.d.ts.map