@saltcorn/sqlite 0.6.1-beta.2 → 0.6.2-beta.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/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/{index.js → dist/index.js} +14 -14
- package/dist/index.js.map +1 -0
- package/dist/sqlite.d.ts +158 -0
- package/dist/sqlite.d.ts.map +1 -0
- package/dist/sqlite.js +320 -0
- package/dist/sqlite.js.map +1 -0
- package/dist/tsconfig.ref.tsbuildinfo +1 -0
- package/package.json +24 -4
- package/sqlite.js +0 -310
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AACA;;;GAGG;AAEH;;;;;;GAMG"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* @
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* All files in the sqlite package.
|
|
9
|
-
* @namespace sqlite_overview
|
|
10
|
-
* @property {module:sqlite} sqlite
|
|
11
|
-
*
|
|
12
|
-
* @category sqlite
|
|
13
|
-
*/
|
|
14
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// for the jsdoc documentation
|
|
3
|
+
/**
|
|
4
|
+
* @category sqlite
|
|
5
|
+
* @module sqlite/index
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* All files in the sqlite package.
|
|
9
|
+
* @namespace sqlite_overview
|
|
10
|
+
* @property {module:sqlite} sqlite
|
|
11
|
+
*
|
|
12
|
+
* @category sqlite
|
|
13
|
+
*/
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";AAAA,8BAA8B;AAC9B;;;GAGG;AAEH;;;;;;GAMG"}
|
package/dist/sqlite.d.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite3 data access layer
|
|
3
|
+
* @category sqlite
|
|
4
|
+
* @module sqlite
|
|
5
|
+
*/
|
|
6
|
+
import { Database } from "sqlite3";
|
|
7
|
+
/**
|
|
8
|
+
* Initializes internals of the the sqlite module.
|
|
9
|
+
* It must be called after importing the module.
|
|
10
|
+
* @function
|
|
11
|
+
* @param {any} getConnectObject
|
|
12
|
+
*/
|
|
13
|
+
export declare const init: (getConnectObject: () => Database) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Get sqlite path
|
|
16
|
+
* @function
|
|
17
|
+
* @returns {string|void}
|
|
18
|
+
*/
|
|
19
|
+
export declare const get_db_filepath: () => string;
|
|
20
|
+
/**
|
|
21
|
+
* Control Logging sql statements to console
|
|
22
|
+
* @param {boolean} [val = true] - if true then log sql statements to console
|
|
23
|
+
*/
|
|
24
|
+
export declare function set_sql_logging(val?: boolean): void;
|
|
25
|
+
/**
|
|
26
|
+
* Get sql logging state
|
|
27
|
+
* @returns {boolean} if true then sql logging eabled
|
|
28
|
+
*/
|
|
29
|
+
export declare function get_sql_logging(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Log SQL statement to console
|
|
32
|
+
* @param {string} sql - SQL statement
|
|
33
|
+
* @param {any} [vs] - any additional parameter
|
|
34
|
+
*/
|
|
35
|
+
export declare function sql_log(sql: string, vs?: any): void;
|
|
36
|
+
/**
|
|
37
|
+
* @param {string} sql
|
|
38
|
+
* @param {any} params
|
|
39
|
+
* @returns {Promise<object>}
|
|
40
|
+
*/
|
|
41
|
+
export declare function query(sql: string, params?: any): Promise<any>;
|
|
42
|
+
/**
|
|
43
|
+
* Change connection (close connection and open new connection from connObj)
|
|
44
|
+
* @param {any} connObj - connection object
|
|
45
|
+
* @returns {Promise<void>}
|
|
46
|
+
* @function
|
|
47
|
+
*/
|
|
48
|
+
export declare const changeConnection: (connObj: any) => Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Close database connection
|
|
51
|
+
* @returns {Promise<void>}
|
|
52
|
+
* @function
|
|
53
|
+
*/
|
|
54
|
+
export declare const close: () => Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Execute Select statement
|
|
57
|
+
* @param {string} tbl - table name
|
|
58
|
+
* @param {any} whereObj - where object
|
|
59
|
+
* @param {any} [selectopts = {}] - select options
|
|
60
|
+
* @returns {Promise<*>} return rows
|
|
61
|
+
* @function
|
|
62
|
+
*/
|
|
63
|
+
export declare const select: (tbl: string, whereObj: any, selectopts?: any) => Promise<any>;
|
|
64
|
+
/**
|
|
65
|
+
* @param {any} v
|
|
66
|
+
* @returns {boolean}
|
|
67
|
+
* @function
|
|
68
|
+
*/
|
|
69
|
+
export declare const reprAsJson: (v: any) => boolean;
|
|
70
|
+
/**
|
|
71
|
+
* @param {object[]} opts
|
|
72
|
+
* @param {*} opts.k
|
|
73
|
+
* @param {any} opts.v
|
|
74
|
+
* @returns {string|any}
|
|
75
|
+
* @function
|
|
76
|
+
*/
|
|
77
|
+
export declare const mkVal: ([k, v]: [any, any]) => string;
|
|
78
|
+
/**
|
|
79
|
+
* Drop unique constraint
|
|
80
|
+
* @param {string} tbl - table name
|
|
81
|
+
* @param {any} obj - list of column=value pairs
|
|
82
|
+
* @param {string} id - primary key column value
|
|
83
|
+
* @returns {Promise<void>} no results
|
|
84
|
+
* @function
|
|
85
|
+
*/
|
|
86
|
+
export declare const update: (tbl: string, obj: any, id: string) => Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Delete rows in table
|
|
89
|
+
* @param {string} tbl - table name
|
|
90
|
+
* @param {any} whereObj - where object
|
|
91
|
+
* @returns {Promise<void>} result of delete execution
|
|
92
|
+
* @function
|
|
93
|
+
*/
|
|
94
|
+
export declare const deleteWhere: (tbl: string, whereObj: any) => Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Insert rows into table
|
|
97
|
+
* @param {string} tbl - table name
|
|
98
|
+
* @param {any} obj - columns names and data
|
|
99
|
+
* @param {any} [opts = {}] - columns attributes
|
|
100
|
+
* @returns {Promise<string|void>} returns id.
|
|
101
|
+
* @function
|
|
102
|
+
*/
|
|
103
|
+
export declare const insert: (tbl: string, obj: any, opts?: any) => Promise<string | void>;
|
|
104
|
+
/**
|
|
105
|
+
* Select one record
|
|
106
|
+
* @param {string} tbl - table name
|
|
107
|
+
* @param {any} where - where object
|
|
108
|
+
* @throws {Error}
|
|
109
|
+
* @returns {Promise<any>} return first record from sql result
|
|
110
|
+
* @function
|
|
111
|
+
*/
|
|
112
|
+
export declare const selectOne: (tbl: string, where: any) => Promise<any>;
|
|
113
|
+
/**
|
|
114
|
+
* Select one record or null if no records
|
|
115
|
+
* @param {string} tbl - table name
|
|
116
|
+
* @param {any} where - where object
|
|
117
|
+
* @returns {Promise<any>} - null if no record or first record data
|
|
118
|
+
* @function
|
|
119
|
+
*/
|
|
120
|
+
export declare const selectMaybeOne: (tbl: string, where: any) => Promise<any>;
|
|
121
|
+
/**
|
|
122
|
+
* Get count of rows in table
|
|
123
|
+
* @param {string} tbl - table name
|
|
124
|
+
* @param {any} whereObj - where object
|
|
125
|
+
* @returns {Promise<number>} count of tables
|
|
126
|
+
* @function
|
|
127
|
+
*/
|
|
128
|
+
export declare const count: (tbl: string, whereObj: any) => Promise<number>;
|
|
129
|
+
/**
|
|
130
|
+
* Get version of PostgreSQL
|
|
131
|
+
* @returns {Promise<string>} returns version
|
|
132
|
+
* @function
|
|
133
|
+
*/
|
|
134
|
+
export declare const getVersion: () => Promise<string>;
|
|
135
|
+
/**
|
|
136
|
+
* Reset DB Schema using drop schema and recreate it.
|
|
137
|
+
* Attention! You will lost data after call this function!
|
|
138
|
+
* @returns {Promise<void>} no result
|
|
139
|
+
* @function
|
|
140
|
+
*/
|
|
141
|
+
export declare const drop_reset_schema: () => Promise<void>;
|
|
142
|
+
/**
|
|
143
|
+
* Add unique constraint
|
|
144
|
+
* @param {string} table_name - table name
|
|
145
|
+
* @param {string[]} field_names - list of columns (members of constraint)
|
|
146
|
+
* @returns {Promise<void>} no result
|
|
147
|
+
* @function
|
|
148
|
+
*/
|
|
149
|
+
export declare const add_unique_constraint: (table_name: string, field_names: string[]) => Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* Drop unique constraint
|
|
152
|
+
* @param {string} table_name - table name
|
|
153
|
+
* @param {string[]} field_names - list of columns (members of constraint)
|
|
154
|
+
* @returns {Promise<void>} no results
|
|
155
|
+
* @function
|
|
156
|
+
*/
|
|
157
|
+
export declare const drop_unique_constraint: (table_name: string, field_names: string[]) => Promise<void>;
|
|
158
|
+
//# sourceMappingURL=sqlite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../sqlite.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAW,MAAM,SAAS,CAAC;AAW5C;;;;;GAKG;AACH,eAAO,MAAM,IAAI,qBAAsB,MAAM,QAAQ,KAAG,IAMvD,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,QAAO,MAGlC,CAAC;AAIF;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,GAAC,OAAc,GAAG,IAAI,CAExD;AAED;;;GAGG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAEzC;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAC,MAAM,EAAE,EAAE,CAAC,EAAC,GAAG,QAI1C;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAC,MAAM,EAAE,MAAM,CAAC,EAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAe3D;AAED;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,YAAkB,GAAG,KAAG,QAAQ,IAAI,CAOhE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,KAAK,QAAa,QAAQ,IA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,KAClF,QAAQ,IAAI,CAMb,CAAC"}
|
package/dist/sqlite.js
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SQLite3 data access layer
|
|
4
|
+
* @category sqlite
|
|
5
|
+
* @module sqlite
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.drop_unique_constraint = exports.add_unique_constraint = exports.drop_reset_schema = exports.getVersion = exports.count = exports.selectMaybeOne = exports.selectOne = exports.insert = exports.deleteWhere = exports.update = exports.mkVal = exports.reprAsJson = exports.select = exports.close = exports.changeConnection = exports.query = exports.sql_log = exports.get_sql_logging = exports.set_sql_logging = exports.get_db_filepath = exports.init = void 0;
|
|
9
|
+
const sqlite3_1 = require("sqlite3");
|
|
10
|
+
(0, sqlite3_1.verbose)();
|
|
11
|
+
const promises_1 = require("fs/promises");
|
|
12
|
+
const { sqlsanitize, mkWhere, mkSelectOptions } = require("@saltcorn/db-common/internal");
|
|
13
|
+
let sqliteDatabase = null;
|
|
14
|
+
let connectObj = null;
|
|
15
|
+
let current_filepath;
|
|
16
|
+
/**
|
|
17
|
+
* Initializes internals of the the sqlite module.
|
|
18
|
+
* It must be called after importing the module.
|
|
19
|
+
* @function
|
|
20
|
+
* @param {any} getConnectObject
|
|
21
|
+
*/
|
|
22
|
+
const init = (getConnectObject) => {
|
|
23
|
+
if (!sqliteDatabase) {
|
|
24
|
+
connectObj = getConnectObject();
|
|
25
|
+
current_filepath = (0, exports.get_db_filepath)();
|
|
26
|
+
sqliteDatabase = new sqlite3_1.Database(current_filepath);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.init = init;
|
|
30
|
+
/**
|
|
31
|
+
* Get sqlite path
|
|
32
|
+
* @function
|
|
33
|
+
* @returns {string|void}
|
|
34
|
+
*/
|
|
35
|
+
const get_db_filepath = () => {
|
|
36
|
+
if (connectObj.sqlite_path)
|
|
37
|
+
return connectObj.sqlite_path;
|
|
38
|
+
return "";
|
|
39
|
+
};
|
|
40
|
+
exports.get_db_filepath = get_db_filepath;
|
|
41
|
+
let log_sql_enabled = false;
|
|
42
|
+
/**
|
|
43
|
+
* Control Logging sql statements to console
|
|
44
|
+
* @param {boolean} [val = true] - if true then log sql statements to console
|
|
45
|
+
*/
|
|
46
|
+
function set_sql_logging(val = true) {
|
|
47
|
+
log_sql_enabled = val;
|
|
48
|
+
}
|
|
49
|
+
exports.set_sql_logging = set_sql_logging;
|
|
50
|
+
/**
|
|
51
|
+
* Get sql logging state
|
|
52
|
+
* @returns {boolean} if true then sql logging eabled
|
|
53
|
+
*/
|
|
54
|
+
function get_sql_logging() {
|
|
55
|
+
return log_sql_enabled;
|
|
56
|
+
}
|
|
57
|
+
exports.get_sql_logging = get_sql_logging;
|
|
58
|
+
/**
|
|
59
|
+
* Log SQL statement to console
|
|
60
|
+
* @param {string} sql - SQL statement
|
|
61
|
+
* @param {any} [vs] - any additional parameter
|
|
62
|
+
*/
|
|
63
|
+
function sql_log(sql, vs) {
|
|
64
|
+
if (log_sql_enabled)
|
|
65
|
+
if (typeof vs === "undefined")
|
|
66
|
+
console.log(sql);
|
|
67
|
+
else
|
|
68
|
+
console.log(sql, vs);
|
|
69
|
+
}
|
|
70
|
+
exports.sql_log = sql_log;
|
|
71
|
+
/**
|
|
72
|
+
* @param {string} sql
|
|
73
|
+
* @param {any} params
|
|
74
|
+
* @returns {Promise<object>}
|
|
75
|
+
*/
|
|
76
|
+
function query(sql, params) {
|
|
77
|
+
sql_log(sql, params);
|
|
78
|
+
return new Promise((resolve, reject) => {
|
|
79
|
+
if (!sqliteDatabase) {
|
|
80
|
+
reject(new Error("The database connection is closed."));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
sqliteDatabase.all(sql, params, function (err, rows) {
|
|
84
|
+
if (err) {
|
|
85
|
+
reject(err);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
resolve({ rows });
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
exports.query = query;
|
|
94
|
+
/**
|
|
95
|
+
* Change connection (close connection and open new connection from connObj)
|
|
96
|
+
* @param {any} connObj - connection object
|
|
97
|
+
* @returns {Promise<void>}
|
|
98
|
+
* @function
|
|
99
|
+
*/
|
|
100
|
+
const changeConnection = async (connObj) => {
|
|
101
|
+
if (!sqliteDatabase) {
|
|
102
|
+
throw new Error("The database connection is closed.");
|
|
103
|
+
}
|
|
104
|
+
await sqliteDatabase.close();
|
|
105
|
+
current_filepath = connObj.sqlite_path;
|
|
106
|
+
sqliteDatabase = new sqlite3_1.Database(current_filepath);
|
|
107
|
+
};
|
|
108
|
+
exports.changeConnection = changeConnection;
|
|
109
|
+
/**
|
|
110
|
+
* Close database connection
|
|
111
|
+
* @returns {Promise<void>}
|
|
112
|
+
* @function
|
|
113
|
+
*/
|
|
114
|
+
const close = async () => {
|
|
115
|
+
if (!sqliteDatabase) {
|
|
116
|
+
throw new Error("The database connection is closed.");
|
|
117
|
+
}
|
|
118
|
+
await sqliteDatabase.close();
|
|
119
|
+
sqliteDatabase = null;
|
|
120
|
+
};
|
|
121
|
+
exports.close = close;
|
|
122
|
+
/**
|
|
123
|
+
* Execute Select statement
|
|
124
|
+
* @param {string} tbl - table name
|
|
125
|
+
* @param {any} whereObj - where object
|
|
126
|
+
* @param {any} [selectopts = {}] - select options
|
|
127
|
+
* @returns {Promise<*>} return rows
|
|
128
|
+
* @function
|
|
129
|
+
*/
|
|
130
|
+
const select = async (tbl, whereObj, selectopts = {}) => {
|
|
131
|
+
const { where, values } = mkWhere(whereObj, true);
|
|
132
|
+
const sql = `SELECT * FROM "${sqlsanitize(tbl)}" ${where} ${mkSelectOptions(selectopts)}`;
|
|
133
|
+
const tq = await query(sql, values);
|
|
134
|
+
return tq.rows;
|
|
135
|
+
};
|
|
136
|
+
exports.select = select;
|
|
137
|
+
// TODO Utility function - needs ti be moved out this module
|
|
138
|
+
/**
|
|
139
|
+
* @param {any} v
|
|
140
|
+
* @returns {boolean}
|
|
141
|
+
* @function
|
|
142
|
+
*/
|
|
143
|
+
const reprAsJson = (v) => typeof v === "object" && v !== null && !(v instanceof Date);
|
|
144
|
+
exports.reprAsJson = reprAsJson;
|
|
145
|
+
/**
|
|
146
|
+
* @param {object[]} opts
|
|
147
|
+
* @param {*} opts.k
|
|
148
|
+
* @param {any} opts.v
|
|
149
|
+
* @returns {string|any}
|
|
150
|
+
* @function
|
|
151
|
+
*/
|
|
152
|
+
const mkVal = ([k, v]) => ((0, exports.reprAsJson)(v) ? JSON.stringify(v) : v);
|
|
153
|
+
exports.mkVal = mkVal;
|
|
154
|
+
/**
|
|
155
|
+
* Drop unique constraint
|
|
156
|
+
* @param {string} tbl - table name
|
|
157
|
+
* @param {any} obj - list of column=value pairs
|
|
158
|
+
* @param {string} id - primary key column value
|
|
159
|
+
* @returns {Promise<void>} no results
|
|
160
|
+
* @function
|
|
161
|
+
*/
|
|
162
|
+
const update = async (tbl, obj, id) => {
|
|
163
|
+
const kvs = Object.entries(obj);
|
|
164
|
+
const assigns = kvs.map(([k, v], ix) => `"${sqlsanitize(k)}"=?`).join();
|
|
165
|
+
let valList = kvs.map(exports.mkVal);
|
|
166
|
+
valList.push(id);
|
|
167
|
+
const q = `update "${sqlsanitize(tbl)}" set ${assigns} where id=?`;
|
|
168
|
+
await query(q, valList);
|
|
169
|
+
};
|
|
170
|
+
exports.update = update;
|
|
171
|
+
/**
|
|
172
|
+
* Delete rows in table
|
|
173
|
+
* @param {string} tbl - table name
|
|
174
|
+
* @param {any} whereObj - where object
|
|
175
|
+
* @returns {Promise<void>} result of delete execution
|
|
176
|
+
* @function
|
|
177
|
+
*/
|
|
178
|
+
const deleteWhere = async (tbl, whereObj) => {
|
|
179
|
+
const { where, values } = mkWhere(whereObj, true);
|
|
180
|
+
const sql = `delete FROM "${sqlsanitize(tbl)}" ${where}`;
|
|
181
|
+
const tq = await query(sql, values);
|
|
182
|
+
};
|
|
183
|
+
exports.deleteWhere = deleteWhere;
|
|
184
|
+
/**
|
|
185
|
+
* Insert rows into table
|
|
186
|
+
* @param {string} tbl - table name
|
|
187
|
+
* @param {any} obj - columns names and data
|
|
188
|
+
* @param {any} [opts = {}] - columns attributes
|
|
189
|
+
* @returns {Promise<string|void>} returns id.
|
|
190
|
+
* @function
|
|
191
|
+
*/
|
|
192
|
+
const insert = async (tbl, obj, opts = {}) => {
|
|
193
|
+
const kvs = Object.entries(obj);
|
|
194
|
+
const fnameList = kvs.map(([k, v]) => `"${sqlsanitize(k)}"`).join();
|
|
195
|
+
const valPosList = kvs
|
|
196
|
+
.map(([k, v], ix) => v && v.next_version_by_id
|
|
197
|
+
? `coalesce((select max(_version) from "${sqlsanitize(tbl)}" where id=${+v.next_version_by_id}), 0)+1`
|
|
198
|
+
: (0, exports.reprAsJson)(v)
|
|
199
|
+
? "json(?)"
|
|
200
|
+
: "?")
|
|
201
|
+
.join();
|
|
202
|
+
const valList = kvs
|
|
203
|
+
.filter(([k, v]) => !(v && v.next_version_by_id))
|
|
204
|
+
.map(exports.mkVal);
|
|
205
|
+
const sql = `insert into "${sqlsanitize(tbl)}"(${fnameList}) values(${valPosList})`;
|
|
206
|
+
await query(sql, valList);
|
|
207
|
+
if (opts.noid)
|
|
208
|
+
return;
|
|
209
|
+
// TBD Support of primary key column different from id
|
|
210
|
+
const ids = await query("SELECT last_insert_rowid() as id");
|
|
211
|
+
return ids.rows[0].id;
|
|
212
|
+
};
|
|
213
|
+
exports.insert = insert;
|
|
214
|
+
/**
|
|
215
|
+
* Select one record
|
|
216
|
+
* @param {string} tbl - table name
|
|
217
|
+
* @param {any} where - where object
|
|
218
|
+
* @throws {Error}
|
|
219
|
+
* @returns {Promise<any>} return first record from sql result
|
|
220
|
+
* @function
|
|
221
|
+
*/
|
|
222
|
+
const selectOne = async (tbl, where) => {
|
|
223
|
+
const rows = await (0, exports.select)(tbl, where);
|
|
224
|
+
if (rows.length === 0) {
|
|
225
|
+
const w = mkWhere(where, true);
|
|
226
|
+
throw new Error(`no ${tbl} ${w.where} are ${w.values}`);
|
|
227
|
+
}
|
|
228
|
+
else
|
|
229
|
+
return rows[0];
|
|
230
|
+
};
|
|
231
|
+
exports.selectOne = selectOne;
|
|
232
|
+
/**
|
|
233
|
+
* Select one record or null if no records
|
|
234
|
+
* @param {string} tbl - table name
|
|
235
|
+
* @param {any} where - where object
|
|
236
|
+
* @returns {Promise<any>} - null if no record or first record data
|
|
237
|
+
* @function
|
|
238
|
+
*/
|
|
239
|
+
const selectMaybeOne = async (tbl, where) => {
|
|
240
|
+
const rows = await (0, exports.select)(tbl, where);
|
|
241
|
+
if (rows.length === 0)
|
|
242
|
+
return null;
|
|
243
|
+
else
|
|
244
|
+
return rows[0];
|
|
245
|
+
};
|
|
246
|
+
exports.selectMaybeOne = selectMaybeOne;
|
|
247
|
+
/**
|
|
248
|
+
* Get count of rows in table
|
|
249
|
+
* @param {string} tbl - table name
|
|
250
|
+
* @param {any} whereObj - where object
|
|
251
|
+
* @returns {Promise<number>} count of tables
|
|
252
|
+
* @function
|
|
253
|
+
*/
|
|
254
|
+
const count = async (tbl, whereObj) => {
|
|
255
|
+
const { where, values } = mkWhere(whereObj, true);
|
|
256
|
+
const sql = `SELECT COUNT(*) FROM "${sqlsanitize(tbl)}" ${where}`;
|
|
257
|
+
const tq = await query(sql, values);
|
|
258
|
+
return parseInt(tq.rows[0]["COUNT(*)"]);
|
|
259
|
+
};
|
|
260
|
+
exports.count = count;
|
|
261
|
+
/**
|
|
262
|
+
* Get version of PostgreSQL
|
|
263
|
+
* @returns {Promise<string>} returns version
|
|
264
|
+
* @function
|
|
265
|
+
*/
|
|
266
|
+
const getVersion = async () => {
|
|
267
|
+
const sql = `SELECT sqlite_version();`;
|
|
268
|
+
sql_log(sql);
|
|
269
|
+
const tq = await query(sql);
|
|
270
|
+
return tq.rows[0]["sqlite_version()"];
|
|
271
|
+
};
|
|
272
|
+
exports.getVersion = getVersion;
|
|
273
|
+
/**
|
|
274
|
+
* Reset DB Schema using drop schema and recreate it.
|
|
275
|
+
* Attention! You will lost data after call this function!
|
|
276
|
+
* @returns {Promise<void>} no result
|
|
277
|
+
* @function
|
|
278
|
+
*/
|
|
279
|
+
const drop_reset_schema = async () => {
|
|
280
|
+
if (!sqliteDatabase) {
|
|
281
|
+
throw new Error("The database connection is closed.");
|
|
282
|
+
}
|
|
283
|
+
await sqliteDatabase.close();
|
|
284
|
+
await (0, promises_1.unlink)(current_filepath);
|
|
285
|
+
sqliteDatabase = new sqlite3_1.Database(current_filepath);
|
|
286
|
+
};
|
|
287
|
+
exports.drop_reset_schema = drop_reset_schema;
|
|
288
|
+
/**
|
|
289
|
+
* Add unique constraint
|
|
290
|
+
* @param {string} table_name - table name
|
|
291
|
+
* @param {string[]} field_names - list of columns (members of constraint)
|
|
292
|
+
* @returns {Promise<void>} no result
|
|
293
|
+
* @function
|
|
294
|
+
*/
|
|
295
|
+
const add_unique_constraint = async (table_name, field_names) => {
|
|
296
|
+
const sql = `create unique index ${sqlsanitize(table_name)}_${field_names
|
|
297
|
+
.map((f) => sqlsanitize(f))
|
|
298
|
+
.join("_")}_unique on "${sqlsanitize(table_name)}"(${field_names
|
|
299
|
+
.map((f) => `"${sqlsanitize(f)}"`)
|
|
300
|
+
.join(",")});`;
|
|
301
|
+
sql_log(sql);
|
|
302
|
+
await query(sql);
|
|
303
|
+
};
|
|
304
|
+
exports.add_unique_constraint = add_unique_constraint;
|
|
305
|
+
/**
|
|
306
|
+
* Drop unique constraint
|
|
307
|
+
* @param {string} table_name - table name
|
|
308
|
+
* @param {string[]} field_names - list of columns (members of constraint)
|
|
309
|
+
* @returns {Promise<void>} no results
|
|
310
|
+
* @function
|
|
311
|
+
*/
|
|
312
|
+
const drop_unique_constraint = async (table_name, field_names) => {
|
|
313
|
+
const sql = `drop index ${sqlsanitize(table_name)}_${field_names
|
|
314
|
+
.map((f) => sqlsanitize(f))
|
|
315
|
+
.join("_")}_unique;`;
|
|
316
|
+
sql_log(sql);
|
|
317
|
+
await query(sql);
|
|
318
|
+
};
|
|
319
|
+
exports.drop_unique_constraint = drop_unique_constraint;
|
|
320
|
+
//# sourceMappingURL=sqlite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite.js","sourceRoot":"","sources":["../sqlite.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,qCAA4C;AAC5C,IAAA,iBAAO,GAAE,CAAC;AACV,0CAAoC;AAEpC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;AAG1F,IAAI,cAAc,GAAiB,IAAI,CAAC;AACxC,IAAI,UAAU,GAAO,IAAI,CAAC;AAC1B,IAAI,gBAAuB,CAAC;AAE5B;;;;;GAKG;AACI,MAAM,IAAI,GAAG,CAAC,gBAAgC,EAAQ,EAAE;IAC7D,IAAI,CAAC,cAAc,EAAE;QACnB,UAAU,GAAG,gBAAgB,EAAE,CAAC;QAChC,gBAAgB,GAAG,IAAA,uBAAe,GAAE,CAAC;QACrC,cAAc,GAAG,IAAI,kBAAQ,CAAC,gBAAgB,CAAC,CAAC;KACjD;AACH,CAAC,CAAA;AANY,QAAA,IAAI,QAMhB;AAED;;;;GAIG;AACI,MAAM,eAAe,GAAG,GAAW,EAAE;IAC1C,IAAI,UAAU,CAAC,WAAW;QAAE,OAAO,UAAU,CAAC,WAAW,CAAC;IAC1D,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAHW,QAAA,eAAe,mBAG1B;AAEF,IAAI,eAAe,GAAG,KAAK,CAAC;AAE5B;;;GAGG;AACH,SAAgB,eAAe,CAAC,MAAc,IAAI;IAChD,eAAe,GAAG,GAAG,CAAC;AACxB,CAAC;AAFD,0CAEC;AAED;;;GAGG;AACH,SAAgB,eAAe;IAC7B,OAAO,eAAe,CAAC;AACzB,CAAC;AAFD,0CAEC;AAED;;;;GAIG;AAC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IACb,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;AACnB,CAAC,CAAC;AAPW,QAAA,sBAAsB,0BAOjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"program":{"fileNames":["../../../node_modules/typescript/lib/lib.es5.d.ts","../../../node_modules/typescript/lib/lib.es2015.d.ts","../../../node_modules/typescript/lib/lib.es2016.d.ts","../../../node_modules/typescript/lib/lib.es2017.d.ts","../../../node_modules/typescript/lib/lib.es2018.d.ts","../../../node_modules/typescript/lib/lib.es2019.d.ts","../../../node_modules/typescript/lib/lib.es2020.d.ts","../../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../node_modules/typescript/lib/lib.es2020.string.d.ts","../../../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../node_modules/typescript/lib/lib.esnext.intl.d.ts","../index.ts","../node_modules/@types/node/assert.d.ts","../node_modules/@types/node/assert/strict.d.ts","../node_modules/@types/node/globals.d.ts","../node_modules/@types/node/async_hooks.d.ts","../node_modules/@types/node/buffer.d.ts","../node_modules/@types/node/child_process.d.ts","../node_modules/@types/node/cluster.d.ts","../node_modules/@types/node/console.d.ts","../node_modules/@types/node/constants.d.ts","../node_modules/@types/node/crypto.d.ts","../node_modules/@types/node/dgram.d.ts","../node_modules/@types/node/diagnostics_channel.d.ts","../node_modules/@types/node/dns.d.ts","../node_modules/@types/node/dns/promises.d.ts","../node_modules/@types/node/domain.d.ts","../node_modules/@types/node/events.d.ts","../node_modules/@types/node/fs.d.ts","../node_modules/@types/node/fs/promises.d.ts","../node_modules/@types/node/http.d.ts","../node_modules/@types/node/http2.d.ts","../node_modules/@types/node/https.d.ts","../node_modules/@types/node/inspector.d.ts","../node_modules/@types/node/module.d.ts","../node_modules/@types/node/net.d.ts","../node_modules/@types/node/os.d.ts","../node_modules/@types/node/path.d.ts","../node_modules/@types/node/perf_hooks.d.ts","../node_modules/@types/node/process.d.ts","../node_modules/@types/node/punycode.d.ts","../node_modules/@types/node/querystring.d.ts","../node_modules/@types/node/readline.d.ts","../node_modules/@types/node/repl.d.ts","../node_modules/@types/node/stream.d.ts","../node_modules/@types/node/stream/promises.d.ts","../node_modules/@types/node/stream/consumers.d.ts","../node_modules/@types/node/stream/web.d.ts","../node_modules/@types/node/string_decoder.d.ts","../node_modules/@types/node/timers.d.ts","../node_modules/@types/node/timers/promises.d.ts","../node_modules/@types/node/tls.d.ts","../node_modules/@types/node/trace_events.d.ts","../node_modules/@types/node/tty.d.ts","../node_modules/@types/node/url.d.ts","../node_modules/@types/node/util.d.ts","../node_modules/@types/node/v8.d.ts","../node_modules/@types/node/vm.d.ts","../node_modules/@types/node/wasi.d.ts","../node_modules/@types/node/worker_threads.d.ts","../node_modules/@types/node/zlib.d.ts","../node_modules/@types/node/globals.global.d.ts","../node_modules/@types/node/index.d.ts","../node_modules/@types/sqlite3/index.d.ts","../sqlite.ts","../../../node_modules/@types/babel-types/index.d.ts","../../../node_modules/@babel/types/lib/index.d.ts","../../../node_modules/@types/babel__generator/index.d.ts","../../../node_modules/@babel/parser/typings/babel-parser.d.ts","../../../node_modules/@types/babel__template/index.d.ts","../../../node_modules/@types/babel__traverse/index.d.ts","../../../node_modules/@types/babel__core/index.d.ts","../../../node_modules/@types/babylon/index.d.ts","../../../node_modules/@types/minimatch/index.d.ts","../../../node_modules/@types/glob/index.d.ts","../../../node_modules/@types/graceful-fs/index.d.ts","../../../node_modules/@types/istanbul-lib-coverage/index.d.ts","../../../node_modules/@types/istanbul-lib-report/index.d.ts","../../../node_modules/@types/istanbul-reports/index.d.ts","../../../node_modules/@types/minimist/index.d.ts","../../../node_modules/@types/normalize-package-data/index.d.ts","../../../node_modules/@types/prettier/index.d.ts","../../../node_modules/@types/stack-utils/index.d.ts","../../../node_modules/@types/yargs-parser/index.d.ts","../../../node_modules/@types/yargs/index.d.ts","../../../node_modules/@types/node/util.d.ts","../../../node_modules/@types/node/events.d.ts","../../../node_modules/@types/node/fs.d.ts","../../../node_modules/@types/node/index.d.ts"],"fileInfos":[{"version":"6adbf5efd0e374ff5f427a4f26a5a413e9734eee5067a0e86da69aea41910b52","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06","e6b724280c694a9f588847f754198fb96c43d805f065c3a5b28bbc9594541c84","e21c071ca3e1b4a815d5f04a7475adcaeea5d64367e840dd0154096d705c3940",{"version":"d8996609230d17e90484a2dd58f22668f9a05a3bfe00bfb1d6271171e54a31fb","affectsGlobalScope":true},{"version":"43fb1d932e4966a39a41b464a12a81899d9ae5f2c829063f5571b6b87e6d2f9c","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"4378fc8122ec9d1a685b01eb66c46f62aba6b239ca7228bb6483bcf8259ee493","affectsGlobalScope":true},{"version":"0d5f52b3174bee6edb81260ebcd792692c32c81fd55499d69531496f3f2b25e7","affectsGlobalScope":true},{"version":"810627a82ac06fb5166da5ada4159c4ec11978dfbb0805fe804c86406dab8357","affectsGlobalScope":true},{"version":"62d80405c46c3f4c527ee657ae9d43fda65a0bf582292429aea1e69144a522a6","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"75ec0bdd727d887f1b79ed6619412ea72ba3c81d92d0787ccb64bab18d261f14","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"12a310447c5d23c7d0d5ca2af606e3bd08afda69100166730ab92c62999ebb9d","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true},{"version":"d154ea5bb7f7f9001ed9153e876b2d5b8f5c2bb9ec02b3ae0d239ec769f1f2ae","affectsGlobalScope":true},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true},{"version":"9d57b2b5d15838ed094aa9ff1299eecef40b190722eb619bac4616657a05f951","affectsGlobalScope":true},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true},{"version":"6e7997ef61de3132e4d4b2250e75343f487903ddf5370e7ce33cf1b9db9a63ed","affectsGlobalScope":true},{"version":"2ad234885a4240522efccd77de6c7d99eecf9b4de0914adb9a35c0c22433f993","affectsGlobalScope":true},{"version":"1b3fe904465430e030c93239a348f05e1be80640d91f2f004c3512c2c2c89f34","affectsGlobalScope":true},{"version":"3787b83e297de7c315d55d4a7c546ae28e5f6c0a361b7a1dcec1f1f50a54ef11","affectsGlobalScope":true},{"version":"e7e8e1d368290e9295ef18ca23f405cf40d5456fa9f20db6373a61ca45f75f40","affectsGlobalScope":true},{"version":"faf0221ae0465363c842ce6aa8a0cbda5d9296940a8e26c86e04cc4081eea21e","affectsGlobalScope":true},{"version":"06393d13ea207a1bfe08ec8d7be562549c5e2da8983f2ee074e00002629d1871","affectsGlobalScope":true},{"version":"d071129cba6a5f2700be09c86c07ad2791ab67d4e5ed1eb301d6746c62745ea4","affectsGlobalScope":true},{"version":"10bbdc1981b8d9310ee75bfac28ee0477bb2353e8529da8cff7cb26c409cb5e8","affectsGlobalScope":true},{"version":"5b4f4eb3939464786d0dae2fe064719de4c4e34f79aa068336a9f96dbf28fcc1","signature":"a9c7ccada9aaaee5ec0c658ece4e06fe251844115d43db9661a9e8bc70c98ddf"},"0d5a2ee1fdfa82740e0103389b9efd6bfe145a20018a2da3c02b89666181f4d9","a69c09dbea52352f479d3e7ac949fde3d17b195abe90b045d619f747b38d6d1a",{"version":"92d63add669d18ebc349efbacd88966d6f2ccdddfb1b880b2db98ae3aa7bf7c4","affectsGlobalScope":true},"ccc94049a9841fe47abe5baef6be9a38fc6228807974ae675fb15dc22531b4be",{"version":"9acfe4d1ff027015151ce81d60797b04b52bffe97ad8310bb0ec2e8fd61e1303","affectsGlobalScope":true},"95843d5cfafced8f3f8a5ce57d2335f0bcd361b9483587d12a25e4bd403b8216","afc6e96061af46bcff47246158caee7e056f5288783f2d83d6858cd25be1c565",{"version":"34f5bcac12b36d70304b73de5f5aab3bb91bd9919f984be80579ebcad03a624e","affectsGlobalScope":true},"82408ed3e959ddc60d3e9904481b5a8dc16469928257af22a3f7d1a3bc7fd8c4","2f520601649a893e6a49a8851ebfcf4be8ce090dc1281c2a08a871cb04e8251f","f50c975ab7b50e25a69e3d8a3773894125b44e9698924105f23b812bf7488baf","2b8c764f856a1dd0a9a2bf23e5efddbff157de8138b0754010be561ae5fcaa90","76650408392bf49a8fbf3e2b6b302712a92d76af77b06e2da1cc8077359c4409","0af3121e68297b2247dd331c0d24dba599e50736a7517a5622d5591aae4a3122","6972fca26f6e9bd56197568d4379f99071a90766e06b4fcb5920a0130a9202be",{"version":"4a2628e95962c8ab756121faa3ac2ed348112ff7a87b5c286dd2cc3326546b4c","affectsGlobalScope":true},"6dfd135b38ab97c536d9c966fc5a5a879a19c6ed75c2c9633902be1ef0945ff7","a049a59a02009fc023684fcfaf0ac526fe36c35dcc5d2b7d620c1750ba11b083","5533392c50c51b1a5c32b89f13145db929c574ef1c5949cf67a074a05ea107d9","b287b810b5035d5685f1df6e1e418f1ca452a3ed4f59fd5cc081dbf2045f0d9b","4b9a003b5c556c96784132945bb41c655ea11273b1917f5c8d0c154dd5fd20dd","a458dc78104cc80048ac24fdc02fe6dce254838094c2f25641b3f954d9721241",{"version":"e8b18c6385ff784228a6f369694fcf1a6b475355ba89090a88de13587a9391d5","affectsGlobalScope":true},"902cd98bf46e95caf4118a0733fb801e9e90eec3edaed6abdad77124afec9ca2","abc1c425b2ad6720433f40f1877abfa4223f0f3dd486c9c28c492179ca183cb6","cd4854d38f4eb5592afd98ab95ca17389a7dfe38013d9079e802d739bdbcc939","94eed4cc2f5f658d5e229ff1ccd38860bddf4233e347bf78edd2154dee1f2b99",{"version":"bd1a08e30569b0fb2f0b21035eb9b039871f68faa9b98accf847e9c878c5e0a9","affectsGlobalScope":true},"9f1069b9e2c051737b1f9b4f1baf50e4a63385a6a89c32235549ae87fc3d5492","ee18f2da7a037c6ceeb112a084e485aead9ea166980bf433474559eac1b46553","29c2706fa0cc49a2bd90c83234da33d08bb9554ecec675e91c1f85087f5a5324","0acbf26bf958f9e80c1ffa587b74749d2697b75b484062d36e103c137c562bc3","d7838022c7dab596357a9604b9c6adffe37dc34085ce0779c958ce9545bd7139","1b952304137851e45bc009785de89ada562d9376177c97e37702e39e60c2f1ff",{"version":"806ef4cac3b3d9fa4a48d849c8e084d7c72fcd7b16d76e06049a9ed742ff79c0","affectsGlobalScope":true},"a279435e7813d1f061c0cab6ab77b1b9377e8d96851e5ed4a76a1ce6eb6e628f","c33a6ea7147af60d8e98f1ac127047f4b0d4e2ce28b8f08ff3de07ca7cc00637",{"version":"b42b47e17b8ece2424ae8039feb944c2e3ba4b262986aebd582e51efbdca93dc","affectsGlobalScope":true},"664d8f2d59164f2e08c543981453893bc7e003e4dfd29651ce09db13e9457980","2408611d9b4146e35d1dbd1f443ccd8e187c74614a54b80300728277529dbf11","998a3de5237518c0b3ac00a11b3b4417affb008aa20aedee52f3fdae3cb86151","ad41008ffe077206e1811fc873f4d9005b5fd7f6ab52bb6118fef600815a5cb4","d88ecca73348e7c337541c4b8b60a50aca5e87384f6b8a422fc6603c637e4c21","badae0df9a8016ac36994b0a0e7b82ba6aaa3528e175a8c3cb161e4683eec03e","c3db860bcaaaeb3bbc23f353bbda1f8ab82756c8d5e973bebb3953cb09ea68f2","235a53595bd20b0b0eeb1a29cb2887c67c48375e92f03749b2488fbd46d0b1a0","bc09393cd4cd13f69cf1366d4236fbae5359bb550f0de4e15767e9a91d63dfb1","9c266243b01545e11d2733a55ad02b4c00ecdbda99c561cd1674f96e89cdc958","c71155c05fc76ff948a4759abc1cb9feec036509f500174bc18dad4c7827a60c",{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true},"1cdb8f094b969dcc183745dc88404e2d8fcf2a858c6e7cc2441011476573238e","502cca269275c29bf4b7cf2175ed724d07fda07132a38095f5a89726661a8265",{"version":"9b79b8a3696c3e789bd1a45f616709bf290b8c0e6ff915906e0c495c075ace5e","signature":"ec9459a119af51518a67ab0652811590fd0f8dcc5a7351e5a3175fffe88078e3"},"75925c52e539a150d822acf3d43f41075d6c371215be27e0c81215a79a802fb4","272c2dac4baaf7fdd2d7efeef0fa2547af54cc21883c5e138b8c4d1661697a54","8dfed5c91ad36e69e6da6b7e49be929d4e19666db2b651aa839c485170a2902c","64b867c61effed7b5bc0cc06b3d8eac23b067a3fba581fc7d3c292fa593e6a45","93de1c6dab503f053efe8d304cb522bb3a89feab8c98f307a674a4fae04773e9","3b043cf9a81854a72963fdb57d1884fc4da1cf5be69b5e0a4c5b751e58cb6d88","d0b0a00cf31968a33baeaadf974ce4e5e7edf58cea5288765293f41ba5e72b3a","b76275b4a94b85da9e4b6b1f8c2b619b996560f9e6030a454260240210a39dd8","8841e2aa774b89bd23302dede20663306dc1b9902431ac64b24be8b8d0e3f649","fd326577c62145816fe1acc306c734c2396487f76719d3785d4e825b34540b33","3ebae8c00411116a66fca65b08228ea0cf0b72724701f9b854442100aab55aba","de18acda71730bac52f4b256ce7511bb56cc21f6f114c59c46782eff2f632857","7eb06594824ada538b1d8b48c3925a83e7db792f47a081a62cf3e5c4e23cf0ee","029769d13d9917e3284cb2356ed28a6576e8b07ae6a06ee1e672518adf21a102","209e814e8e71aec74f69686a9506dd7610b97ab59dcee9446266446f72a76d05","6fa0008bf91a4cc9c8963bace4bba0bd6865cbfa29c3e3ccc461155660fb113a","29651525db5579157e617c77e869af8bfdc1130f5d811c1f759ad35b7bafc8ef","41422586881bcd739b4e62d9b91cd29909f8572aa3e3cdf316b7c50f14708d49","f7e133b20ee2669b6c0e5d7f0cd510868c57cd64b283e68c7f598e30ce9d76d2","09c4b2e2d3070239d563fc690f0cc5db04a2d9b66a23e61aef8b5274e3e9910c"],"options":{"allowSyntheticDefaultImports":true,"composite":true,"declaration":true,"declarationMap":true,"esModuleInterop":true,"module":1,"outDir":"./","rootDir":"..","sourceMap":true,"strict":true,"target":7},"fileIdsList":[[83,94],[83],[83,94,95,96,97,98],[83,94,96],[83,93],[55,56,83,90,101],[56,83,90],[83,104],[83,104,105],[83,111],[40,83],[43,83],[44,49,83],[45,55,56,63,72,82,83],[45,46,55,63,83],[47,83],[48,49,56,64,83],[49,72,79,83],[50,52,55,63,83],[51,83],[52,53,83],[54,55,83],[55,83],[55,56,57,72,82,83],[55,56,57,72,83],[58,63,72,82,83],[55,56,58,59,63,72,79,82,83],[58,60,72,79,82,83],[40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89],[55,61,83],[62,82,83],[52,55,63,72,83],[64,83],[65,83],[43,66,83],[67,81,83,87],[68,83],[69,83],[55,70,83],[70,71,83,85],[55,72,73,74,83],[72,74,83],[72,73,83],[75,83],[76,83],[55,77,78,83],[77,78,83],[49,63,79,83],[80,83],[63,81,83],[44,58,69,82,83],[49,83],[72,83,84],[83,85],[83,86],[44,49,55,57,66,72,82,83,85,87],[72,83,88],[55,83,90],[57,83,91],[94,113],[113],[94,95,96,97,98,113],[94,96,113],[93,113],[101,113,114,115,116],[113,115,116],[104,113],[104,105,113],[111,113],[91]],"referencedMap":[[96,1],[94,2],[93,2],[99,3],[95,1],[97,4],[98,1],[100,5],[102,6],[103,7],[104,2],[105,8],[106,9],[101,2],[107,2],[108,2],[109,2],[110,2],[111,2],[112,10],[9,2],[8,2],[2,2],[10,2],[11,2],[12,2],[13,2],[14,2],[15,2],[16,2],[17,2],[3,2],[4,2],[21,2],[18,2],[19,2],[20,2],[22,2],[23,2],[24,2],[5,2],[25,2],[26,2],[27,2],[28,2],[6,2],[29,2],[30,2],[31,2],[32,2],[7,2],[37,2],[33,2],[34,2],[35,2],[36,2],[1,2],[38,2],[39,2],[40,11],[41,11],[43,12],[44,13],[45,14],[46,15],[47,16],[48,17],[49,18],[50,19],[51,20],[52,21],[53,21],[54,22],[55,23],[56,24],[57,25],[42,2],[89,2],[58,26],[59,27],[60,28],[90,29],[61,30],[62,31],[63,32],[64,33],[65,34],[66,35],[67,36],[68,37],[69,38],[70,39],[71,40],[72,41],[74,42],[73,43],[75,44],[76,45],[77,46],[78,47],[79,48],[80,49],[81,50],[82,51],[83,52],[84,53],[85,54],[86,55],[87,56],[88,57],[91,58],[92,59]],"exportedModulesMap":[[96,60],[94,61],[93,61],[99,62],[95,60],[97,63],[98,60],[100,64],[102,65],[103,66],[104,61],[105,67],[106,68],[101,61],[107,61],[108,61],[109,61],[110,61],[111,61],[112,69],[9,61],[8,61],[2,61],[10,61],[11,61],[12,61],[13,61],[14,61],[15,61],[16,61],[17,61],[3,61],[4,61],[21,61],[18,61],[19,61],[20,61],[22,61],[23,61],[24,61],[5,61],[25,61],[26,61],[27,61],[28,61],[6,61],[29,61],[30,61],[31,61],[32,61],[7,61],[37,61],[33,61],[34,61],[35,61],[36,61],[1,61],[38,61],[40,11],[41,11],[43,12],[44,13],[45,14],[46,15],[47,16],[48,17],[49,18],[50,19],[51,20],[52,21],[53,21],[54,22],[55,23],[56,24],[57,25],[42,2],[89,2],[58,26],[59,27],[60,28],[90,29],[61,30],[62,31],[63,32],[64,33],[65,34],[66,35],[67,36],[68,37],[69,38],[70,39],[71,40],[72,41],[74,42],[73,43],[75,44],[76,45],[77,46],[78,47],[79,48],[80,49],[81,50],[82,51],[83,52],[84,53],[85,54],[86,55],[87,56],[88,57],[91,58],[92,70]],"semanticDiagnosticsPerFile":[96,94,93,99,95,97,98,100,102,103,104,105,106,101,107,108,109,110,111,112,9,8,2,10,11,12,13,14,15,16,17,3,4,21,18,19,20,22,23,24,5,25,26,27,28,6,29,30,31,32,7,37,33,34,35,36,1,38,39,40,41,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,42,89,58,59,60,90,61,62,63,64,65,66,67,68,69,70,71,72,74,73,75,76,77,78,79,80,81,82,83,84,85,86,87,88,91,92]},"version":"4.5.2"}
|
package/package.json
CHANGED
|
@@ -1,20 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saltcorn/sqlite",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2-beta.1",
|
|
4
4
|
"description": "Sqlite structures for Saltcorn, open-source no-code platform",
|
|
5
5
|
"homepage": "https://saltcorn.com",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\""
|
|
7
|
+
"test": "echo \"Error: no test specified\"",
|
|
8
|
+
"tsc": "tsc -p tsconfig.json",
|
|
9
|
+
"clean": "rm -rf ./dist/*"
|
|
8
10
|
},
|
|
9
11
|
"author": "Tom Nielsen",
|
|
10
12
|
"license": "MIT",
|
|
11
|
-
"main": "index.js",
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"exports": {
|
|
15
|
+
"./*": "./dist/*.js"
|
|
16
|
+
},
|
|
17
|
+
"typesVersions": {
|
|
18
|
+
"*": {
|
|
19
|
+
"*": [
|
|
20
|
+
"dist/*"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist/**/*"
|
|
26
|
+
],
|
|
12
27
|
"dependencies": {
|
|
13
|
-
"@saltcorn/db-common": "0.6.
|
|
28
|
+
"@saltcorn/db-common": "0.6.2-beta.1",
|
|
14
29
|
"sqlite3": "^5.0.2"
|
|
15
30
|
},
|
|
16
31
|
"repository": "github:saltcorn/saltcorn",
|
|
17
32
|
"publishConfig": {
|
|
18
33
|
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/node": "^16.11.9",
|
|
37
|
+
"@types/sqlite3": "^3.1.7",
|
|
38
|
+
"typescript": "^4.4.4"
|
|
19
39
|
}
|
|
20
40
|
}
|
package/sqlite.js
DELETED
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SQLite3 data access layer
|
|
3
|
-
* @category sqlite
|
|
4
|
-
* @module sqlite
|
|
5
|
-
*/
|
|
6
|
-
// TODO move all sqlite specific to this module
|
|
7
|
-
const sqlite3 = require("sqlite3").verbose();
|
|
8
|
-
const { sqlsanitize, mkWhere, mkSelectOptions } = require("@saltcorn/db-common/internal");
|
|
9
|
-
const fs = require("fs").promises;
|
|
10
|
-
|
|
11
|
-
let connectObj = null;
|
|
12
|
-
let current_filepath = null;
|
|
13
|
-
let sqliteDatabase = null;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Get sqlite path
|
|
17
|
-
* @returns {string}
|
|
18
|
-
*/
|
|
19
|
-
const get_db_filepath = () => {
|
|
20
|
-
if (connectObj.sqlite_path) return connectObj.sqlite_path;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
let log_sql_enabled = false;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Control Logging sql statements to console
|
|
28
|
-
* @param {boolean} [val = true] - if true then log sql statements to console
|
|
29
|
-
*/
|
|
30
|
-
function set_sql_logging(val = true) {
|
|
31
|
-
log_sql_enabled = val;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Get sql logging state
|
|
36
|
-
* @returns {boolean} if true then sql logging eabled
|
|
37
|
-
*/
|
|
38
|
-
function get_sql_logging() {
|
|
39
|
-
return log_sql_enabled;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Log SQL statement to console
|
|
43
|
-
* @param {string} sql - SQL statement
|
|
44
|
-
* @param {object} [vs] - any additional parameter
|
|
45
|
-
*/
|
|
46
|
-
function sql_log(sql, vs) {
|
|
47
|
-
if (log_sql_enabled)
|
|
48
|
-
if (typeof vs === "undefined") console.log(sql);
|
|
49
|
-
else console.log(sql, vs);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* @param {string} sql
|
|
54
|
-
* @param {object} params
|
|
55
|
-
* @returns {Promise<Object[]>}
|
|
56
|
-
*/
|
|
57
|
-
function query(sql, params) {
|
|
58
|
-
sql_log(sql, params);
|
|
59
|
-
return new Promise((resolve, reject) => {
|
|
60
|
-
sqliteDatabase.all(sql, params, function (err, rows) {
|
|
61
|
-
if (err) {
|
|
62
|
-
reject(err);
|
|
63
|
-
} else {
|
|
64
|
-
resolve({ rows });
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Change connection (close connection and open new connection from connObj)
|
|
71
|
-
* @param {object} connObj - connection object
|
|
72
|
-
* @returns {Promise<void>}
|
|
73
|
-
*/
|
|
74
|
-
const changeConnection = async (connObj) => {
|
|
75
|
-
await sqliteDatabase.close();
|
|
76
|
-
current_filepath = connObj.sqlite_path;
|
|
77
|
-
sqliteDatabase = new sqlite3.Database(current_filepath);
|
|
78
|
-
sqliteExports.sqliteDatabase = sqliteDatabase;
|
|
79
|
-
};
|
|
80
|
-
/**
|
|
81
|
-
* Close database connection
|
|
82
|
-
* @returns {Promise<void>}
|
|
83
|
-
*/
|
|
84
|
-
const close = async () => {
|
|
85
|
-
await sqliteDatabase.close();
|
|
86
|
-
sqliteDatabase = null;
|
|
87
|
-
};
|
|
88
|
-
/**
|
|
89
|
-
* Execute Select statement
|
|
90
|
-
* @param {string} tbl - table name
|
|
91
|
-
* @param {object} whereObj - where object
|
|
92
|
-
* @param {object} [selectopts = {}] - select options
|
|
93
|
-
* @returns {Promise<*>} return rows
|
|
94
|
-
*/
|
|
95
|
-
const select = async (tbl, whereObj, selectopts = {}) => {
|
|
96
|
-
const { where, values } = mkWhere(whereObj, true);
|
|
97
|
-
const sql = `SELECT * FROM "${sqlsanitize(tbl)}" ${where} ${mkSelectOptions(
|
|
98
|
-
selectopts
|
|
99
|
-
)}`;
|
|
100
|
-
const tq = await query(sql, values);
|
|
101
|
-
|
|
102
|
-
return tq.rows;
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
*
|
|
106
|
-
* @param v
|
|
107
|
-
* @returns {boolean}
|
|
108
|
-
*/
|
|
109
|
-
// TODO Utility function - needs ti be moved out this module
|
|
110
|
-
/**
|
|
111
|
-
* @param {object} v
|
|
112
|
-
* @returns {boolean}
|
|
113
|
-
*/
|
|
114
|
-
const reprAsJson = (v) =>
|
|
115
|
-
typeof v === "object" && v !== null && !(v instanceof Date);
|
|
116
|
-
/**
|
|
117
|
-
* @param {object[]} opts
|
|
118
|
-
* @param {*} opts.k
|
|
119
|
-
* @param {object} opts.v
|
|
120
|
-
* @returns {object}
|
|
121
|
-
*/
|
|
122
|
-
const mkVal = ([k, v]) => (reprAsJson(v) ? JSON.stringify(v) : v);
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Drop unique constraint
|
|
126
|
-
* @param {string} tbl - table name
|
|
127
|
-
* @param {object[]} obj - list of column=value pairs
|
|
128
|
-
* @param {number} id - primary key column value
|
|
129
|
-
* @returns {Promise<void>} no results
|
|
130
|
-
*/
|
|
131
|
-
const update = async (tbl, obj, id) => {
|
|
132
|
-
const kvs = Object.entries(obj);
|
|
133
|
-
const assigns = kvs.map(([k, v], ix) => `"${sqlsanitize(k)}"=?`).join();
|
|
134
|
-
let valList = kvs.map(mkVal);
|
|
135
|
-
valList.push(id);
|
|
136
|
-
const q = `update "${sqlsanitize(tbl)}" set ${assigns} where id=?`;
|
|
137
|
-
await query(q, valList);
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Delete rows in table
|
|
142
|
-
* @param {string} tbl - table name
|
|
143
|
-
* @param {object} whereObj - where object
|
|
144
|
-
* @returns {Promise<void>} result of delete execution
|
|
145
|
-
*/
|
|
146
|
-
const deleteWhere = async (tbl, whereObj) => {
|
|
147
|
-
const { where, values } = mkWhere(whereObj, true);
|
|
148
|
-
const sql = `delete FROM "${sqlsanitize(tbl)}" ${where}`;
|
|
149
|
-
|
|
150
|
-
const tq = await query(sql, values);
|
|
151
|
-
};
|
|
152
|
-
/**
|
|
153
|
-
* Insert rows into table
|
|
154
|
-
* @param {string} tbl - table name
|
|
155
|
-
* @param {object} obj - columns names and data
|
|
156
|
-
* @param {object} [opts = {}] - columns attributes
|
|
157
|
-
* @returns {Promise<string>} returns id.
|
|
158
|
-
*/
|
|
159
|
-
const insert = async (tbl, obj, opts = {}) => {
|
|
160
|
-
const kvs = Object.entries(obj);
|
|
161
|
-
const fnameList = kvs.map(([k, v]) => `"${sqlsanitize(k)}"`).join();
|
|
162
|
-
const valPosList = kvs
|
|
163
|
-
.map(([k, v], ix) =>
|
|
164
|
-
v && v.next_version_by_id
|
|
165
|
-
? `coalesce((select max(_version) from "${sqlsanitize(
|
|
166
|
-
tbl
|
|
167
|
-
)}" where id=${+v.next_version_by_id}), 0)+1`
|
|
168
|
-
: reprAsJson(v)
|
|
169
|
-
? "json(?)"
|
|
170
|
-
: "?"
|
|
171
|
-
)
|
|
172
|
-
.join();
|
|
173
|
-
const valList = kvs
|
|
174
|
-
.filter(([k, v]) => !(v && v.next_version_by_id))
|
|
175
|
-
.map(mkVal);
|
|
176
|
-
const sql = `insert into "${sqlsanitize(
|
|
177
|
-
tbl
|
|
178
|
-
)}"(${fnameList}) values(${valPosList})`;
|
|
179
|
-
|
|
180
|
-
await query(sql, valList);
|
|
181
|
-
if (opts.noid) return;
|
|
182
|
-
// TBD Support of primary key column different from id
|
|
183
|
-
const ids = await query("SELECT last_insert_rowid() as id");
|
|
184
|
-
return ids.rows[0].id;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Select one record
|
|
189
|
-
* @param {string} tbl - table name
|
|
190
|
-
* @param {object} where - where object
|
|
191
|
-
* @throws {Error}
|
|
192
|
-
* @returns {Promise<object>} return first record from sql result
|
|
193
|
-
*/
|
|
194
|
-
const selectOne = async (tbl, where) => {
|
|
195
|
-
const rows = await select(tbl, where);
|
|
196
|
-
if (rows.length === 0) {
|
|
197
|
-
const w = mkWhere(where, true);
|
|
198
|
-
throw new Error(`no ${tbl} ${w.where} are ${w.values}`);
|
|
199
|
-
} else return rows[0];
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Select one record or null if no records
|
|
204
|
-
* @param {string} tbl - table name
|
|
205
|
-
* @param {object} where - where object
|
|
206
|
-
* @returns {Promise<object>} - null if no record or first record data
|
|
207
|
-
*/
|
|
208
|
-
const selectMaybeOne = async (tbl, where) => {
|
|
209
|
-
const rows = await select(tbl, where);
|
|
210
|
-
if (rows.length === 0) return null;
|
|
211
|
-
else return rows[0];
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Get count of rows in table
|
|
216
|
-
* @param {string} tbl - table name
|
|
217
|
-
* @param {object} whereObj - where object
|
|
218
|
-
* @returns {Promise<number>} count of tables
|
|
219
|
-
*/
|
|
220
|
-
const count = async (tbl, whereObj) => {
|
|
221
|
-
const { where, values } = mkWhere(whereObj, true);
|
|
222
|
-
const sql = `SELECT COUNT(*) FROM "${sqlsanitize(tbl)}" ${where}`;
|
|
223
|
-
const tq = await query(sql, values);
|
|
224
|
-
return parseInt(tq.rows[0]["COUNT(*)"]);
|
|
225
|
-
};
|
|
226
|
-
/**
|
|
227
|
-
* Get version of PostgreSQL
|
|
228
|
-
* @returns {Promise<string>} returns version
|
|
229
|
-
*/
|
|
230
|
-
const getVersion = async () => {
|
|
231
|
-
const sql = `SELECT sqlite_version();`;
|
|
232
|
-
sql_log(sql);
|
|
233
|
-
const tq = await query(sql);
|
|
234
|
-
return tq.rows[0]["sqlite_version()"];
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Reset DB Schema using drop schema and recreate it.
|
|
239
|
-
* Attention! You will lost data after call this function!
|
|
240
|
-
* @returns {Promise<void>} no result
|
|
241
|
-
*/
|
|
242
|
-
const drop_reset_schema = async () => {
|
|
243
|
-
await sqliteDatabase.close();
|
|
244
|
-
await fs.unlink(current_filepath);
|
|
245
|
-
sqliteDatabase = new sqlite3.Database(current_filepath);
|
|
246
|
-
sqliteExports.sqliteDatabase = sqliteDatabase;
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Add unique constraint
|
|
251
|
-
* @param {string} table_name - table name
|
|
252
|
-
* @param {string[]} field_names - list of columns (members of constraint)
|
|
253
|
-
* @returns {Promise<void>} no result
|
|
254
|
-
*/
|
|
255
|
-
const add_unique_constraint = async (table_name, field_names) => {
|
|
256
|
-
const sql = `create unique index ${sqlsanitize(
|
|
257
|
-
table_name
|
|
258
|
-
)}_${field_names
|
|
259
|
-
.map((f) => sqlsanitize(f))
|
|
260
|
-
.join("_")}_unique on "${sqlsanitize(table_name)}"(${field_names
|
|
261
|
-
.map((f) => `"${sqlsanitize(f)}"`)
|
|
262
|
-
.join(",")});`;
|
|
263
|
-
sql_log(sql);
|
|
264
|
-
await query(sql);
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Drop unique constraint
|
|
269
|
-
* @param {string} table_name - table name
|
|
270
|
-
* @param {string[]} field_names - list of columns (members of constraint)
|
|
271
|
-
* @returns {Promise<void>} no results
|
|
272
|
-
*/
|
|
273
|
-
const drop_unique_constraint = async (table_name, field_names) => {
|
|
274
|
-
const sql = `drop index ${sqlsanitize(table_name)}_${field_names
|
|
275
|
-
.map((f) => sqlsanitize(f))
|
|
276
|
-
.join("_")}_unique;`;
|
|
277
|
-
sql_log(sql);
|
|
278
|
-
await query(sql);
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
const sqliteExports = {
|
|
282
|
-
sql_log,
|
|
283
|
-
set_sql_logging,
|
|
284
|
-
get_sql_logging,
|
|
285
|
-
sqliteDatabase,
|
|
286
|
-
changeConnection,
|
|
287
|
-
query,
|
|
288
|
-
select,
|
|
289
|
-
selectOne,
|
|
290
|
-
selectMaybeOne,
|
|
291
|
-
insert,
|
|
292
|
-
count,
|
|
293
|
-
close,
|
|
294
|
-
drop_reset_schema,
|
|
295
|
-
update,
|
|
296
|
-
deleteWhere,
|
|
297
|
-
add_unique_constraint,
|
|
298
|
-
drop_unique_constraint,
|
|
299
|
-
getVersion,
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
module.exports = (getConnectObject) => {
|
|
303
|
-
if (!sqliteDatabase) {
|
|
304
|
-
connectObj = getConnectObject();
|
|
305
|
-
current_filepath = get_db_filepath();
|
|
306
|
-
sqliteDatabase = new sqlite3.Database(current_filepath);
|
|
307
|
-
sqliteExports.sqliteDatabase = sqliteDatabase;
|
|
308
|
-
}
|
|
309
|
-
return sqliteExports;
|
|
310
|
-
}
|