@sqlitecloud/drivers 1.0.245 → 1.0.256-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -0
- package/lib/drivers/connection-tls.js +15 -6
- package/lib/drivers/protocol.js +7 -5
- package/lib/drivers/utilities.js +4 -2
- package/lib/sqlitecloud.drivers.dev.js +35 -3
- package/lib/sqlitecloud.drivers.js +2 -1
- package/lib/sqlitecloud.drivers.js.LICENSE.txt +8 -0
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -12,6 +12,38 @@
|
|
|
12
12
|
npm install @sqlitecloud/drivers
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
## React Native / Expo Install
|
|
16
|
+
|
|
17
|
+
You also have to install Peer Dependencies
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @sqlitecloud/drivers react-native-tcp-socket react-native-fast-base64
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
React Native run IOS
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
cd ios && pod install && cd .. && npm run ios
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
React Native run Android (without ./ in Windows)
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
cd android && ./gradlew clean build && cd .. && npm run android
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Expo run IOS
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npx expo prebuild && npx expo run:ios
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Expo run Android
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npx expo prebuild && npx expo run:android
|
|
45
|
+
```
|
|
46
|
+
|
|
15
47
|
## Usage
|
|
16
48
|
|
|
17
49
|
```ts
|
|
@@ -60,6 +92,10 @@ Pub/Sub is a messaging pattern that allows multiple applications to communicate
|
|
|
60
92
|
|
|
61
93
|
Pub/Sub Documentation: [https://docs.sqlitecloud.io/docs/pub-sub](https://docs.sqlitecloud.io/docs/pub-sub)
|
|
62
94
|
|
|
95
|
+
## Examples
|
|
96
|
+
|
|
97
|
+
Check out all the supported platforms with related examples [here](https://github.com/sqlitecloud/sqlitecloud-js/tree/main/examples)!
|
|
98
|
+
|
|
63
99
|
## More
|
|
64
100
|
|
|
65
101
|
How do I deploy SQLite in the cloud?
|
|
@@ -31,6 +31,8 @@ const types_1 = require("./types");
|
|
|
31
31
|
const connection_1 = require("./connection");
|
|
32
32
|
const utilities_1 = require("./utilities");
|
|
33
33
|
const protocol_1 = require("./protocol");
|
|
34
|
+
// explicitly importing buffer library to allow cross-platform support by replacing it
|
|
35
|
+
const buffer_1 = require("buffer");
|
|
34
36
|
const tls = __importStar(require("tls"));
|
|
35
37
|
/**
|
|
36
38
|
* Implementation of SQLiteCloudConnection that connects to the database using specific tls APIs
|
|
@@ -43,7 +45,7 @@ class SQLiteCloudTlsConnection extends connection_1.SQLiteCloudConnection {
|
|
|
43
45
|
// onData is called when data is received, it will process the data until all data is retrieved for a response
|
|
44
46
|
// when response is complete or there's an error, finish is called to call the results callback set by processCommands...
|
|
45
47
|
// buffer to accumulate incoming data until an whole command is received and can be parsed
|
|
46
|
-
this.buffer = Buffer.alloc(0);
|
|
48
|
+
this.buffer = buffer_1.Buffer.alloc(0);
|
|
47
49
|
this.startedOn = new Date();
|
|
48
50
|
this.pendingChunks = [];
|
|
49
51
|
}
|
|
@@ -71,7 +73,14 @@ class SQLiteCloudTlsConnection extends connection_1.SQLiteCloudConnection {
|
|
|
71
73
|
// https://r2.nodejs.org/docs/v6.11.4/api/tls.html#tls_class_tls_tlssocket
|
|
72
74
|
servername: config.host
|
|
73
75
|
};
|
|
74
|
-
|
|
76
|
+
// tls.connect in the react-native-tcp-socket library is tls.connectTLS
|
|
77
|
+
let connector = tls.connect;
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
if (typeof tls.connectTLS !== 'undefined') {
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
connector = tls.connectTLS;
|
|
82
|
+
}
|
|
83
|
+
this.socket = connector(connectionOptions, () => {
|
|
75
84
|
var _a;
|
|
76
85
|
if (this.config.verbose) {
|
|
77
86
|
console.debug(`SQLiteCloudTlsConnection - connected to ${this.config.host}, authorized: ${(_a = this.socket) === null || _a === void 0 ? void 0 : _a.authorized}`);
|
|
@@ -110,7 +119,7 @@ class SQLiteCloudTlsConnection extends connection_1.SQLiteCloudConnection {
|
|
|
110
119
|
return this;
|
|
111
120
|
}
|
|
112
121
|
// reset buffer and rowset chunks, define response callback
|
|
113
|
-
this.buffer = Buffer.alloc(0);
|
|
122
|
+
this.buffer = buffer_1.Buffer.alloc(0);
|
|
114
123
|
this.startedOn = new Date();
|
|
115
124
|
this.processCallback = callback;
|
|
116
125
|
this.executingCommands = commands;
|
|
@@ -143,7 +152,7 @@ class SQLiteCloudTlsConnection extends connection_1.SQLiteCloudConnection {
|
|
|
143
152
|
// append data to buffer as it arrives
|
|
144
153
|
if (data.length && data.length > 0) {
|
|
145
154
|
// console.debug(`processCommandsData - received ${data.length} bytes`)
|
|
146
|
-
this.buffer = Buffer.concat([this.buffer, data]);
|
|
155
|
+
this.buffer = buffer_1.Buffer.concat([this.buffer, data]);
|
|
147
156
|
}
|
|
148
157
|
let dataType = (_a = this.buffer) === null || _a === void 0 ? void 0 : _a.subarray(0, 1).toString();
|
|
149
158
|
if ((0, protocol_1.hasCommandLength)(dataType)) {
|
|
@@ -164,7 +173,7 @@ class SQLiteCloudTlsConnection extends connection_1.SQLiteCloudConnection {
|
|
|
164
173
|
if (decompressResults.dataType === protocol_1.CMD_ROWSET_CHUNK) {
|
|
165
174
|
this.pendingChunks.push(decompressResults.buffer);
|
|
166
175
|
this.buffer = decompressResults.remainingBuffer;
|
|
167
|
-
this.processCommandsData(Buffer.alloc(0));
|
|
176
|
+
this.processCommandsData(buffer_1.Buffer.alloc(0));
|
|
168
177
|
return;
|
|
169
178
|
}
|
|
170
179
|
else {
|
|
@@ -217,7 +226,7 @@ class SQLiteCloudTlsConnection extends connection_1.SQLiteCloudConnection {
|
|
|
217
226
|
if (this.processCallback) {
|
|
218
227
|
this.processCallback(error, result);
|
|
219
228
|
}
|
|
220
|
-
this.buffer = Buffer.alloc(0);
|
|
229
|
+
this.buffer = buffer_1.Buffer.alloc(0);
|
|
221
230
|
this.pendingChunks = [];
|
|
222
231
|
}
|
|
223
232
|
/** Disconnect immediately, release connection, no events. */
|
package/lib/drivers/protocol.js
CHANGED
|
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.formatCommand = exports.popData = exports.parseRowsetChunks = exports.bufferEndsWith = exports.bufferStartsWith = exports.parseRowsetHeader = exports.parseArray = exports.parseError = exports.decompressBuffer = exports.parseCommandLength = exports.hasCommandLength = exports.ROWSET_CHUNKS_END = exports.CMD_PUBSUB = exports.CMD_ARRAY = exports.CMD_COMMAND = exports.CMD_COMPRESSED = exports.CMD_BLOB = exports.CMD_NULL = exports.CMD_JSON = exports.CMD_ROWSET_CHUNK = exports.CMD_ROWSET = exports.CMD_FLOAT = exports.CMD_INT = exports.CMD_ERROR = exports.CMD_ZEROSTRING = exports.CMD_STRING = void 0;
|
|
7
7
|
const types_1 = require("./types");
|
|
8
8
|
const rowset_1 = require("./rowset");
|
|
9
|
+
// explicitly importing buffer library to allow cross-platform support by replacing it
|
|
10
|
+
const buffer_1 = require("buffer");
|
|
9
11
|
// https://www.npmjs.com/package/lz4js
|
|
10
12
|
const lz4 = require('lz4js');
|
|
11
13
|
// The server communicates with clients via commands defined in
|
|
@@ -59,13 +61,13 @@ function decompressBuffer(buffer) {
|
|
|
59
61
|
commandBuffer = commandBuffer.subarray(commandBuffer.indexOf(' ') + 1);
|
|
60
62
|
// extract compressed dataType
|
|
61
63
|
const dataType = commandBuffer.subarray(0, 1).toString('utf8');
|
|
62
|
-
let decompressedBuffer = Buffer.alloc(decompressedSize);
|
|
64
|
+
let decompressedBuffer = buffer_1.Buffer.alloc(decompressedSize);
|
|
63
65
|
const compressedBuffer = commandBuffer.subarray(commandBuffer.length - compressedSize);
|
|
64
66
|
// lz4js library is javascript and doesn't have types so we silence the type check
|
|
65
67
|
// eslint-disable-next-line
|
|
66
68
|
const decompressionResult = lz4.decompressBlock(compressedBuffer, decompressedBuffer, 0, compressedSize, 0);
|
|
67
69
|
// the entire command is composed of the header (which is not compressed) + the decompressed block
|
|
68
|
-
decompressedBuffer = Buffer.concat([commandBuffer.subarray(0, commandBuffer.length - compressedSize), decompressedBuffer]);
|
|
70
|
+
decompressedBuffer = buffer_1.Buffer.concat([commandBuffer.subarray(0, commandBuffer.length - compressedSize), decompressedBuffer]);
|
|
69
71
|
if (decompressionResult <= 0 || decompressionResult !== decompressedSize) {
|
|
70
72
|
throw new Error(`lz4 decompression error at offset ${decompressionResult}`);
|
|
71
73
|
}
|
|
@@ -195,7 +197,7 @@ exports.bufferEndsWith = bufferEndsWith;
|
|
|
195
197
|
* @see https://github.com/sqlitecloud/sdk/blob/master/PROTOCOL.md#scsp-rowset-chunk
|
|
196
198
|
*/
|
|
197
199
|
function parseRowsetChunks(buffers) {
|
|
198
|
-
let buffer = Buffer.concat(buffers);
|
|
200
|
+
let buffer = buffer_1.Buffer.concat(buffers);
|
|
199
201
|
if (!bufferStartsWith(buffer, exports.CMD_ROWSET_CHUNK) || !bufferEndsWith(buffer, exports.ROWSET_CHUNKS_END)) {
|
|
200
202
|
throw new Error('SQLiteCloudConnection.parseRowsetChunks - invalid chunks buffer');
|
|
201
203
|
}
|
|
@@ -248,7 +250,7 @@ function popData(buffer) {
|
|
|
248
250
|
return { data, fwdBuffer };
|
|
249
251
|
}
|
|
250
252
|
// first character is the data type
|
|
251
|
-
console.assert(buffer && buffer instanceof Buffer);
|
|
253
|
+
console.assert(buffer && buffer instanceof buffer_1.Buffer);
|
|
252
254
|
let dataType = buffer.subarray(0, 1).toString('utf8');
|
|
253
255
|
if (dataType == exports.CMD_COMPRESSED)
|
|
254
256
|
throw new Error('Compressed data should be decompressed before parsing');
|
|
@@ -301,7 +303,7 @@ function popData(buffer) {
|
|
|
301
303
|
exports.popData = popData;
|
|
302
304
|
/** Format a command to be sent via SCSP protocol */
|
|
303
305
|
function formatCommand(command) {
|
|
304
|
-
const commandLength = Buffer.byteLength(command, 'utf-8');
|
|
306
|
+
const commandLength = buffer_1.Buffer.byteLength(command, 'utf-8');
|
|
305
307
|
return `+${commandLength} ${command}`;
|
|
306
308
|
}
|
|
307
309
|
exports.formatCommand = formatCommand;
|
package/lib/drivers/utilities.js
CHANGED
|
@@ -6,7 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.parseBooleanToZeroOne = exports.parseBoolean = exports.parseconnectionstring = exports.validateConfiguration = exports.popCallback = exports.getUpdateResults = exports.prepareSql = exports.escapeSqlParameter = exports.getInitializationCommands = exports.anonimizeError = exports.anonimizeCommand = exports.isNode = exports.isBrowser = void 0;
|
|
7
7
|
const types_1 = require("./types");
|
|
8
8
|
const types_2 = require("./types");
|
|
9
|
+
// explicitly importing these libraries to allow cross-platform support by replacing them
|
|
9
10
|
const whatwg_url_1 = require("whatwg-url");
|
|
11
|
+
const buffer_1 = require("buffer");
|
|
10
12
|
//
|
|
11
13
|
// determining running environment, thanks to browser-or-node
|
|
12
14
|
// https://www.npmjs.com/package/browser-or-node
|
|
@@ -94,7 +96,7 @@ function escapeSqlParameter(param) {
|
|
|
94
96
|
return param ? '1' : '0';
|
|
95
97
|
}
|
|
96
98
|
// serialize buffer as X'...' hex encoded string
|
|
97
|
-
if (Buffer.isBuffer(param)) {
|
|
99
|
+
if (buffer_1.Buffer.isBuffer(param)) {
|
|
98
100
|
return `X'${param.toString('hex')}'`;
|
|
99
101
|
}
|
|
100
102
|
if (typeof param === 'object') {
|
|
@@ -118,7 +120,7 @@ function prepareSql(sql, ...params) {
|
|
|
118
120
|
const index = matchIndex ? parseInt(matchIndex) : parameterIndex;
|
|
119
121
|
parameterIndex++;
|
|
120
122
|
let sqlParameter;
|
|
121
|
-
if (params[0] && typeof params[0] === 'object' && !(params[0] instanceof Buffer)) {
|
|
123
|
+
if (params[0] && typeof params[0] === 'object' && !(params[0] instanceof buffer_1.Buffer)) {
|
|
122
124
|
sqlParameter = params[0][index];
|
|
123
125
|
}
|
|
124
126
|
if (!sqlParameter) {
|