@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,605 @@
1
+ import { IMemoryDb, IMemoryTable, DataType, IType, TableEvent, GlobalEvent, ISchema, SchemaField, MemoryDbOptions, nil, Schema, ISubscription, LanguageCompiler, ArgDefDetails, QueryResult, IBoundQuery, IPreparedQuery } from './interfaces';
2
+ import { Expr, SelectedColumn, CreateColumnDef, AlterColumn, LimitStatement, OrderByStatement, TableConstraint, AlterSequenceChange, CreateSequenceOptions, QName, DataTypeDef, ExprRef, Name, BinaryOperator, CreateExtensionStatement, DropFunctionStatement, ExprCall } from 'pgsql-ast-parser';
3
+ import { Map as ImMap, Record, Set as ImSet } from 'immutable';
4
+ export * from './interfaces';
5
+ export declare const GLOBAL_VARS: unique symbol;
6
+ export declare function getId(item: any): string;
7
+ export declare function setId<T = any>(item: T, id: string): T;
8
+ export type RegClass = string | number;
9
+ export type RegType = string | number;
10
+ export type TypeQuery = DataTypeDef | DataType | number | _IType;
11
+ export interface _ISchema extends ISchema {
12
+ readonly name: string;
13
+ readonly db: _IDb;
14
+ readonly dualTable: _ITable;
15
+ /** @deprecated for debug purposes */
16
+ lastSelect?: _ISelection;
17
+ /** If the given name refers to another schema, then get it. Else, get this */
18
+ getThisOrSiblingFor(name: QName): _ISchema;
19
+ executeCreateExtension(p: CreateExtensionStatement): void;
20
+ dropFunction(fn: DropFunctionStatement): void;
21
+ explainSelect(sql: string): _SelectExplanation;
22
+ explainLastSelect(): _SelectExplanation | undefined;
23
+ getTable(table: string): _ITable;
24
+ getTable(table: string, nullIfNotFound?: boolean): _ITable;
25
+ tablesCount(t: _Transaction): number;
26
+ listTables(t?: _Transaction): Iterable<_ITable>;
27
+ declareTable(table: Schema, noSchemaChange?: boolean): _ITable;
28
+ createSequence(t: _Transaction, opts: CreateSequenceOptions | nil, name: QName | nil): _ISequence;
29
+ /** Get functions matching this overload */
30
+ resolveFunction(name: string | QName, args: IValue[], forceOwn?: boolean): _FunctionDefinition | nil;
31
+ /** Get an exact function def from its signature (do not use that to resolve overload) */
32
+ getFunction(name: string, args: _IType[]): _FunctionDefinition | nil;
33
+ /** Get operator matching this overload */
34
+ resolveOperator(name: BinaryOperator, left: IValue, right: IValue, forceOwn?: boolean): _OperatorDefinition | nil;
35
+ getObject(p: QName): _IRelation;
36
+ getObject(p: QName, opts: BeingCreated): _IRelation;
37
+ getObject(p: QName, opts?: QueryObjOpts): _IRelation | null;
38
+ getOwnObject(name: string): _IRelation | null;
39
+ parseType(t: string): _IType;
40
+ getType(t: TypeQuery): _IType;
41
+ getType(_t: TypeQuery, opts?: QueryObjOpts): _IType | null;
42
+ getOwnType(name: DataTypeDef): _IType | null;
43
+ getObjectByRegClassId(reg: number): _IRelation;
44
+ getObjectByRegClassId(reg: number, opts?: QueryObjOpts): _IRelation | null;
45
+ getOwnObjectByRegClassId(reg: number): _IRelation | null;
46
+ getObjectByRegOrName(reg: RegClass): _IRelation;
47
+ getObjectByRegOrName(reg: RegClass, opts?: QueryObjOpts): _IRelation | null;
48
+ setReadonly(): void;
49
+ _registerTypeSizeable(name: string, type: (sz?: number) => _IType): this;
50
+ _registerType(type: _IType): this;
51
+ _unregisterType(type: _IType): this;
52
+ _reg_register(rel: _IRelation): Reg;
53
+ _reg_unregister(rel: _IRelation): void;
54
+ _reg_rename(rel: _IRelation, oldName: string, newName: string): void;
55
+ }
56
+ export interface _IStatement {
57
+ readonly schema: _ISchema;
58
+ onExecuted(callback: OnStatementExecuted): void;
59
+ }
60
+ export interface _IStatementExecutor {
61
+ execute(t: _Transaction): StatementResult;
62
+ }
63
+ export interface StatementResult {
64
+ result: QueryResult;
65
+ state: _Transaction;
66
+ }
67
+ export type OnStatementExecuted = (t: _Transaction) => void;
68
+ export interface QueryObjOpts extends Partial<BeingCreated> {
69
+ /** Returns null instead of throwing error if not found */
70
+ nullIfNotFound?: boolean;
71
+ /** Will only search in the current schema, or in the targeted schema (not in search path) */
72
+ skipSearch?: boolean;
73
+ }
74
+ export interface BeingCreated {
75
+ beingCreated: _IRelation;
76
+ }
77
+ export interface _FunctionDefinition {
78
+ name: string;
79
+ args: _ArgDefDetails[];
80
+ argsVariadic?: _IType | nil;
81
+ returns?: _IType | nil;
82
+ impure?: boolean;
83
+ allowNullArguments?: boolean;
84
+ implementation: (...args: any[]) => any;
85
+ }
86
+ export interface _OperatorDefinition extends _FunctionDefinition {
87
+ commutative: boolean;
88
+ left: _IType;
89
+ right: _IType;
90
+ returns: _IType;
91
+ }
92
+ export type _ArgDefDetails = ArgDefDetails & {
93
+ type: _IType;
94
+ default?: IValue;
95
+ };
96
+ export interface _Transaction {
97
+ readonly isChild: boolean;
98
+ /** Create a new transaction within this transaction */
99
+ fork(): _Transaction;
100
+ /** Commit this transaction (returns the parent transaction) */
101
+ commit(): _Transaction;
102
+ /** Commits this transaction and all underlying transactions */
103
+ fullCommit(): _Transaction;
104
+ rollback(): _Transaction;
105
+ delete(identity: symbol): void;
106
+ /** Set data persisted in this transaction */
107
+ set<T>(identity: symbol, data: T): T;
108
+ /** Get data persisted in this transaction */
109
+ get<T>(identity: symbol): T;
110
+ getMap<T extends ImMap<any, any>>(identity: symbol): T;
111
+ getSet<T>(identity: symbol): ImSet<T>;
112
+ /** Get transient data, which will only exist within the scope of the current statement */
113
+ setTransient<T>(identity: symbol, data: T): T;
114
+ /** Set transient data, which will only exist within the scope of the current statement */
115
+ getTransient<T>(identity: symbol): T;
116
+ clearTransientData(): void;
117
+ }
118
+ export interface Stats {
119
+ /** Returns this selection size, or null if it cannot be computed without iteration */
120
+ count: number;
121
+ }
122
+ export interface _IAggregation {
123
+ checkIfIsKey(got: IValue): IValue;
124
+ getAggregation(name: string, call: ExprCall): IValue;
125
+ }
126
+ export type Row = any;
127
+ export interface _ISelection extends _IAlias {
128
+ readonly debugId?: string;
129
+ readonly ownerSchema: _ISchema;
130
+ readonly db: _IDb;
131
+ /** Tells if this statement is an execution without any meaningful result ("update" with no "returning", etc...) */
132
+ readonly isExecutionWithNoResult: boolean;
133
+ /** Column list (those visible when select *) */
134
+ readonly columns: ReadonlyArray<IValue>;
135
+ /** True when this is an aggregation being built */
136
+ isAggregation(): this is _IAggregation;
137
+ /** Statistical measure of how many items will be returned by this selection */
138
+ entropy(t: _Transaction): number;
139
+ enumerate(t: _Transaction): Iterable<Row>;
140
+ /** Returns true if the given value is present in this */
141
+ hasItem(value: Row, t: _Transaction): boolean;
142
+ stats(t: _Transaction): Stats | null;
143
+ /** Gets the index associated with this value (or returns null) */
144
+ getIndex(...forValue: IValue[]): _IIndex | nil;
145
+ /** All columns. A bit like .columns`, but including records selections */
146
+ listSelectableIdentities(): Iterable<IValue>;
147
+ filter(where: Expr | nil): _ISelection;
148
+ limit(limit: LimitStatement): _ISelection;
149
+ orderBy(orderBy: OrderByStatement[] | nil): _ISelection;
150
+ groupBy(grouping: Expr[] | nil): _ISelection;
151
+ distinct(select?: Expr[]): _ISelection;
152
+ union(right: _ISelection): _ISelection;
153
+ getColumn(column: string | ExprRef): IValue;
154
+ getColumn(column: string | ExprRef, nullIfNotFound?: boolean): IValue | nil;
155
+ setAlias(alias?: string): _ISelection;
156
+ isOriginOf(a: IValue): boolean;
157
+ explain(e: _Explainer): _SelectExplanation;
158
+ /** Select a specific subset */
159
+ select(select: (string | SelectedColumn)[]): _ISelection;
160
+ /** Limit selection to a specific alias (in joins) */
161
+ selectAlias(alias: string): _IAlias | nil;
162
+ }
163
+ export interface _IAlias {
164
+ listColumns(): Iterable<IValue>;
165
+ }
166
+ export interface _Explainer {
167
+ readonly transaction: _Transaction;
168
+ idFor(sel: _ISelection): string | number;
169
+ }
170
+ export type _SelectExplanation = {
171
+ /** A jointure */
172
+ id: string | number;
173
+ _: 'join';
174
+ /** The restrictive table (the one which MUST have a matched elemnt) */
175
+ restrictive: _SelectExplanation;
176
+ /** The joined table */
177
+ joined: _SelectExplanation;
178
+ inner: boolean;
179
+ on: {
180
+ /** 'with' will have to be scanned with this expression */
181
+ seqScan: _ExprExplanation;
182
+ } | {
183
+ /** Which seq id will be iterated (could be either 'join' or 'with' when there is an inner join) */
184
+ iterate: string | number;
185
+ /** Which iteration side has been chosen (always 'restrictive' for non inner joins) */
186
+ iterateSide: 'joined' | 'restrictive';
187
+ /** the index table on the other table that can be used to lookup corresponding item(s) */
188
+ joinIndex: _IndexExplanation;
189
+ /** It will be matched with this expression (computable from the other table) */
190
+ matches: _ExprExplanation;
191
+ /** True if there is a predicate filter that is also applied (happens when there are 'ANDs' in join condition) */
192
+ filtered?: boolean;
193
+ };
194
+ } | {
195
+ /** A selection transformation */
196
+ id: string | number;
197
+ _: 'map';
198
+ select?: {
199
+ what: _ExprExplanation;
200
+ as: string;
201
+ }[];
202
+ of: _SelectExplanation;
203
+ } | {
204
+ id: string | number;
205
+ _: 'orderBy';
206
+ of: _SelectExplanation;
207
+ } | {
208
+ /** A selection transformation */
209
+ id: string | number;
210
+ _: 'limit';
211
+ take?: _ExprExplanation;
212
+ skip?: _ExprExplanation;
213
+ on: _SelectExplanation;
214
+ } | {
215
+ /** A selection transformation */
216
+ id: string | number;
217
+ _: 'distinct';
218
+ of: _SelectExplanation;
219
+ } | {
220
+ /** A table */
221
+ _: 'table';
222
+ table: string;
223
+ } | {
224
+ /** An AND filter */
225
+ id: string | number;
226
+ _: 'and';
227
+ enumerate: _SelectExplanation;
228
+ andCheck: _SelectExplanation[];
229
+ } | {
230
+ /** A raw array definition */
231
+ id: string | number;
232
+ _: 'constantSet';
233
+ rawArrayLen: number;
234
+ } | {
235
+ /** One of the following operators on an index:
236
+ * - (NOT) IN
237
+ * - (NOT) LIKE
238
+ * - (NOT) BETWEEN
239
+ * - < > <= >= = !=
240
+ *
241
+ * (against constants) */
242
+ id: string | number;
243
+ _: 'eq' | 'ineq' | 'neq' | 'inside' | 'outside';
244
+ entropy: number;
245
+ /** The index that will be used to check equality */
246
+ on: _IndexExplanation;
247
+ } | {
248
+ /** An empty set */
249
+ id: string | number;
250
+ _: 'empty';
251
+ } | {
252
+ /** An union set */
253
+ id: string | number;
254
+ _: 'union';
255
+ union: _SelectExplanation[];
256
+ } | {
257
+ /** A seq-scan filter of another set */
258
+ id: string | number;
259
+ _: 'seqFilter';
260
+ filtered: _SelectExplanation;
261
+ } | {
262
+ id: string | number;
263
+ _: 'aggregate';
264
+ aggregator: {
265
+ /** aggregation will iterate the whole lot */
266
+ seqScan: _ExprExplanation;
267
+ } | {
268
+ /** aggregation uses an index items which already contains required aggregations */
269
+ index: _IndexExplanation;
270
+ } | {
271
+ /** aggregation is trivial (select count(*) from table) */
272
+ trivial: _ISelection;
273
+ };
274
+ };
275
+ export type _IndexExplanation = {
276
+ /** BTree index on expression */
277
+ _: 'btree';
278
+ onTable: string;
279
+ btree: string[];
280
+ } | {
281
+ _: 'indexMap';
282
+ of: _IndexExplanation;
283
+ } | {
284
+ _: 'indexRestriction';
285
+ /** This index will receive a lookup for each item of "for" collection */
286
+ lookup: _IndexExplanation;
287
+ /** Enumerated collection */
288
+ for: _SelectExplanation;
289
+ } | {
290
+ /** Uses an index of a column propagated by a join */
291
+ _: 'indexOnJoin';
292
+ /** The in propagated column that is used */
293
+ index: _IndexExplanation;
294
+ /** How elements from the other table will be joined */
295
+ strategy: _IndexExplanation | 'catastrophic';
296
+ };
297
+ export type _ExprExplanation = {
298
+ constant: true;
299
+ } | {
300
+ /** ID of the origin of this selection */
301
+ on: string | number;
302
+ col: string;
303
+ };
304
+ export interface _IDb extends IMemoryDb {
305
+ readonly options: MemoryDbOptions;
306
+ readonly public: _ISchema;
307
+ readonly data: _Transaction;
308
+ readonly searchPath: ReadonlyArray<string>;
309
+ createSchema(db: string): _ISchema;
310
+ getSchema(db?: string | null, nullIfNotFound?: false): _ISchema;
311
+ getSchema(db: string, nullIfNotFound: true): _ISchema | null;
312
+ raiseTable(table: string, event: TableEvent): void;
313
+ raiseGlobal(event: GlobalEvent, ...args: any[]): void;
314
+ listSchemas(): _ISchema[];
315
+ onSchemaChange(): void;
316
+ getTable(name: string, nullIfNotExists?: boolean): _ITable;
317
+ getExtension(name: string): (schema: ISchema) => void;
318
+ /** Get functions matching this overload */
319
+ resolveFunction(name: string | QName, types: IValue[]): _FunctionDefinition | nil;
320
+ /** Get operators matching this overload */
321
+ resolveOperator(name: BinaryOperator, left: IValue, right: IValue): _OperatorDefinition | nil;
322
+ getLanguage(name: string): LanguageCompiler;
323
+ }
324
+ export type OnConflictHandler = {
325
+ ignore: 'all' | _IIndex;
326
+ } | {
327
+ onIndex: _IIndex;
328
+ update: (item: any, excluded: any, t: _Transaction) => void;
329
+ };
330
+ export type DropHandler = (t: _Transaction, cascade: boolean) => void;
331
+ export type TruncateHandler = (t: _Transaction, opts: TruncateOpts) => void;
332
+ export type IndexHandler = (act: 'create' | 'drop', idx: _INamedIndex) => void;
333
+ export interface _RelationBase {
334
+ readonly name: string;
335
+ readonly reg: Reg;
336
+ readonly ownerSchema?: _ISchema;
337
+ }
338
+ export interface Reg {
339
+ readonly typeId: number;
340
+ readonly classId: number;
341
+ }
342
+ export interface ChangeOpts {
343
+ onConflict?: OnConflictHandler | nil;
344
+ overriding?: 'user' | 'system' | nil;
345
+ }
346
+ export interface _ITable extends IMemoryTable<any>, _RelationBase {
347
+ readonly type: 'table';
348
+ readonly hidden: boolean;
349
+ readonly db: _IDb;
350
+ readonly selection: _ISelection;
351
+ readonly ownerSchema: _ISchema;
352
+ doInsert(t: _Transaction, toInsert: Row, opts?: ChangeOpts): Row | nil | void;
353
+ setHidden(): this;
354
+ setReadonly(): this;
355
+ delete(t: _Transaction, toDelete: Row): void;
356
+ update(t: _Transaction, toUpdate: Row): Row | never;
357
+ createIndex(t: _Transaction, expressions: CreateIndexDef): _IConstraint | nil;
358
+ createIndex(t: _Transaction, expressions: Name[], type: 'primary' | 'unique', indexName?: string | nil): _IConstraint;
359
+ setReadonly(): this;
360
+ /** Create a column */
361
+ addColumn(column: SchemaField | CreateColumnDef, t: _Transaction): _Column;
362
+ /** Get a column to modify it */
363
+ getColumnRef(column: string): _Column;
364
+ getColumnRef(column: string, nullIfNotFound?: boolean): _Column | nil;
365
+ rename(to: string): this;
366
+ getConstraint(constraint: string): _IConstraint | nil;
367
+ addConstraint(constraint: TableConstraint, t: _Transaction): _IConstraint | nil;
368
+ getIndex(...forValues: IValue[]): _IIndex | nil;
369
+ dropIndex(t: _Transaction, name: string): void;
370
+ drop(t: _Transaction, cascade: boolean): void;
371
+ /** Will be executed when one of the given columns is affected (update/delete) */
372
+ onBeforeChange(columns: 'all' | (string | _Column)[], check: ChangeHandler): ISubscription;
373
+ /** Will be executed once all 'onBeforeChange' handlers have ran (coherency checks) */
374
+ onCheckChange(columns: 'all' | (string | _Column)[], check: ChangeHandler): ISubscription;
375
+ onDrop(sub: DropHandler): ISubscription;
376
+ onIndex(sub: IndexHandler): ISubscription;
377
+ onTruncate(sub: TruncateHandler): ISubscription;
378
+ truncate(t: _Transaction, truncateOpts?: TruncateOpts): void;
379
+ }
380
+ export interface TruncateOpts {
381
+ restartIdentity?: boolean;
382
+ cascade?: boolean;
383
+ }
384
+ export interface _IView extends _RelationBase {
385
+ readonly type: 'view';
386
+ readonly db: _IDb;
387
+ readonly selection: _ISelection;
388
+ drop(t: _Transaction): void;
389
+ }
390
+ export interface _IConstraint {
391
+ readonly name: string | nil;
392
+ uninstall(t: _Transaction): void;
393
+ }
394
+ export type ChangeHandler = (old: Row | null, neu: Row | null, t: _Transaction, opts: ChangeOpts) => void;
395
+ export interface _Column {
396
+ readonly comment?: string | nil;
397
+ readonly notNull: boolean;
398
+ readonly default: IValue | nil;
399
+ readonly expression: IValue;
400
+ readonly usedInIndexes: ReadonlySet<_IIndex>;
401
+ readonly table: _ITable;
402
+ readonly name: string;
403
+ alter(alter: AlterColumn, t: _Transaction): this;
404
+ rename(to: string, t: _Transaction): this;
405
+ drop(t: _Transaction): void;
406
+ onDrop(sub: DropHandler): ISubscription;
407
+ }
408
+ export interface CreateIndexDef {
409
+ ifNotExists?: boolean;
410
+ columns: CreateIndexColDef[];
411
+ indexName?: string;
412
+ unique?: boolean;
413
+ notNull?: boolean;
414
+ primary?: boolean;
415
+ predicate?: IValue;
416
+ }
417
+ export interface CreateIndexColDef {
418
+ value: IValue;
419
+ nullsLast?: boolean;
420
+ desc?: boolean;
421
+ }
422
+ export interface _IType<TRaw = any> extends IType, _RelationBase {
423
+ readonly type: 'type';
424
+ /** Data type */
425
+ readonly primary: DataType;
426
+ readonly primaryName: string;
427
+ /** Reg type name */
428
+ readonly name: string;
429
+ readonly reg: Reg;
430
+ toString(): string;
431
+ equals(a: TRaw, b: TRaw): boolean | null;
432
+ gt(a: TRaw, b: TRaw): boolean | null;
433
+ ge(a: TRaw, b: TRaw): boolean | null;
434
+ lt(a: TRaw, b: TRaw): boolean | null;
435
+ le(a: TRaw, b: TRaw): boolean | null;
436
+ canConvertImplicit(to: _IType<TRaw>): boolean | nil;
437
+ canCast(to: _IType<TRaw>): boolean | nil;
438
+ cast<T = any>(value: IValue<TRaw>, to: _IType<T>): IValue;
439
+ convertImplicit<T = any>(value: IValue<TRaw>, to: _IType<T>): IValue;
440
+ prefer(type: _IType<any>, stricterType?: boolean): _IType | nil;
441
+ /** Build an array type for this type */
442
+ asArray(): _IType<TRaw[]>;
443
+ asList(): _IType<TRaw[]>;
444
+ /** Get an unicity hash */
445
+ hash(value: TRaw): string | number | null;
446
+ drop(t: _Transaction): void;
447
+ }
448
+ export interface Parameter {
449
+ readonly index: number;
450
+ readonly value: IValue | nil;
451
+ inferedType?: _IType | nil;
452
+ }
453
+ export interface IValue<TRaw = any> {
454
+ /** Columns used in this expression (if any) */
455
+ readonly usedColumns: ReadonlySet<IValue>;
456
+ readonly type: _IType<TRaw>;
457
+ /** is 'any()' call ? */
458
+ readonly isAny: boolean;
459
+ /** Is a constant... i.e. not dependent on columns. ex: (2+2) or NOW() */
460
+ readonly isConstant: boolean;
461
+ /** Is REAL constant (i.e. 2+2, not varying expressions like NOW()) */
462
+ readonly isConstantReal: boolean;
463
+ /** Is a literal constant ? (constant not defined as an operation) */
464
+ readonly isConstantLiteral: boolean;
465
+ /** Will be set if there is an index on this value */
466
+ readonly index: _IIndex | nil;
467
+ /** Originates from this selection */
468
+ readonly origin: _ISelection | nil;
469
+ /** Column ID, or null */
470
+ readonly id: string | nil;
471
+ /** Hash of this value (used to identify indexed expressions) */
472
+ readonly hash: string;
473
+ /** Get value if is a constant */
474
+ get(): any;
475
+ /** Get value if is NOT a constant */
476
+ get(raw: TRaw, t?: _Transaction | nil): any;
477
+ setId(newId: string): IValue;
478
+ canCast(to: _IType): boolean;
479
+ cast<T = any>(to: _IType<T>): IValue;
480
+ convertImplicit<T = any>(to: _IType<T>): IValue;
481
+ /**
482
+ * Creates a copy of this column that can
483
+ **/
484
+ setWrapper<TNew>(newOrigin: _ISelection, unwrap: (val: TRaw) => TNew, newType: _IType<TNew>): IValue<TNew>;
485
+ setWrapper(newOrigin: _ISelection, unwrap: (val: TRaw) => TRaw): IValue<TRaw>;
486
+ map(unwrap: (val: TRaw) => TRaw): IValue<TRaw>;
487
+ map<TNew>(unwrap: (val: TRaw) => TNew, newType: _IType<TNew>): IValue<TNew>;
488
+ setOrigin(origin: _ISelection): IValue<TRaw>;
489
+ clone(): IValue;
490
+ explain(e: _Explainer): _ExprExplanation;
491
+ }
492
+ export type IndexKey = unknown[];
493
+ export interface IndexExpression {
494
+ readonly hash: string;
495
+ readonly type: _IType;
496
+ }
497
+ export interface _INamedIndex extends _IIndex, _RelationBase {
498
+ readonly type: 'index';
499
+ readonly onTable: _ITable;
500
+ drop(t: _Transaction): void;
501
+ }
502
+ export interface _IIndex {
503
+ readonly unique?: boolean;
504
+ readonly expressions: IndexExpression[];
505
+ /** Returns a measure of how many items will be returned by this op */
506
+ entropy(t: IndexOp): number;
507
+ /** Returns this selection stats, or null if it cannot be computed without iteration */
508
+ stats(t: _Transaction, key?: IndexKey): Stats | null;
509
+ /** Get values equating the given key */
510
+ eqFirst(rawKey: IndexKey, t: _Transaction): Row | null;
511
+ enumerate(op: IndexOp): Iterable<Row>;
512
+ explain(e: _Explainer): _IndexExplanation;
513
+ iterateKeys(t: _Transaction): Iterable<IndexKey> | null;
514
+ }
515
+ export type IndexOp = {
516
+ type: 'eq' | 'neq' | 'gt' | 'lt' | 'ge' | 'le';
517
+ key: IndexKey;
518
+ t: _Transaction;
519
+ matchNull?: boolean;
520
+ } | {
521
+ type: 'inside' | 'outside';
522
+ lo: IndexKey;
523
+ hi: IndexKey;
524
+ t: _Transaction;
525
+ } | {
526
+ type: 'nin';
527
+ keys: IndexKey[];
528
+ t: _Transaction;
529
+ };
530
+ export interface TableRecordDef {
531
+ readonly?: boolean;
532
+ hidden?: boolean;
533
+ name?: string;
534
+ dataId?: symbol;
535
+ serials: ImMap<string, number>;
536
+ it: number;
537
+ indexByHash: ImMap<string, _IIndex>;
538
+ indexByName: ImMap<string, _IIndex>;
539
+ columnsByName: ImMap<string, CR>;
540
+ }
541
+ export interface TableColumnRecordDef {
542
+ default: IValue;
543
+ notNull: boolean;
544
+ usedInIndexes: ImSet<_IIndex>;
545
+ type: _IType;
546
+ name: string;
547
+ }
548
+ export type TR = Record<TableRecordDef>;
549
+ export type CR = Record<TableColumnRecordDef>;
550
+ export declare const EmtpyTable: Record.Factory<TableRecordDef>;
551
+ export declare const NewColumn: Record.Factory<TableColumnRecordDef>;
552
+ export type _IRelation = _ITable | _ISequence | _INamedIndex | _IType | _IView;
553
+ export declare function asIndex(o: _IRelation): _INamedIndex;
554
+ export declare function asIndex(o: _IRelation | null): _INamedIndex | null;
555
+ export declare function asType(o: _IRelation): _IType;
556
+ export declare function asType(o: _IRelation | null): _IType | null;
557
+ export declare function asSeq(o: _IRelation): _ISequence;
558
+ export declare function asSeq(o: _IRelation | null): _ISequence | null;
559
+ export declare function asTable(o: _IRelation): _ITable;
560
+ export declare function asTable(o: _IRelation | null): _ITable | null;
561
+ export declare function asTable(o: _IRelation | null, nullIfNotType?: boolean): _ITable | null;
562
+ export type _ISelectable = _ITable | _IView;
563
+ export declare function asSelectable(o: _IRelation): _ISelectable;
564
+ export declare function asSelectable(o: _IRelation | null): _ISelectable | null;
565
+ export declare function asSelectable(o: _IRelation | null, nullIfNotType?: boolean): _ISelectable | null;
566
+ export declare function asView(o: _IRelation): _IView;
567
+ export declare function asView(o: _IRelation | null): _IView | null;
568
+ export declare function asView(o: _IRelation | null, nullIfNotType?: boolean): _IView | null;
569
+ export interface _ISequence extends _RelationBase {
570
+ readonly type: 'sequence';
571
+ alter(t: _Transaction, opts: CreateSequenceOptions | AlterSequenceChange): this;
572
+ nextValue(t: _Transaction): number;
573
+ restart(t: _Transaction): void;
574
+ setValue(t: _Transaction, value: number, increase?: boolean): void;
575
+ currentValue(t: _Transaction): number;
576
+ drop(t: _Transaction): void;
577
+ }
578
+ export interface AggregationComputer<TRet = any> {
579
+ readonly type: _IType;
580
+ /** Compute from index (ex: count(*) with a group-by) */
581
+ computeFromIndex?(key: IndexKey, index: _IIndex, t: _Transaction): TRet | undefined;
582
+ /** Compute out of nowhere when there is no group
583
+ * (ex: when there is no grouping, count(*) on a table or count(xxx) when there is an index on xxx) */
584
+ computeNoGroup?(t: _Transaction): TRet | undefined;
585
+ /** When iterating, each new group will have its computer */
586
+ createGroup(t: _Transaction): AggregationGroupComputer<TRet>;
587
+ }
588
+ export interface AggregationGroupComputer<TRet = any> {
589
+ /** When iterating, this will be called for each item in this group */
590
+ feedItem(item: any): void;
591
+ /** Finish computation (sets aggregation on result) */
592
+ finish(): TRet | nil;
593
+ }
594
+ export interface _IPreparedQuery extends IPreparedQuery {
595
+ bind(args?: any[]): _IBoundQuery;
596
+ executed?: () => void;
597
+ failed?: (e: any) => void;
598
+ }
599
+ export interface _IBoundQuery extends IBoundQuery {
600
+ executeAll(tx?: _Transaction): _QueryResult;
601
+ }
602
+ export interface _QueryResult extends QueryResult {
603
+ state?: _Transaction;
604
+ }
605
+ //# sourceMappingURL=interfaces-private.d.ts.map