taon-type-sql 21.0.25 → 21.0.27
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/browser/README.md +24 -24
- package/browser/fesm2022/taon-type-sql-browser.mjs.map +1 -1
- package/browser/package.json +1 -1
- package/browser-prod/README.md +24 -24
- package/browser-prod/fesm2022/taon-type-sql-browser.mjs.map +1 -1
- package/browser-prod/package.json +1 -1
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/builder/helpers/generics-helper.js.map +1 -1
- package/lib/builder/helpers/internal-types.js.map +1 -1
- package/lib/converter/param-converter.js.map +1 -1
- package/lib/converter/type-converter.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/package.json +1 -1
- package/lib-prod/package.json +1 -1
- package/package.json +1 -1
- package/websql/README.md +24 -24
- package/websql/fesm2022/taon-type-sql-websql.mjs.map +1 -1
- package/websql/package.json +1 -1
- package/websql-prod/README.md +24 -24
- package/websql-prod/fesm2022/taon-type-sql-websql.mjs.map +1 -1
- package/websql-prod/package.json +1 -1
- package/lib-prod/build-info._auto-generated_.js +0 -26
- package/lib-prod/builder/column/basic-column.js +0 -11
- package/lib-prod/builder/column/boolean-column.js +0 -11
- package/lib-prod/builder/column/comparable-column.js +0 -39
- package/lib-prod/builder/column/date-column.js +0 -11
- package/lib-prod/builder/column/number-column.js +0 -16
- package/lib-prod/builder/column/query-column.js +0 -18
- package/lib-prod/builder/column/string-column.js +0 -33
- package/lib-prod/builder/column/value-column.js +0 -27
- package/lib-prod/builder/condition/query-column-condition.js +0 -16
- package/lib-prod/builder/condition/query-condition-chain.js +0 -26
- package/lib-prod/builder/condition/query-condition.js +0 -4
- package/lib-prod/builder/condition/query-join-condition.js +0 -16
- package/lib-prod/builder/helpers/generics-helper.js +0 -3
- package/lib-prod/builder/helpers/internal-types.js +0 -1
- package/lib-prod/builder/join/joined-tables-chain.js +0 -11
- package/lib-prod/builder/join/joined-tables.js +0 -19
- package/lib-prod/builder/other/query-ordering.js +0 -14
- package/lib-prod/builder/query/select-query.js +0 -45
- package/lib-prod/builder/query/table-condition-query.js +0 -22
- package/lib-prod/builder/query/table-query.js +0 -52
- package/lib-prod/builder/query-source.js +0 -17
- package/lib-prod/builder/query-table.js +0 -22
- package/lib-prod/client/mysql.js +0 -7
- package/lib-prod/client/pg.js +0 -7
- package/lib-prod/client/query-processor.js +0 -69
- package/lib-prod/converter/param-converter.js +0 -26
- package/lib-prod/converter/parameterized-converter.js +0 -14
- package/lib-prod/converter/query-converter.js +0 -280
- package/lib-prod/converter/result-converter.js +0 -85
- package/lib-prod/converter/sql-converter.js +0 -5
- package/lib-prod/converter/type-converter.js +0 -36
- package/lib-prod/converter/types.js +0 -1
- package/lib-prod/env/env.angular-node-app.js +0 -66
- package/lib-prod/env/env.docs-webapp.js +0 -66
- package/lib-prod/env/env.electron-app.js +0 -66
- package/lib-prod/env/env.mobile-app.js +0 -66
- package/lib-prod/env/env.npm-lib-and-cli-tool.js +0 -66
- package/lib-prod/env/env.vscode-plugin.js +0 -66
- package/lib-prod/env/index.js +0 -6
- package/lib-prod/index._auto-generated_.js +0 -5
- package/lib-prod/index.js +0 -25
- package/lib-prod/migrations/index.js +0 -2
- package/lib-prod/migrations/migrations_index._auto-generated_.js +0 -3
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import QueryColumnCondition from "../condition/query-column-condition";
|
|
2
|
-
import QueryOrdering from "../other/query-ordering";
|
|
3
|
-
import QueryColumn from "./query-column";
|
|
4
|
-
import QueryJoinCondition from "../condition/query-join-condition";
|
|
5
|
-
class ValueColumn extends QueryColumn {
|
|
6
|
-
constructor(table, name, modifiers = []) {
|
|
7
|
-
super(table, name, modifiers);
|
|
8
|
-
}
|
|
9
|
-
asc() {
|
|
10
|
-
return new QueryOrdering(this, 'ASC');
|
|
11
|
-
}
|
|
12
|
-
desc() {
|
|
13
|
-
return new QueryOrdering(this, 'DESC');
|
|
14
|
-
}
|
|
15
|
-
eq(value) {
|
|
16
|
-
if (value instanceof QueryColumn) {
|
|
17
|
-
return new QueryJoinCondition(this, 'eq', value);
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
return new QueryColumnCondition(this, 'eq', value);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
ne(value) {
|
|
24
|
-
return new QueryColumnCondition(this, 'ne', value);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export default ValueColumn;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import QueryCondition from "./query-condition";
|
|
2
|
-
import QueryConditionChain from "./query-condition-chain";
|
|
3
|
-
export default class QueryColumnCondition extends QueryCondition {
|
|
4
|
-
constructor(column, type, ...values) {
|
|
5
|
-
super();
|
|
6
|
-
this._column = column;
|
|
7
|
-
this._type = type;
|
|
8
|
-
this._values = values;
|
|
9
|
-
}
|
|
10
|
-
and(condition) {
|
|
11
|
-
return new QueryConditionChain(this, condition, 'and');
|
|
12
|
-
}
|
|
13
|
-
or(condition) {
|
|
14
|
-
return new QueryConditionChain(this, condition, 'or');
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import QueryCondition from "./query-condition";
|
|
2
|
-
export default class QueryConditionChain extends QueryCondition {
|
|
3
|
-
constructor(sibling, child, chainType) {
|
|
4
|
-
super();
|
|
5
|
-
this._parenthesis = false;
|
|
6
|
-
this._negation = false;
|
|
7
|
-
this._sibling = sibling;
|
|
8
|
-
this._child = child;
|
|
9
|
-
this._chainType = chainType;
|
|
10
|
-
}
|
|
11
|
-
// TODO how to call this
|
|
12
|
-
$() {
|
|
13
|
-
this._parenthesis = true;
|
|
14
|
-
return this;
|
|
15
|
-
}
|
|
16
|
-
not() {
|
|
17
|
-
this._negation = true;
|
|
18
|
-
return this;
|
|
19
|
-
}
|
|
20
|
-
and(condition) {
|
|
21
|
-
return new QueryConditionChain(this, condition, 'and');
|
|
22
|
-
}
|
|
23
|
-
or(condition) {
|
|
24
|
-
return new QueryConditionChain(this, condition, 'or');
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import QueryCondition from "./query-condition";
|
|
2
|
-
import QueryConditionChain from "./query-condition-chain";
|
|
3
|
-
export default class QueryJoinCondition extends QueryCondition {
|
|
4
|
-
constructor(column, type, otherColumn) {
|
|
5
|
-
super();
|
|
6
|
-
this._column = column;
|
|
7
|
-
this._type = type;
|
|
8
|
-
this._otherColumn = otherColumn;
|
|
9
|
-
}
|
|
10
|
-
and(condition) {
|
|
11
|
-
return new QueryConditionChain(this, condition, 'and');
|
|
12
|
-
}
|
|
13
|
-
or(condition) {
|
|
14
|
-
return new QueryConditionChain(this, condition, 'or');
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import JoinedTables from "./joined-tables";
|
|
2
|
-
export default class JoinedTablesChain {
|
|
3
|
-
constructor(_table, _modifier, _parent) {
|
|
4
|
-
this._table = _table;
|
|
5
|
-
this._modifier = _modifier;
|
|
6
|
-
this._parent = _parent;
|
|
7
|
-
}
|
|
8
|
-
on(condition) {
|
|
9
|
-
return new JoinedTables(condition, this);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import JoinedTablesChain from "./joined-tables-chain";
|
|
2
|
-
export default class JoinedTables {
|
|
3
|
-
constructor(_condition, _parent) {
|
|
4
|
-
this._condition = _condition;
|
|
5
|
-
this._parent = _parent;
|
|
6
|
-
}
|
|
7
|
-
innerJoin(table) {
|
|
8
|
-
return new JoinedTablesChain(table, 'inner', this);
|
|
9
|
-
}
|
|
10
|
-
leftJoin(table) {
|
|
11
|
-
return new JoinedTablesChain(table, 'left', this);
|
|
12
|
-
}
|
|
13
|
-
rightJoin(table) {
|
|
14
|
-
return new JoinedTablesChain(table, 'right', this);
|
|
15
|
-
}
|
|
16
|
-
fullJoin(table) {
|
|
17
|
-
return new JoinedTablesChain(table, 'full', this);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export default class QueryOrdering {
|
|
2
|
-
constructor(column, direction) {
|
|
3
|
-
this._column = column;
|
|
4
|
-
this._direction = direction;
|
|
5
|
-
}
|
|
6
|
-
nullsFirst() {
|
|
7
|
-
this._nullsPosition = 'FIRST';
|
|
8
|
-
return this;
|
|
9
|
-
}
|
|
10
|
-
nullsLast() {
|
|
11
|
-
this._nullsPosition = 'LAST';
|
|
12
|
-
return this;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export default class SelectQuery {
|
|
2
|
-
constructor(_queryProcessor, _tables) {
|
|
3
|
-
this._queryProcessor = _queryProcessor;
|
|
4
|
-
this._tables = _tables;
|
|
5
|
-
this._distinct = false;
|
|
6
|
-
this._conditions = [];
|
|
7
|
-
this._groupBy = [];
|
|
8
|
-
this._having = [];
|
|
9
|
-
this._orderings = [];
|
|
10
|
-
this._columns = [];
|
|
11
|
-
}
|
|
12
|
-
offset(offset) {
|
|
13
|
-
this._offset = offset;
|
|
14
|
-
return this;
|
|
15
|
-
}
|
|
16
|
-
limit(limit) {
|
|
17
|
-
this._limit = limit;
|
|
18
|
-
return this;
|
|
19
|
-
}
|
|
20
|
-
distinct() {
|
|
21
|
-
this._distinct = true;
|
|
22
|
-
return this;
|
|
23
|
-
}
|
|
24
|
-
where(...conditions) {
|
|
25
|
-
this._conditions = conditions;
|
|
26
|
-
return this;
|
|
27
|
-
}
|
|
28
|
-
groupBy(...columns) {
|
|
29
|
-
this._groupBy = columns;
|
|
30
|
-
return this;
|
|
31
|
-
}
|
|
32
|
-
having(...conditions) {
|
|
33
|
-
this._having = conditions;
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
orderBy(...orderings) {
|
|
37
|
-
this._orderings = orderings;
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
|
-
select(...columns) {
|
|
41
|
-
this._columns = columns;
|
|
42
|
-
this._action = 'select';
|
|
43
|
-
return this._queryProcessor(this);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export default class TableConditionQuery {
|
|
2
|
-
constructor(_queryProcessor, _table, _conditions) {
|
|
3
|
-
this._queryProcessor = _queryProcessor;
|
|
4
|
-
this._table = _table;
|
|
5
|
-
this._conditions = _conditions;
|
|
6
|
-
this._columns = [];
|
|
7
|
-
}
|
|
8
|
-
update(entity) {
|
|
9
|
-
this._entity = entity;
|
|
10
|
-
this._action = 'update';
|
|
11
|
-
return this._queryProcessor(this);
|
|
12
|
-
}
|
|
13
|
-
delete() {
|
|
14
|
-
this._action = 'delete';
|
|
15
|
-
return this._queryProcessor(this);
|
|
16
|
-
}
|
|
17
|
-
count() {
|
|
18
|
-
this._columns = [this._table.$all.count()];
|
|
19
|
-
this._action = 'select';
|
|
20
|
-
return this._queryProcessor(this).then((rows) => rows[0]);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import TableConditionQuery from "./table-condition-query";
|
|
2
|
-
import ValueColumn from "../column/value-column";
|
|
3
|
-
export default class TableQuery {
|
|
4
|
-
constructor(_queryProcessor, _table) {
|
|
5
|
-
this._queryProcessor = _queryProcessor;
|
|
6
|
-
this._table = _table;
|
|
7
|
-
this._columns = [];
|
|
8
|
-
}
|
|
9
|
-
where(...conditions) {
|
|
10
|
-
return new TableConditionQuery(this._queryProcessor, this._table, conditions);
|
|
11
|
-
}
|
|
12
|
-
insert(param) {
|
|
13
|
-
this._entity = param;
|
|
14
|
-
this._action = 'insert';
|
|
15
|
-
return this._queryProcessor(this);
|
|
16
|
-
}
|
|
17
|
-
deleteAll() {
|
|
18
|
-
this._action = 'delete';
|
|
19
|
-
return this._queryProcessor(this);
|
|
20
|
-
}
|
|
21
|
-
updateAll(entity) {
|
|
22
|
-
this._entity = entity;
|
|
23
|
-
this._action = 'update';
|
|
24
|
-
return this._queryProcessor(this);
|
|
25
|
-
}
|
|
26
|
-
countAll() {
|
|
27
|
-
this._columns = [this._table.$all.count()];
|
|
28
|
-
this._action = 'select';
|
|
29
|
-
return this._queryProcessor(this).then((rows) => rows[0]);
|
|
30
|
-
}
|
|
31
|
-
delete(id) {
|
|
32
|
-
return this._whereId(id).delete().then(count => count > 0);
|
|
33
|
-
}
|
|
34
|
-
update(id, entity) {
|
|
35
|
-
return this._whereId(id).update(entity).then(count => count > 0);
|
|
36
|
-
}
|
|
37
|
-
get(id) {
|
|
38
|
-
let query = this._whereId(id);
|
|
39
|
-
return this._queryProcessor({ _action: 'select', ...query })
|
|
40
|
-
.then((rows) => rows[0]);
|
|
41
|
-
}
|
|
42
|
-
_whereId(id) {
|
|
43
|
-
// TODO remove assertions if $id typing is fixed
|
|
44
|
-
let $id = this._table.$id;
|
|
45
|
-
if ($id instanceof ValueColumn) {
|
|
46
|
-
return this.where($id.eq(id));
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
return this.where(...Object.keys($id).map(key => this._table[key].eq(id[key])));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import SelectQuery from './query/select-query';
|
|
2
|
-
import TableQuery from "./query/table-query";
|
|
3
|
-
export default class QuerySource {
|
|
4
|
-
constructor(_queryProcessor) {
|
|
5
|
-
this._queryProcessor = _queryProcessor;
|
|
6
|
-
}
|
|
7
|
-
from(table1, table2, table3) {
|
|
8
|
-
if (table3 != null)
|
|
9
|
-
return new SelectQuery(this._queryProcessor, [table1, table2, table3]);
|
|
10
|
-
else if (table2 != null)
|
|
11
|
-
return new SelectQuery(this._queryProcessor, [table1, table2]);
|
|
12
|
-
return new SelectQuery(this._queryProcessor, [table1]);
|
|
13
|
-
}
|
|
14
|
-
table(table) {
|
|
15
|
-
return new TableQuery(this._queryProcessor, table);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import BasicColumn from "./column/basic-column";
|
|
2
|
-
import JoinedTablesChain from "./join/joined-tables-chain";
|
|
3
|
-
class QueryTable {
|
|
4
|
-
constructor(_$name) {
|
|
5
|
-
this._$name = _$name;
|
|
6
|
-
// abstract readonly $id; // FIXME I got a dozen incomprehensible type errors
|
|
7
|
-
this.$all = new BasicColumn(this, '*');
|
|
8
|
-
}
|
|
9
|
-
innerJoin(table) {
|
|
10
|
-
return new JoinedTablesChain(table, 'inner', this);
|
|
11
|
-
}
|
|
12
|
-
leftJoin(table) {
|
|
13
|
-
return new JoinedTablesChain(table, 'left', this);
|
|
14
|
-
}
|
|
15
|
-
rightJoin(table) {
|
|
16
|
-
return new JoinedTablesChain(table, 'right', this);
|
|
17
|
-
}
|
|
18
|
-
fullJoin(table) {
|
|
19
|
-
return new JoinedTablesChain(table, 'full', this);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
export default QueryTable;
|
package/lib-prod/client/mysql.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import QuerySource from "../builder/query-source";
|
|
2
|
-
import { createQueryProcessor } from "./query-processor";
|
|
3
|
-
export default class MySqlQuerySource extends QuerySource {
|
|
4
|
-
constructor(client, options = {}) {
|
|
5
|
-
super(createQueryProcessor(client, options, 'mysql'));
|
|
6
|
-
}
|
|
7
|
-
}
|
package/lib-prod/client/pg.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import QuerySource from "../builder/query-source";
|
|
2
|
-
import { createQueryProcessor } from "./query-processor";
|
|
3
|
-
export default class PgQuerySource extends QuerySource {
|
|
4
|
-
constructor(client, options = {}) {
|
|
5
|
-
super(createQueryProcessor(client, options, 'pg'));
|
|
6
|
-
}
|
|
7
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { Log } from 'ng2-logger/lib-prod';
|
|
2
|
-
import { convertQueryToParameterizedSQL } from '../converter/parameterized-converter';
|
|
3
|
-
import { convertQueryToSQL } from '../converter/sql-converter';
|
|
4
|
-
const log = Log.create('query processor');
|
|
5
|
-
const DEFAULT_OPTIONS = {
|
|
6
|
-
lineBreaks: false,
|
|
7
|
-
parameterized: true,
|
|
8
|
-
logging: true,
|
|
9
|
-
identifierQuote: '"'
|
|
10
|
-
};
|
|
11
|
-
function mySqlTypeCast(field, next) {
|
|
12
|
-
if (field.type == 'TINY' && field.length == 1) { // Boolean
|
|
13
|
-
let value = field.string();
|
|
14
|
-
if (value == '1')
|
|
15
|
-
return true;
|
|
16
|
-
if (value == '0')
|
|
17
|
-
return false;
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
else if (field.type == 'JSON') {
|
|
21
|
-
let value = field.string();
|
|
22
|
-
return value == null ? null : JSON.parse(value);
|
|
23
|
-
}
|
|
24
|
-
return next();
|
|
25
|
-
}
|
|
26
|
-
export function createQueryProcessor(client, _options = {}, engine = 'pg') {
|
|
27
|
-
let options = Object.assign({}, DEFAULT_OPTIONS, _options);
|
|
28
|
-
let queryOptions = {
|
|
29
|
-
lineBreak: options.lineBreaks ? '\n' : ' ',
|
|
30
|
-
nameEscape: _options.identifierQuote || (engine === 'mysql' ? '`' : '"')
|
|
31
|
-
};
|
|
32
|
-
// function processSql(query: any, sql: string, params: any[] | undefined, callback: any): Promise<any> {
|
|
33
|
-
// if (options.logging) log.i(sql);
|
|
34
|
-
// if (options.logger) options.logger(sql, params);
|
|
35
|
-
// return new Promise((resolve, reject) => {
|
|
36
|
-
// callback(sql, params, (err: any, result: any) => {
|
|
37
|
-
// if (err) reject(err);
|
|
38
|
-
// else resolve(convertResult(query, result, engine));
|
|
39
|
-
// });
|
|
40
|
-
// });
|
|
41
|
-
// }
|
|
42
|
-
// function executeSql(sql: string, params: any[] | undefined, cb: any) {
|
|
43
|
-
// if (engine === 'pg') {
|
|
44
|
-
// client.query(sql, params || cb, params ? cb : undefined);
|
|
45
|
-
// } else if (engine === 'mysql') {
|
|
46
|
-
// client.query({
|
|
47
|
-
// sql,
|
|
48
|
-
// values: params,
|
|
49
|
-
// typeCast: mySqlTypeCast
|
|
50
|
-
// }, cb);
|
|
51
|
-
// } else throw new Error('Unknown DB engine: ' + engine);
|
|
52
|
-
// }
|
|
53
|
-
return (query) => {
|
|
54
|
-
if (options.parameterized) {
|
|
55
|
-
let { sql, params } = convertQueryToParameterizedSQL(query, queryOptions, engine);
|
|
56
|
-
// if (Helpers.isWebSQL || Helpers.isNode) {
|
|
57
|
-
return client.query(sql, params);
|
|
58
|
-
// }
|
|
59
|
-
// return processSql(query, sql, params, (sql: string, params: any[], cb: any) => executeSql(sql, params, cb));
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
let sql = convertQueryToSQL(query, queryOptions, engine);
|
|
63
|
-
// if (Helpers.isWebSQL || Helpers.isNode) {
|
|
64
|
-
return client.query(sql, undefined);
|
|
65
|
-
// }
|
|
66
|
-
// return processSql(query, sql, undefined, (sql: string, params: undefined, cb: any) => executeSql(sql, undefined, cb));
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export function convertSubstitutionParam(param) {
|
|
2
|
-
if (param == null)
|
|
3
|
-
return 'NULL';
|
|
4
|
-
if (typeof param === 'string' || param instanceof String) {
|
|
5
|
-
return `'${String(param)}'`;
|
|
6
|
-
}
|
|
7
|
-
else if (typeof param === 'boolean' || param instanceof Boolean) {
|
|
8
|
-
return String(param).toUpperCase();
|
|
9
|
-
}
|
|
10
|
-
else if (param instanceof Date) {
|
|
11
|
-
return `'${param.toISOString()}'`;
|
|
12
|
-
}
|
|
13
|
-
else if (typeof param === 'number' || param instanceof Number) {
|
|
14
|
-
return String(param);
|
|
15
|
-
}
|
|
16
|
-
return `'${JSON.stringify(param)}'`;
|
|
17
|
-
}
|
|
18
|
-
// node mysql doesn't have an typeCast equivalent solution for the other direction
|
|
19
|
-
// node-postgres: https://github.com/brianc/node-postgres/issues/442
|
|
20
|
-
export function convertEscapedParam(param) {
|
|
21
|
-
if (typeof param === 'object' && !(param == null || param instanceof String || param instanceof Number ||
|
|
22
|
-
param instanceof Boolean || param instanceof Date)) {
|
|
23
|
-
return JSON.stringify(param);
|
|
24
|
-
}
|
|
25
|
-
return param;
|
|
26
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { createQueryConverter } from "./query-converter";
|
|
2
|
-
import { convertEscapedParam } from './param-converter';
|
|
3
|
-
let pgParamConverter = (index) => '$' + index;
|
|
4
|
-
let mySqlParamConverter = (index) => '?';
|
|
5
|
-
function convertSingleParam(param, params, paramConverter) {
|
|
6
|
-
params.push(convertEscapedParam(param));
|
|
7
|
-
return paramConverter(params.length);
|
|
8
|
-
}
|
|
9
|
-
export function convertQueryToParameterizedSQL(query, options, engine) {
|
|
10
|
-
let params = [];
|
|
11
|
-
let paramConverter = engine === 'mysql' ? mySqlParamConverter : pgParamConverter;
|
|
12
|
-
let sql = createQueryConverter((param) => convertSingleParam(param, params, paramConverter), options, engine)(query);
|
|
13
|
-
return { sql, params };
|
|
14
|
-
}
|