@remix-run/data-table-postgres 0.4.0 → 0.5.1
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.
- package/README.md +40 -16
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/database.d.ts +35 -0
- package/dist/lib/database.d.ts.map +1 -0
- package/dist/lib/database.js +31 -0
- package/dist/lib/{adapter.d.ts → driver.d.ts} +40 -38
- package/dist/lib/driver.d.ts.map +1 -0
- package/dist/lib/driver.js +577 -0
- package/dist/lib/sql-compiler.d.ts +2 -1
- package/dist/lib/sql-compiler.d.ts.map +1 -1
- package/dist/lib/sql-compiler.js +6 -6
- package/package.json +12 -12
- package/src/index.ts +3 -1
- package/src/lib/database.ts +45 -0
- package/src/lib/driver.ts +760 -0
- package/src/lib/sql-compiler.ts +8 -7
- package/dist/lib/adapter.d.ts.map +0 -1
- package/dist/lib/adapter.js +0 -343
- package/src/lib/adapter.ts +0 -454
package/src/lib/sql-compiler.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getTableName, getTablePrimaryKey } from '@remix-run/data-table'
|
|
2
|
-
import type {
|
|
2
|
+
import type { Predicate, SqlStatement } from '@remix-run/data-table'
|
|
3
|
+
import type { DataManipulationOperation } from '@remix-run/data-table'
|
|
3
4
|
import {
|
|
4
5
|
collectColumns as collectColumnsHelper,
|
|
5
6
|
normalizeJoinType as normalizeJoinTypeHelper,
|
|
@@ -39,8 +40,8 @@ export function compilePostgresOperation(operation: DataManipulationOperation):
|
|
|
39
40
|
compileGroupByClause(operation.groupBy) +
|
|
40
41
|
compileHavingClause(operation.having, context) +
|
|
41
42
|
compileOrderByClause(operation.orderBy) +
|
|
42
|
-
compileLimitClause(operation.limit) +
|
|
43
|
-
compileOffsetClause(operation.offset)
|
|
43
|
+
compileLimitClause(operation.limit, context) +
|
|
44
|
+
compileOffsetClause(operation.offset, context)
|
|
44
45
|
|
|
45
46
|
return {
|
|
46
47
|
text,
|
|
@@ -555,20 +556,20 @@ function compileOrderByClause(orderBy: { column: string; direction: 'asc' | 'des
|
|
|
555
556
|
)
|
|
556
557
|
}
|
|
557
558
|
|
|
558
|
-
function compileLimitClause(limit: number | undefined): string {
|
|
559
|
+
function compileLimitClause(limit: number | undefined, context: CompileContext): string {
|
|
559
560
|
if (limit === undefined) {
|
|
560
561
|
return ''
|
|
561
562
|
}
|
|
562
563
|
|
|
563
|
-
return ' limit ' +
|
|
564
|
+
return ' limit ' + pushValue(context, limit)
|
|
564
565
|
}
|
|
565
566
|
|
|
566
|
-
function compileOffsetClause(offset: number | undefined): string {
|
|
567
|
+
function compileOffsetClause(offset: number | undefined, context: CompileContext): string {
|
|
567
568
|
if (offset === undefined) {
|
|
568
569
|
return ''
|
|
569
570
|
}
|
|
570
571
|
|
|
571
|
-
return ' offset ' +
|
|
572
|
+
return ' offset ' + pushValue(context, offset)
|
|
572
573
|
}
|
|
573
574
|
|
|
574
575
|
function compileReturningClause(returning: '*' | string[] | undefined): string {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/lib/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,sBAAsB,EACtB,yBAAyB,EACzB,eAAe,EACf,YAAY,EACZ,QAAQ,EACR,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,KAAK,EACV,MAAM,IAAI,cAAc,EACxB,IAAI,IAAI,YAAY,EACpB,UAAU,IAAI,kBAAkB,EACjC,MAAM,IAAI,CAAA;AASX,KAAK,iBAAiB,GAAG,cAAc,GAAG,YAAY,GAAG,kBAAkB,CAAA;AAE3E;;GAEG;AACH,qBAAa,uBAAwB,YAAW,eAAe;;IAC7D;;OAEG;IACH,OAAO,SAAa;IAEpB;;OAEG;IACH,YAAY;;;;;;MAAA;IAMZ,YAAY,MAAM,EAAE,iBAAiB,EASpC;IAED;;;;OAIG;IACH,UAAU,CAAC,SAAS,EAAE,yBAAyB,GAAG,YAAY,EAAE,CAG/D;IAED;;;;OAIG;IACG,OAAO,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAuB/E;IAED;;;;;;;;OAQG;IACG,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAG9E;IAED;;;;;OAKG;IACG,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,WAAW,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAMhF;IAED;;;;;;OAMG;IACG,SAAS,CACb,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,gBAAgB,GAC7B,OAAO,CAAC,OAAO,CAAC,CASlB;IAED;;;;OAIG;IACG,gBAAgB,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA0B9E;IAED;;;;OAIG;IACG,iBAAiB,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgB9D;IAED;;;;OAIG;IACG,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBhE;IAED;;;;;OAKG;IACG,eAAe,CAAC,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG1E;IAED;;;;;OAKG;IACG,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG9E;IAED;;;;;OAKG;IACG,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG3E;IAED;;;OAGG;IACG,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAE1C;IAED;;;OAGG;IACG,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAE1C;CAmBF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,iBAAiB,GAAG,uBAAuB,CAEhG"}
|
package/dist/lib/adapter.js
DELETED
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
import { getTablePrimaryKey } from '@remix-run/data-table';
|
|
2
|
-
import { compilePostgresOperation } from "./sql-compiler.js";
|
|
3
|
-
/**
|
|
4
|
-
* `DatabaseAdapter` implementation for postgres-compatible clients.
|
|
5
|
-
*/
|
|
6
|
-
export class PostgresDatabaseAdapter {
|
|
7
|
-
/**
|
|
8
|
-
* The SQL dialect identifier reported by this adapter.
|
|
9
|
-
*/
|
|
10
|
-
dialect = 'postgres';
|
|
11
|
-
/**
|
|
12
|
-
* Feature flags describing the postgres behaviors supported by this adapter.
|
|
13
|
-
*/
|
|
14
|
-
capabilities;
|
|
15
|
-
#client;
|
|
16
|
-
#transactions = new Map();
|
|
17
|
-
#transactionCounter = 0;
|
|
18
|
-
constructor(client) {
|
|
19
|
-
this.#client = client;
|
|
20
|
-
this.capabilities = {
|
|
21
|
-
returning: true,
|
|
22
|
-
savepoints: true,
|
|
23
|
-
upsert: true,
|
|
24
|
-
transactionalDdl: true,
|
|
25
|
-
migrationLock: true,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Compiles a data-manipulation operation to postgres SQL statements.
|
|
30
|
-
* @param operation Operation to compile.
|
|
31
|
-
* @returns Compiled SQL statements.
|
|
32
|
-
*/
|
|
33
|
-
compileSql(operation) {
|
|
34
|
-
let compiled = compilePostgresOperation(operation);
|
|
35
|
-
return [{ text: compiled.text, values: compiled.values }];
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Executes a postgres data-manipulation request.
|
|
39
|
-
* @param request Request to execute.
|
|
40
|
-
* @returns Execution result.
|
|
41
|
-
*/
|
|
42
|
-
async execute(request) {
|
|
43
|
-
if (request.operation.kind === 'insertMany' && request.operation.values.length === 0) {
|
|
44
|
-
return {
|
|
45
|
-
affectedRows: 0,
|
|
46
|
-
insertId: undefined,
|
|
47
|
-
rows: request.operation.returning ? [] : undefined,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
let statement = compilePostgresOperation(request.operation);
|
|
51
|
-
let client = this.#resolveClient(request.transaction);
|
|
52
|
-
let result = await client.query(statement.text, statement.values);
|
|
53
|
-
let rows = normalizeRows(result.rows);
|
|
54
|
-
if (request.operation.kind === 'count' || request.operation.kind === 'exists') {
|
|
55
|
-
rows = normalizeCountRows(rows);
|
|
56
|
-
}
|
|
57
|
-
return {
|
|
58
|
-
rows,
|
|
59
|
-
affectedRows: normalizeAffectedRows(request.operation.kind, result.rowCount, rows),
|
|
60
|
-
insertId: normalizeInsertId(request.operation.kind, request.operation, rows),
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Executes a multi-statement postgres SQL script.
|
|
65
|
-
*
|
|
66
|
-
* Postgres natively supports multi-statement scripts when `query` is called
|
|
67
|
-
* without a parameter array.
|
|
68
|
-
* @param sql SQL script to execute.
|
|
69
|
-
* @param transaction Optional transaction token.
|
|
70
|
-
* @returns A promise that resolves once execution completes.
|
|
71
|
-
*/
|
|
72
|
-
async executeScript(sql, transaction) {
|
|
73
|
-
let client = this.#resolveClient(transaction);
|
|
74
|
-
await client.query(sql);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Checks whether a table exists in postgres.
|
|
78
|
-
* @param table Table reference to inspect.
|
|
79
|
-
* @param transaction Optional transaction token.
|
|
80
|
-
* @returns `true` when the table exists.
|
|
81
|
-
*/
|
|
82
|
-
async hasTable(table, transaction) {
|
|
83
|
-
let relation = toPostgresRelationName(table);
|
|
84
|
-
let client = this.#resolveClient(transaction);
|
|
85
|
-
let result = await client.query('select to_regclass($1) is not null as "exists"', [relation]);
|
|
86
|
-
let row = result.rows[0];
|
|
87
|
-
return toBooleanExists(row?.exists);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Checks whether a column exists in postgres.
|
|
91
|
-
* @param table Table reference to inspect.
|
|
92
|
-
* @param column Column name to look up.
|
|
93
|
-
* @param transaction Optional transaction token.
|
|
94
|
-
* @returns `true` when the column exists.
|
|
95
|
-
*/
|
|
96
|
-
async hasColumn(table, column, transaction) {
|
|
97
|
-
let relation = toPostgresRelationName(table);
|
|
98
|
-
let client = this.#resolveClient(transaction);
|
|
99
|
-
let result = await client.query('select exists (select 1 from pg_attribute where attrelid = to_regclass($1) and attname = $2 and attnum > 0 and not attisdropped) as "exists"', [relation, column]);
|
|
100
|
-
let row = result.rows[0];
|
|
101
|
-
return toBooleanExists(row?.exists);
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Starts a postgres transaction.
|
|
105
|
-
* @param options Transaction options.
|
|
106
|
-
* @returns Transaction token.
|
|
107
|
-
*/
|
|
108
|
-
async beginTransaction(options) {
|
|
109
|
-
let releaseOnClose = false;
|
|
110
|
-
let transactionClient;
|
|
111
|
-
if (isPostgresPool(this.#client)) {
|
|
112
|
-
transactionClient = await this.#client.connect();
|
|
113
|
-
releaseOnClose = true;
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
transactionClient = this.#client;
|
|
117
|
-
}
|
|
118
|
-
await transactionClient.query('begin');
|
|
119
|
-
if (options?.isolationLevel || options?.readOnly !== undefined) {
|
|
120
|
-
await transactionClient.query(buildSetTransactionStatement(options));
|
|
121
|
-
}
|
|
122
|
-
this.#transactionCounter += 1;
|
|
123
|
-
let token = { id: 'tx_' + String(this.#transactionCounter) };
|
|
124
|
-
this.#transactions.set(token.id, {
|
|
125
|
-
client: transactionClient,
|
|
126
|
-
releaseOnClose,
|
|
127
|
-
});
|
|
128
|
-
return token;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Commits an open postgres transaction.
|
|
132
|
-
* @param token Transaction token to commit.
|
|
133
|
-
* @returns A promise that resolves when the transaction is committed.
|
|
134
|
-
*/
|
|
135
|
-
async commitTransaction(token) {
|
|
136
|
-
let transaction = this.#transactions.get(token.id);
|
|
137
|
-
if (!transaction) {
|
|
138
|
-
throw new Error('Unknown transaction token: ' + token.id);
|
|
139
|
-
}
|
|
140
|
-
try {
|
|
141
|
-
await transaction.client.query('commit');
|
|
142
|
-
}
|
|
143
|
-
finally {
|
|
144
|
-
this.#transactions.delete(token.id);
|
|
145
|
-
if (transaction.releaseOnClose) {
|
|
146
|
-
releasePostgresClient(transaction.client);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Rolls back an open postgres transaction.
|
|
152
|
-
* @param token Transaction token to roll back.
|
|
153
|
-
* @returns A promise that resolves when the transaction is rolled back.
|
|
154
|
-
*/
|
|
155
|
-
async rollbackTransaction(token) {
|
|
156
|
-
let transaction = this.#transactions.get(token.id);
|
|
157
|
-
if (!transaction) {
|
|
158
|
-
throw new Error('Unknown transaction token: ' + token.id);
|
|
159
|
-
}
|
|
160
|
-
try {
|
|
161
|
-
await transaction.client.query('rollback');
|
|
162
|
-
}
|
|
163
|
-
finally {
|
|
164
|
-
this.#transactions.delete(token.id);
|
|
165
|
-
if (transaction.releaseOnClose) {
|
|
166
|
-
releasePostgresClient(transaction.client);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Creates a savepoint in an open postgres transaction.
|
|
172
|
-
* @param token Transaction token to use.
|
|
173
|
-
* @param name Savepoint name.
|
|
174
|
-
* @returns A promise that resolves when the savepoint is created.
|
|
175
|
-
*/
|
|
176
|
-
async createSavepoint(token, name) {
|
|
177
|
-
let client = this.#transactionClient(token);
|
|
178
|
-
await client.query('savepoint ' + quoteIdentifier(name));
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Rolls back to a savepoint in an open postgres transaction.
|
|
182
|
-
* @param token Transaction token to use.
|
|
183
|
-
* @param name Savepoint name.
|
|
184
|
-
* @returns A promise that resolves when the rollback completes.
|
|
185
|
-
*/
|
|
186
|
-
async rollbackToSavepoint(token, name) {
|
|
187
|
-
let client = this.#transactionClient(token);
|
|
188
|
-
await client.query('rollback to savepoint ' + quoteIdentifier(name));
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Releases a savepoint in an open postgres transaction.
|
|
192
|
-
* @param token Transaction token to use.
|
|
193
|
-
* @param name Savepoint name.
|
|
194
|
-
* @returns A promise that resolves when the savepoint is released.
|
|
195
|
-
*/
|
|
196
|
-
async releaseSavepoint(token, name) {
|
|
197
|
-
let client = this.#transactionClient(token);
|
|
198
|
-
await client.query('release savepoint ' + quoteIdentifier(name));
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Acquires the postgres migration lock.
|
|
202
|
-
* @returns A promise that resolves when the lock is acquired.
|
|
203
|
-
*/
|
|
204
|
-
async acquireMigrationLock() {
|
|
205
|
-
await this.#client.query('select pg_advisory_lock(hashtext($1))', ['data_table_migrations']);
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Releases the postgres migration lock.
|
|
209
|
-
* @returns A promise that resolves when the lock is released.
|
|
210
|
-
*/
|
|
211
|
-
async releaseMigrationLock() {
|
|
212
|
-
await this.#client.query('select pg_advisory_unlock(hashtext($1))', ['data_table_migrations']);
|
|
213
|
-
}
|
|
214
|
-
#resolveClient(token) {
|
|
215
|
-
if (!token) {
|
|
216
|
-
return this.#client;
|
|
217
|
-
}
|
|
218
|
-
return this.#transactionClient(token);
|
|
219
|
-
}
|
|
220
|
-
#transactionClient(token) {
|
|
221
|
-
let transaction = this.#transactions.get(token.id);
|
|
222
|
-
if (!transaction) {
|
|
223
|
-
throw new Error('Unknown transaction token: ' + token.id);
|
|
224
|
-
}
|
|
225
|
-
return transaction.client;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Creates a postgres `DatabaseAdapter`.
|
|
230
|
-
* @param client `pg` pool or pool client.
|
|
231
|
-
* @param options Optional adapter capability overrides.
|
|
232
|
-
* @returns A configured postgres adapter.
|
|
233
|
-
* @example
|
|
234
|
-
* ```ts
|
|
235
|
-
* import { Pool } from 'pg'
|
|
236
|
-
* import { createDatabase } from 'remix/data-table'
|
|
237
|
-
* import { createPostgresDatabaseAdapter } from 'remix/data-table/postgres'
|
|
238
|
-
*
|
|
239
|
-
* let pool = new Pool({ connectionString: process.env.DATABASE_URL })
|
|
240
|
-
* let adapter = createPostgresDatabaseAdapter(pool)
|
|
241
|
-
* let db = createDatabase(adapter)
|
|
242
|
-
* ```
|
|
243
|
-
*/
|
|
244
|
-
export function createPostgresDatabaseAdapter(client) {
|
|
245
|
-
return new PostgresDatabaseAdapter(client);
|
|
246
|
-
}
|
|
247
|
-
function isPostgresPool(client) {
|
|
248
|
-
return 'connect' in client && typeof client.connect === 'function';
|
|
249
|
-
}
|
|
250
|
-
function releasePostgresClient(client) {
|
|
251
|
-
let release = client.release;
|
|
252
|
-
release?.();
|
|
253
|
-
}
|
|
254
|
-
function buildSetTransactionStatement(options) {
|
|
255
|
-
let parts = ['set transaction'];
|
|
256
|
-
if (options.isolationLevel) {
|
|
257
|
-
parts.push('isolation level ' + options.isolationLevel);
|
|
258
|
-
}
|
|
259
|
-
if (options.readOnly !== undefined) {
|
|
260
|
-
parts.push(options.readOnly ? 'read only' : 'read write');
|
|
261
|
-
}
|
|
262
|
-
return parts.join(' ');
|
|
263
|
-
}
|
|
264
|
-
function normalizeRows(rows) {
|
|
265
|
-
return rows.map((row) => {
|
|
266
|
-
if (typeof row !== 'object' || row === null) {
|
|
267
|
-
return {};
|
|
268
|
-
}
|
|
269
|
-
return { ...row };
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
function normalizeCountRows(rows) {
|
|
273
|
-
return rows.map((row) => {
|
|
274
|
-
let count = row.count;
|
|
275
|
-
if (typeof count === 'string') {
|
|
276
|
-
let numeric = Number(count);
|
|
277
|
-
if (!Number.isNaN(numeric)) {
|
|
278
|
-
return {
|
|
279
|
-
...row,
|
|
280
|
-
count: numeric,
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
if (typeof count === 'bigint') {
|
|
285
|
-
return {
|
|
286
|
-
...row,
|
|
287
|
-
count: Number(count),
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
return row;
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
function normalizeAffectedRows(kind, rowCount, rows) {
|
|
294
|
-
if (kind === 'select' || kind === 'count' || kind === 'exists') {
|
|
295
|
-
return undefined;
|
|
296
|
-
}
|
|
297
|
-
if (rowCount !== null) {
|
|
298
|
-
return rowCount;
|
|
299
|
-
}
|
|
300
|
-
if (kind === 'raw') {
|
|
301
|
-
return undefined;
|
|
302
|
-
}
|
|
303
|
-
return rows.length;
|
|
304
|
-
}
|
|
305
|
-
function normalizeInsertId(kind, operation, rows) {
|
|
306
|
-
if (!isInsertOperationKind(kind) || !isInsertOperation(operation)) {
|
|
307
|
-
return undefined;
|
|
308
|
-
}
|
|
309
|
-
let primaryKey = getTablePrimaryKey(operation.table);
|
|
310
|
-
if (primaryKey.length !== 1) {
|
|
311
|
-
return undefined;
|
|
312
|
-
}
|
|
313
|
-
let key = primaryKey[0];
|
|
314
|
-
let row = rows[rows.length - 1];
|
|
315
|
-
return row ? row[key] : undefined;
|
|
316
|
-
}
|
|
317
|
-
function quoteIdentifier(value) {
|
|
318
|
-
return '"' + value.replace(/"/g, '""') + '"';
|
|
319
|
-
}
|
|
320
|
-
function toPostgresRelationName(table) {
|
|
321
|
-
if (table.schema) {
|
|
322
|
-
return quoteIdentifier(table.schema) + '.' + quoteIdentifier(table.name);
|
|
323
|
-
}
|
|
324
|
-
return quoteIdentifier(table.name);
|
|
325
|
-
}
|
|
326
|
-
function toBooleanExists(value) {
|
|
327
|
-
if (typeof value === 'boolean') {
|
|
328
|
-
return value;
|
|
329
|
-
}
|
|
330
|
-
if (typeof value === 'number') {
|
|
331
|
-
return value > 0;
|
|
332
|
-
}
|
|
333
|
-
if (typeof value === 'string') {
|
|
334
|
-
return value === 't' || value === 'true' || value === '1';
|
|
335
|
-
}
|
|
336
|
-
return false;
|
|
337
|
-
}
|
|
338
|
-
function isInsertOperationKind(kind) {
|
|
339
|
-
return kind === 'insert' || kind === 'insertMany' || kind === 'upsert';
|
|
340
|
-
}
|
|
341
|
-
function isInsertOperation(operation) {
|
|
342
|
-
return (operation.kind === 'insert' || operation.kind === 'insertMany' || operation.kind === 'upsert');
|
|
343
|
-
}
|