@sqlitecloud/drivers 1.0.289 → 1.0.354
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 +3 -3
- package/lib/drivers/connection-tls.d.ts +2 -2
- package/lib/drivers/connection-tls.js +20 -8
- package/lib/drivers/connection-ws.d.ts +2 -2
- package/lib/drivers/connection-ws.js +4 -2
- package/lib/drivers/connection.d.ts +5 -4
- package/lib/drivers/connection.js +16 -15
- package/lib/drivers/database.d.ts +3 -3
- package/lib/drivers/database.js +45 -36
- package/lib/drivers/protocol.d.ts +3 -3
- package/lib/drivers/protocol.js +61 -15
- package/lib/drivers/pubsub.d.ts +5 -0
- package/lib/drivers/pubsub.js +14 -5
- package/lib/drivers/statement.d.ts +12 -6
- package/lib/drivers/statement.js +53 -56
- package/lib/drivers/types.d.ts +11 -9
- package/lib/drivers/types.js +1 -1
- package/lib/drivers/utilities.d.ts +2 -4
- package/lib/drivers/utilities.js +27 -82
- package/lib/index.d.ts +1 -2
- package/lib/index.js +19 -12
- package/lib/sqlitecloud.drivers.dev.js +65 -76
- package/lib/sqlitecloud.drivers.js +1 -1
- package/package.json +16 -27
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { Database } from './database';
|
|
5
5
|
import { RowCallback, RowsCallback, RowCountCallback, ResultsCallback } from './types';
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* A statement generated by Database.prepare used to prepare SQL with ? bindings.
|
|
8
|
+
*
|
|
9
|
+
* SCSP protocol does not support named placeholders yet.
|
|
10
|
+
*/
|
|
7
11
|
export declare class Statement<T> {
|
|
8
12
|
constructor(database: Database, sql: string, ...params: any[]);
|
|
9
13
|
/** Statement belongs to this database */
|
|
@@ -11,15 +15,17 @@ export declare class Statement<T> {
|
|
|
11
15
|
/** The SQL statement with ? binding placeholders */
|
|
12
16
|
private _sql;
|
|
13
17
|
/** The SQL statement with binding values applied */
|
|
14
|
-
private _preparedSql
|
|
18
|
+
private _preparedSql;
|
|
15
19
|
/**
|
|
16
20
|
* Binds parameters to the prepared statement and calls the callback when done
|
|
17
21
|
* or when an error occurs. The function returns the Statement object to allow
|
|
18
22
|
* for function chaining. The first and only argument to the callback is null
|
|
19
|
-
* when binding was successful
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
+
* when binding was successful. Binding parameters with this function completely
|
|
24
|
+
* resets the statement object and row cursor and removes all previously bound
|
|
25
|
+
* parameters, if any.
|
|
26
|
+
*
|
|
27
|
+
* In SQLiteCloud the statement is prepared on the database server and binding errors
|
|
28
|
+
* are raised on execution time.
|
|
23
29
|
*/
|
|
24
30
|
bind(...params: any[]): this;
|
|
25
31
|
/**
|
package/lib/drivers/statement.js
CHANGED
|
@@ -5,118 +5,115 @@
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Statement = void 0;
|
|
7
7
|
const utilities_1 = require("./utilities");
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* A statement generated by Database.prepare used to prepare SQL with ? bindings.
|
|
10
|
+
*
|
|
11
|
+
* SCSP protocol does not support named placeholders yet.
|
|
12
|
+
*/
|
|
10
13
|
class Statement {
|
|
11
14
|
constructor(database, sql, ...params) {
|
|
12
|
-
|
|
15
|
+
/** The SQL statement with binding values applied */
|
|
16
|
+
this._preparedSql = { query: '' };
|
|
13
17
|
this._database = database;
|
|
14
18
|
this._sql = sql;
|
|
15
|
-
|
|
16
|
-
this.bind(...args, callback);
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
callback === null || callback === void 0 ? void 0 : callback.call(this, null);
|
|
20
|
-
}
|
|
19
|
+
this.bind(...params);
|
|
21
20
|
}
|
|
22
21
|
/**
|
|
23
22
|
* Binds parameters to the prepared statement and calls the callback when done
|
|
24
23
|
* or when an error occurs. The function returns the Statement object to allow
|
|
25
24
|
* for function chaining. The first and only argument to the callback is null
|
|
26
|
-
* when binding was successful
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
25
|
+
* when binding was successful. Binding parameters with this function completely
|
|
26
|
+
* resets the statement object and row cursor and removes all previously bound
|
|
27
|
+
* parameters, if any.
|
|
28
|
+
*
|
|
29
|
+
* In SQLiteCloud the statement is prepared on the database server and binding errors
|
|
30
|
+
* are raised on execution time.
|
|
30
31
|
*/
|
|
31
32
|
bind(...params) {
|
|
32
33
|
const { args, callback } = (0, utilities_1.popCallback)(params);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
callback.call(this, null);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
this._preparedSql = undefined;
|
|
41
|
-
if (callback) {
|
|
42
|
-
callback.call(this, error);
|
|
43
|
-
}
|
|
34
|
+
this._preparedSql = { query: this._sql, parameters: args };
|
|
35
|
+
if (callback) {
|
|
36
|
+
callback.call(this, null);
|
|
44
37
|
}
|
|
45
38
|
return this;
|
|
46
39
|
}
|
|
47
40
|
run(...params) {
|
|
41
|
+
var _a;
|
|
48
42
|
const { args, callback } = (0, utilities_1.popCallback)(params || []);
|
|
49
43
|
if ((args === null || args === void 0 ? void 0 : args.length) > 0) {
|
|
50
44
|
// apply new bindings then execute
|
|
51
|
-
this.bind(...args, (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this._database.run(this._preparedSql || '', callback);
|
|
57
|
-
}
|
|
45
|
+
this.bind(...args, () => {
|
|
46
|
+
var _a;
|
|
47
|
+
const query = this._preparedSql.query || '';
|
|
48
|
+
const parametes = [...((_a = this._preparedSql.parameters) !== null && _a !== void 0 ? _a : [])];
|
|
49
|
+
this._database.run(query, ...parametes, callback);
|
|
58
50
|
});
|
|
59
51
|
}
|
|
60
52
|
else {
|
|
61
53
|
// execute prepared sql with same bindings
|
|
62
|
-
this.
|
|
54
|
+
const query = this._preparedSql.query || '';
|
|
55
|
+
const parametes = [...((_a = this._preparedSql.parameters) !== null && _a !== void 0 ? _a : [])];
|
|
56
|
+
this._database.run(query, ...parametes, callback);
|
|
63
57
|
}
|
|
64
58
|
return this;
|
|
65
59
|
}
|
|
66
60
|
get(...params) {
|
|
61
|
+
var _a;
|
|
67
62
|
const { args, callback } = (0, utilities_1.popCallback)(params || []);
|
|
68
63
|
if ((args === null || args === void 0 ? void 0 : args.length) > 0) {
|
|
69
64
|
// apply new bindings then execute
|
|
70
|
-
this.bind(...args, (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
this._database.get(this._preparedSql || '', callback);
|
|
76
|
-
}
|
|
65
|
+
this.bind(...args, () => {
|
|
66
|
+
var _a;
|
|
67
|
+
const query = this._preparedSql.query || '';
|
|
68
|
+
const parametes = [...((_a = this._preparedSql.parameters) !== null && _a !== void 0 ? _a : [])];
|
|
69
|
+
this._database.get(query, ...parametes, callback);
|
|
77
70
|
});
|
|
78
71
|
}
|
|
79
72
|
else {
|
|
80
73
|
// execute prepared sql with same bindings
|
|
81
|
-
this.
|
|
74
|
+
const query = this._preparedSql.query || '';
|
|
75
|
+
const parametes = [...((_a = this._preparedSql.parameters) !== null && _a !== void 0 ? _a : [])];
|
|
76
|
+
this._database.get(query, ...parametes, callback);
|
|
82
77
|
}
|
|
83
78
|
return this;
|
|
84
79
|
}
|
|
85
80
|
all(...params) {
|
|
81
|
+
var _a;
|
|
86
82
|
const { args, callback } = (0, utilities_1.popCallback)(params || []);
|
|
87
83
|
if ((args === null || args === void 0 ? void 0 : args.length) > 0) {
|
|
88
84
|
// apply new bindings then execute
|
|
89
|
-
this.bind(...args, (
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
this._database.all(this._preparedSql || '', callback);
|
|
95
|
-
}
|
|
85
|
+
this.bind(...args, () => {
|
|
86
|
+
var _a;
|
|
87
|
+
const query = this._preparedSql.query || '';
|
|
88
|
+
const parametes = [...((_a = this._preparedSql.parameters) !== null && _a !== void 0 ? _a : [])];
|
|
89
|
+
this._database.all(query, ...parametes, callback);
|
|
96
90
|
});
|
|
97
91
|
}
|
|
98
92
|
else {
|
|
99
93
|
// execute prepared sql with same bindings
|
|
100
|
-
this.
|
|
94
|
+
const query = this._preparedSql.query || '';
|
|
95
|
+
const parametes = [...((_a = this._preparedSql.parameters) !== null && _a !== void 0 ? _a : [])];
|
|
96
|
+
this._database.all(query, ...parametes, callback);
|
|
101
97
|
}
|
|
102
98
|
return this;
|
|
103
99
|
}
|
|
104
100
|
each(...params) {
|
|
101
|
+
var _a;
|
|
105
102
|
const { args, callback, complete } = (0, utilities_1.popCallback)(params);
|
|
106
103
|
if ((args === null || args === void 0 ? void 0 : args.length) > 0) {
|
|
107
104
|
// apply new bindings then execute
|
|
108
|
-
this.bind(...args, (
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
this._database.each(this._preparedSql || '', callback, complete);
|
|
114
|
-
}
|
|
105
|
+
this.bind(...args, () => {
|
|
106
|
+
var _a;
|
|
107
|
+
const query = this._preparedSql.query || '';
|
|
108
|
+
const parametes = [...((_a = this._preparedSql.parameters) !== null && _a !== void 0 ? _a : []), ...[callback, complete]];
|
|
109
|
+
this._database.each(query, ...parametes);
|
|
115
110
|
});
|
|
116
111
|
}
|
|
117
112
|
else {
|
|
118
113
|
// execute prepared sql with same bindings
|
|
119
|
-
this.
|
|
114
|
+
const query = this._preparedSql.query || '';
|
|
115
|
+
const parametes = [...((_a = this._preparedSql.parameters) !== null && _a !== void 0 ? _a : []), ...[callback, complete]];
|
|
116
|
+
this._database.each(query, ...parametes);
|
|
120
117
|
}
|
|
121
118
|
return this;
|
|
122
119
|
}
|
package/lib/drivers/types.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* types.ts - shared types and interfaces
|
|
3
3
|
*/
|
|
4
|
-
/// <reference types="node" />
|
|
5
|
-
/// <reference types="node" />
|
|
6
4
|
import tls from 'tls';
|
|
7
5
|
/** Default timeout value for queries */
|
|
8
6
|
export declare const DEFAULT_TIMEOUT: number;
|
|
@@ -91,6 +89,10 @@ export interface SQLCloudRowsetMetadata {
|
|
|
91
89
|
}
|
|
92
90
|
/** Basic types that can be returned by SQLiteCloud APIs */
|
|
93
91
|
export type SQLiteCloudDataTypes = string | number | bigint | boolean | Record<string | number, unknown> | Buffer | null | undefined;
|
|
92
|
+
export interface SQLiteCloudCommand {
|
|
93
|
+
query: string;
|
|
94
|
+
parameters?: SQLiteCloudDataTypes[];
|
|
95
|
+
}
|
|
94
96
|
/** Custom error reported by SQLiteCloud drivers */
|
|
95
97
|
export declare class SQLiteCloudError extends Error {
|
|
96
98
|
constructor(message: string, args?: Partial<SQLiteCloudError>);
|
|
@@ -115,17 +117,17 @@ export type PubSubCallback<T = any> = (error: Error | null, results?: T, extraDa
|
|
|
115
117
|
* is called SQCLOUD_ARRAY_TYPE in the C API.
|
|
116
118
|
*/
|
|
117
119
|
export declare enum SQLiteCloudArrayType {
|
|
118
|
-
ARRAY_TYPE_SQLITE_EXEC = 10
|
|
120
|
+
ARRAY_TYPE_SQLITE_EXEC = 10,// used in SQLITE_MODE only when a write statement is executed (instead of the OK reply)
|
|
119
121
|
ARRAY_TYPE_DB_STATUS = 11,
|
|
120
122
|
ARRAY_TYPE_METADATA = 12,
|
|
121
|
-
ARRAY_TYPE_VM_STEP = 20
|
|
122
|
-
ARRAY_TYPE_VM_COMPILE = 21
|
|
123
|
-
ARRAY_TYPE_VM_STEP_ONE = 22
|
|
123
|
+
ARRAY_TYPE_VM_STEP = 20,// used in VM_STEP (when SQLITE_DONE is returned)
|
|
124
|
+
ARRAY_TYPE_VM_COMPILE = 21,// used in VM_PREPARE
|
|
125
|
+
ARRAY_TYPE_VM_STEP_ONE = 22,// unused in this version (will be used to step in a server-side rowset)
|
|
124
126
|
ARRAY_TYPE_VM_SQL = 23,
|
|
125
127
|
ARRAY_TYPE_VM_STATUS = 24,
|
|
126
128
|
ARRAY_TYPE_VM_LIST = 25,
|
|
127
|
-
ARRAY_TYPE_BACKUP_INIT = 40
|
|
128
|
-
ARRAY_TYPE_BACKUP_STEP = 41
|
|
129
|
-
ARRAY_TYPE_BACKUP_END = 42
|
|
129
|
+
ARRAY_TYPE_BACKUP_INIT = 40,// used in BACKUP_INIT
|
|
130
|
+
ARRAY_TYPE_BACKUP_STEP = 41,// used in backupWrite (VFS)
|
|
131
|
+
ARRAY_TYPE_BACKUP_END = 42,// used in backupClose (VFS)
|
|
130
132
|
ARRAY_TYPE_SQLITE_STATUS = 50
|
|
131
133
|
}
|
package/lib/drivers/types.js
CHANGED
|
@@ -39,4 +39,4 @@ var SQLiteCloudArrayType;
|
|
|
39
39
|
SQLiteCloudArrayType[SQLiteCloudArrayType["ARRAY_TYPE_BACKUP_STEP"] = 41] = "ARRAY_TYPE_BACKUP_STEP";
|
|
40
40
|
SQLiteCloudArrayType[SQLiteCloudArrayType["ARRAY_TYPE_BACKUP_END"] = 42] = "ARRAY_TYPE_BACKUP_END";
|
|
41
41
|
SQLiteCloudArrayType[SQLiteCloudArrayType["ARRAY_TYPE_SQLITE_STATUS"] = 50] = "ARRAY_TYPE_SQLITE_STATUS"; // used in sqlite_status
|
|
42
|
-
})(SQLiteCloudArrayType
|
|
42
|
+
})(SQLiteCloudArrayType || (exports.SQLiteCloudArrayType = SQLiteCloudArrayType = {}));
|
|
@@ -7,10 +7,8 @@ export declare function anonimizeCommand(message: string): string;
|
|
|
7
7
|
export declare function anonimizeError(error: Error): Error;
|
|
8
8
|
/** Initialization commands sent to database when connection is established */
|
|
9
9
|
export declare function getInitializationCommands(config: SQLiteCloudConfig): string;
|
|
10
|
-
/**
|
|
11
|
-
export declare function
|
|
12
|
-
/** Take a sql statement and replaces ? or $named parameters that are properly serialized and escaped. */
|
|
13
|
-
export declare function prepareSql(sql: string, ...params: (SQLiteCloudDataTypes | SQLiteCloudDataTypes[])[]): string;
|
|
10
|
+
/** Sanitizes an SQLite identifier (e.g., table name, column name). */
|
|
11
|
+
export declare function sanitizeSQLiteIdentifier(identifier: any): string;
|
|
14
12
|
/** Converts results of an update or insert call into a more meaning full result set */
|
|
15
13
|
export declare function getUpdateResults(results?: any): Record<string, any> | undefined;
|
|
16
14
|
/**
|
package/lib/drivers/utilities.js
CHANGED
|
@@ -3,12 +3,21 @@
|
|
|
3
3
|
// utilities.ts - utility methods to manipulate SQL statements
|
|
4
4
|
//
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.isNode = exports.isBrowser = void 0;
|
|
7
|
+
exports.anonimizeCommand = anonimizeCommand;
|
|
8
|
+
exports.anonimizeError = anonimizeError;
|
|
9
|
+
exports.getInitializationCommands = getInitializationCommands;
|
|
10
|
+
exports.sanitizeSQLiteIdentifier = sanitizeSQLiteIdentifier;
|
|
11
|
+
exports.getUpdateResults = getUpdateResults;
|
|
12
|
+
exports.popCallback = popCallback;
|
|
13
|
+
exports.validateConfiguration = validateConfiguration;
|
|
14
|
+
exports.parseconnectionstring = parseconnectionstring;
|
|
15
|
+
exports.parseBoolean = parseBoolean;
|
|
16
|
+
exports.parseBooleanToZeroOne = parseBooleanToZeroOne;
|
|
7
17
|
const types_1 = require("./types");
|
|
8
18
|
const types_2 = require("./types");
|
|
9
19
|
// explicitly importing these libraries to allow cross-platform support by replacing them
|
|
10
20
|
const whatwg_url_1 = require("whatwg-url");
|
|
11
|
-
const buffer_1 = require("buffer");
|
|
12
21
|
//
|
|
13
22
|
// determining running environment, thanks to browser-or-node
|
|
14
23
|
// https://www.npmjs.com/package/browser-or-node
|
|
@@ -26,7 +35,6 @@ function anonimizeCommand(message) {
|
|
|
26
35
|
message = message.replace(/HASH \S+?(?=;)/, 'HASH ******');
|
|
27
36
|
return message;
|
|
28
37
|
}
|
|
29
|
-
exports.anonimizeCommand = anonimizeCommand;
|
|
30
38
|
/** Strip message code in error of user credentials */
|
|
31
39
|
function anonimizeError(error) {
|
|
32
40
|
if (error === null || error === void 0 ? void 0 : error.message) {
|
|
@@ -34,7 +42,6 @@ function anonimizeError(error) {
|
|
|
34
42
|
}
|
|
35
43
|
return error;
|
|
36
44
|
}
|
|
37
|
-
exports.anonimizeError = anonimizeError;
|
|
38
45
|
/** Initialization commands sent to database when connection is established */
|
|
39
46
|
function getInitializationCommands(config) {
|
|
40
47
|
// we check the credentials using non linearizable so we're quicker
|
|
@@ -78,73 +85,18 @@ function getInitializationCommands(config) {
|
|
|
78
85
|
}
|
|
79
86
|
return commands;
|
|
80
87
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
if (typeof param === 'number' || typeof param === 'bigint') {
|
|
93
|
-
return param.toString();
|
|
94
|
-
}
|
|
95
|
-
if (typeof param === 'boolean') {
|
|
96
|
-
return param ? '1' : '0';
|
|
97
|
-
}
|
|
98
|
-
// serialize buffer as X'...' hex encoded string
|
|
99
|
-
if (buffer_1.Buffer.isBuffer(param)) {
|
|
100
|
-
return `X'${param.toString('hex')}'`;
|
|
101
|
-
}
|
|
102
|
-
if (typeof param === 'object') {
|
|
103
|
-
// serialize json then escape single quotes
|
|
104
|
-
let json = JSON.stringify(param);
|
|
105
|
-
json = json.replace(/'/g, "''");
|
|
106
|
-
return `'${json}'`;
|
|
107
|
-
}
|
|
108
|
-
throw new types_1.SQLiteCloudError(`Unsupported parameter type: ${typeof param}`);
|
|
109
|
-
}
|
|
110
|
-
exports.escapeSqlParameter = escapeSqlParameter;
|
|
111
|
-
/** Take a sql statement and replaces ? or $named parameters that are properly serialized and escaped. */
|
|
112
|
-
function prepareSql(sql, ...params) {
|
|
113
|
-
// parameters where passed as an array of parameters?
|
|
114
|
-
if ((params === null || params === void 0 ? void 0 : params.length) === 1 && Array.isArray(params[0])) {
|
|
115
|
-
params = params[0];
|
|
116
|
-
}
|
|
117
|
-
// replace ? or ?idx parameters passed as args or as an array
|
|
118
|
-
let parameterIndex = 1;
|
|
119
|
-
let preparedSql = sql.replace(/\?(\d+)?/g, (match, matchIndex) => {
|
|
120
|
-
const index = matchIndex ? parseInt(matchIndex) : parameterIndex;
|
|
121
|
-
parameterIndex++;
|
|
122
|
-
let sqlParameter;
|
|
123
|
-
if (params[0] && typeof params[0] === 'object' && !(params[0] instanceof buffer_1.Buffer)) {
|
|
124
|
-
sqlParameter = params[0][index];
|
|
125
|
-
}
|
|
126
|
-
if (!sqlParameter) {
|
|
127
|
-
if (index > params.length) {
|
|
128
|
-
throw new types_1.SQLiteCloudError('Not enough parameters');
|
|
129
|
-
}
|
|
130
|
-
sqlParameter = params[index - 1];
|
|
131
|
-
}
|
|
132
|
-
return sqlParameter !== null && sqlParameter !== undefined ? escapeSqlParameter(sqlParameter) : 'NULL';
|
|
133
|
-
});
|
|
134
|
-
// replace $named or :named parameters passed as an object
|
|
135
|
-
if ((params === null || params === void 0 ? void 0 : params.length) === 1 && params[0] && typeof params[0] === 'object') {
|
|
136
|
-
const namedParams = params[0];
|
|
137
|
-
for (const [paramKey, param] of Object.entries(namedParams)) {
|
|
138
|
-
const firstChar = paramKey.charAt(0);
|
|
139
|
-
if (firstChar == '$' || firstChar == ':' || firstChar == '@') {
|
|
140
|
-
const escapedParam = escapeSqlParameter(param);
|
|
141
|
-
preparedSql = preparedSql.replace(new RegExp(`\\${paramKey}`, 'g'), escapedParam);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return preparedSql;
|
|
88
|
+
/** Sanitizes an SQLite identifier (e.g., table name, column name). */
|
|
89
|
+
function sanitizeSQLiteIdentifier(identifier) {
|
|
90
|
+
const trimmed = identifier.trim();
|
|
91
|
+
// it's not empty
|
|
92
|
+
if (trimmed.length === 0) {
|
|
93
|
+
throw new Error('Identifier cannot be empty.');
|
|
94
|
+
}
|
|
95
|
+
// escape double quotes
|
|
96
|
+
const escaped = trimmed.replace(/"/g, '""');
|
|
97
|
+
// Wrap in double quotes for safety
|
|
98
|
+
return `"${escaped}"`;
|
|
146
99
|
}
|
|
147
|
-
exports.prepareSql = prepareSql;
|
|
148
100
|
/** Converts results of an update or insert call into a more meaning full result set */
|
|
149
101
|
function getUpdateResults(results) {
|
|
150
102
|
if (results) {
|
|
@@ -154,10 +106,10 @@ function getUpdateResults(results) {
|
|
|
154
106
|
return {
|
|
155
107
|
type: results[0],
|
|
156
108
|
index: results[1],
|
|
157
|
-
lastID: results[2],
|
|
158
|
-
changes: results[3],
|
|
159
|
-
totalChanges: results[4],
|
|
160
|
-
finalized: results[5],
|
|
109
|
+
lastID: results[2], // ROWID (sqlite3_last_insert_rowid)
|
|
110
|
+
changes: results[3], // CHANGES(sqlite3_changes)
|
|
111
|
+
totalChanges: results[4], // TOTAL_CHANGES (sqlite3_total_changes)
|
|
112
|
+
finalized: results[5], // FINALIZED
|
|
161
113
|
//
|
|
162
114
|
rowId: results[2] // same as lastId
|
|
163
115
|
};
|
|
@@ -166,7 +118,6 @@ function getUpdateResults(results) {
|
|
|
166
118
|
}
|
|
167
119
|
return undefined;
|
|
168
120
|
}
|
|
169
|
-
exports.getUpdateResults = getUpdateResults;
|
|
170
121
|
/**
|
|
171
122
|
* Many of the methods in our API may contain a callback as their last argument.
|
|
172
123
|
* This method will take the arguments array passed to the method and return an object
|
|
@@ -186,7 +137,6 @@ function popCallback(args) {
|
|
|
186
137
|
}
|
|
187
138
|
return { args: remaining };
|
|
188
139
|
}
|
|
189
|
-
exports.popCallback = popCallback;
|
|
190
140
|
//
|
|
191
141
|
// configuration validation
|
|
192
142
|
//
|
|
@@ -214,7 +164,6 @@ function validateConfiguration(config) {
|
|
|
214
164
|
}
|
|
215
165
|
if (!config.connectionstring) {
|
|
216
166
|
// build connection string from configuration, values are already validated
|
|
217
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
218
167
|
if (config.apikey) {
|
|
219
168
|
config.connectionstring = `sqlitecloud://${config.host}:${config.port}/${config.database || ''}?apikey=${config.apikey}`;
|
|
220
169
|
}
|
|
@@ -224,7 +173,6 @@ function validateConfiguration(config) {
|
|
|
224
173
|
}
|
|
225
174
|
return config;
|
|
226
175
|
}
|
|
227
|
-
exports.validateConfiguration = validateConfiguration;
|
|
228
176
|
/**
|
|
229
177
|
* Parse connectionstring like sqlitecloud://username:password@host:port/database?option1=xxx&option2=xxx
|
|
230
178
|
* or sqlitecloud://host.sqlite.cloud:8860/chinook.sqlite?apikey=mIiLARzKm9XBVllbAzkB1wqrgijJ3Gx0X5z1Agm3xBo
|
|
@@ -242,7 +190,7 @@ function parseconnectionstring(connectionstring) {
|
|
|
242
190
|
// all lowecase options
|
|
243
191
|
const options = {};
|
|
244
192
|
url.searchParams.forEach((value, key) => {
|
|
245
|
-
options[key.toLowerCase().
|
|
193
|
+
options[key.toLowerCase().replace(/-/g, '_')] = value;
|
|
246
194
|
});
|
|
247
195
|
const config = Object.assign({ username: decodeURIComponent(url.username), password: decodeURIComponent(url.password), host: url.hostname, port: url.port ? parseInt(url.port) : undefined }, options);
|
|
248
196
|
// either you use an apikey or username and password
|
|
@@ -263,7 +211,6 @@ function parseconnectionstring(connectionstring) {
|
|
|
263
211
|
throw new types_1.SQLiteCloudError(`Invalid connection string: ${connectionstring}`);
|
|
264
212
|
}
|
|
265
213
|
}
|
|
266
|
-
exports.parseconnectionstring = parseconnectionstring;
|
|
267
214
|
/** Returns true if value is 1 or true */
|
|
268
215
|
function parseBoolean(value) {
|
|
269
216
|
if (typeof value === 'string') {
|
|
@@ -271,7 +218,6 @@ function parseBoolean(value) {
|
|
|
271
218
|
}
|
|
272
219
|
return value ? true : false;
|
|
273
220
|
}
|
|
274
|
-
exports.parseBoolean = parseBoolean;
|
|
275
221
|
/** Returns true if value is 1 or true */
|
|
276
222
|
function parseBooleanToZeroOne(value) {
|
|
277
223
|
if (typeof value === 'string') {
|
|
@@ -279,4 +225,3 @@ function parseBooleanToZeroOne(value) {
|
|
|
279
225
|
}
|
|
280
226
|
return value ? 1 : 0;
|
|
281
227
|
}
|
|
282
|
-
exports.parseBooleanToZeroOne = parseBooleanToZeroOne;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { Database } from './drivers/database';
|
|
2
|
-
export { Statement } from './drivers/statement';
|
|
3
2
|
export { SQLiteCloudConnection } from './drivers/connection';
|
|
4
3
|
export { type SQLiteCloudConfig, type SQLCloudRowsetMetadata, SQLiteCloudError, type ResultsCallback, type ErrorCallback, type SQLiteCloudDataTypes } from './drivers/types';
|
|
5
4
|
export { SQLiteCloudRowset, SQLiteCloudRow } from './drivers/rowset';
|
|
6
|
-
export {
|
|
5
|
+
export { parseconnectionstring, validateConfiguration, getInitializationCommands, sanitizeSQLiteIdentifier } from './drivers/utilities';
|
|
7
6
|
export * as protocol from './drivers/protocol';
|
package/lib/index.js
CHANGED
|
@@ -18,23 +18,31 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
18
18
|
}) : function(o, v) {
|
|
19
19
|
o["default"] = v;
|
|
20
20
|
});
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
28
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.protocol = exports.
|
|
39
|
+
exports.protocol = exports.sanitizeSQLiteIdentifier = exports.getInitializationCommands = exports.validateConfiguration = exports.parseconnectionstring = exports.SQLiteCloudRow = exports.SQLiteCloudRowset = exports.SQLiteCloudError = exports.SQLiteCloudConnection = exports.Database = void 0;
|
|
30
40
|
// include ONLY packages used by drivers
|
|
31
41
|
// do NOT include anything related to gateway or bun or express
|
|
32
42
|
// connection-tls does not want/need to load on browser and is loaded dynamically by Database
|
|
33
43
|
// connection-ws does not want/need to load on node and is loaded dynamically by Database
|
|
34
44
|
var database_1 = require("./drivers/database");
|
|
35
45
|
Object.defineProperty(exports, "Database", { enumerable: true, get: function () { return database_1.Database; } });
|
|
36
|
-
var statement_1 = require("./drivers/statement");
|
|
37
|
-
Object.defineProperty(exports, "Statement", { enumerable: true, get: function () { return statement_1.Statement; } });
|
|
38
46
|
var connection_1 = require("./drivers/connection");
|
|
39
47
|
Object.defineProperty(exports, "SQLiteCloudConnection", { enumerable: true, get: function () { return connection_1.SQLiteCloudConnection; } });
|
|
40
48
|
var types_1 = require("./drivers/types");
|
|
@@ -43,9 +51,8 @@ var rowset_1 = require("./drivers/rowset");
|
|
|
43
51
|
Object.defineProperty(exports, "SQLiteCloudRowset", { enumerable: true, get: function () { return rowset_1.SQLiteCloudRowset; } });
|
|
44
52
|
Object.defineProperty(exports, "SQLiteCloudRow", { enumerable: true, get: function () { return rowset_1.SQLiteCloudRow; } });
|
|
45
53
|
var utilities_1 = require("./drivers/utilities");
|
|
46
|
-
Object.defineProperty(exports, "escapeSqlParameter", { enumerable: true, get: function () { return utilities_1.escapeSqlParameter; } });
|
|
47
|
-
Object.defineProperty(exports, "prepareSql", { enumerable: true, get: function () { return utilities_1.prepareSql; } });
|
|
48
54
|
Object.defineProperty(exports, "parseconnectionstring", { enumerable: true, get: function () { return utilities_1.parseconnectionstring; } });
|
|
49
55
|
Object.defineProperty(exports, "validateConfiguration", { enumerable: true, get: function () { return utilities_1.validateConfiguration; } });
|
|
50
56
|
Object.defineProperty(exports, "getInitializationCommands", { enumerable: true, get: function () { return utilities_1.getInitializationCommands; } });
|
|
57
|
+
Object.defineProperty(exports, "sanitizeSQLiteIdentifier", { enumerable: true, get: function () { return utilities_1.sanitizeSQLiteIdentifier; } });
|
|
51
58
|
exports.protocol = __importStar(require("./drivers/protocol"));
|