@bullet./paraql 0.1.2 → 0.3.0
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 +39 -45
- package/binding.c +279 -119
- package/index.js +66 -28
- package/lib/codecs.js +12 -53
- package/lib/constants.js +36 -3
- package/lib/statement.d.ts +0 -11
- package/lib/statement.js +1 -27
- package/lib/vfs.js +31 -97
- package/package.json +3 -8
- package/prebuilds/android-arm/bullet.__paraql.bare +0 -0
- package/prebuilds/android-arm/bullet.__paraql.node +0 -0
- package/prebuilds/android-arm64/bullet.__paraql.bare +0 -0
- package/prebuilds/android-arm64/bullet.__paraql.node +0 -0
- package/prebuilds/android-ia32/bullet.__paraql.bare +0 -0
- package/prebuilds/android-ia32/bullet.__paraql.node +0 -0
- package/prebuilds/android-x64/bullet.__paraql.bare +0 -0
- package/prebuilds/android-x64/bullet.__paraql.node +0 -0
- package/prebuilds/darwin-arm64/bullet.__paraql.bare +0 -0
- package/prebuilds/darwin-arm64/bullet.__paraql.node +0 -0
- package/prebuilds/darwin-x64/bullet.__paraql.bare +0 -0
- package/prebuilds/darwin-x64/bullet.__paraql.node +0 -0
- package/prebuilds/ios-arm64/bullet.__paraql.bare +0 -0
- package/prebuilds/ios-arm64-simulator/bullet.__paraql.bare +0 -0
- package/prebuilds/ios-x64-simulator/bullet.__paraql.bare +0 -0
- package/prebuilds/linux-arm64/bullet.__paraql.bare +0 -0
- package/prebuilds/linux-arm64/bullet.__paraql.node +0 -0
- package/prebuilds/linux-x64/bullet.__paraql.bare +0 -0
- package/prebuilds/linux-x64/bullet.__paraql.node +0 -0
- package/prebuilds/win32-arm64/bullet.__paraql.bare +0 -0
- package/prebuilds/win32-arm64/bullet.__paraql.node +0 -0
- package/prebuilds/win32-x64/bullet.__paraql.bare +0 -0
- package/prebuilds/win32-x64/bullet.__paraql.node +0 -0
package/index.js
CHANGED
|
@@ -2,6 +2,7 @@ const { Buffer } = require("buffer")
|
|
|
2
2
|
const ReadyResource = require("ready-resource")
|
|
3
3
|
|
|
4
4
|
const binding = require("./binding")
|
|
5
|
+
const constants = require("./lib/constants")
|
|
5
6
|
const errors = require("./lib/errors")
|
|
6
7
|
const ParaQLStatement = require("./lib/statement")
|
|
7
8
|
const ParaVFS = require("./lib/vfs")
|
|
@@ -13,14 +14,15 @@ module.exports = exports = class ParaQL extends ReadyResource {
|
|
|
13
14
|
key = null
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
const {
|
|
17
|
+
const { authorize = null, ...opts } = options
|
|
17
18
|
|
|
18
19
|
super()
|
|
19
20
|
|
|
20
21
|
this._handle = null
|
|
21
22
|
this._vfs = new ParaVFS(this, store, key, opts)
|
|
22
|
-
|
|
23
|
-
this.
|
|
23
|
+
|
|
24
|
+
this._authorize = authorize
|
|
25
|
+
this._initiator = null
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
get name() {
|
|
@@ -55,7 +57,11 @@ module.exports = exports = class ParaQL extends ReadyResource {
|
|
|
55
57
|
await this._vfs.ready()
|
|
56
58
|
|
|
57
59
|
try {
|
|
58
|
-
this._handle = await binding.open(
|
|
60
|
+
this._handle = await binding.open(
|
|
61
|
+
this,
|
|
62
|
+
this.name,
|
|
63
|
+
this._authorize ? this._on_authorize : null,
|
|
64
|
+
)
|
|
59
65
|
} catch (err) {
|
|
60
66
|
throw errors.from(err)
|
|
61
67
|
}
|
|
@@ -64,11 +70,6 @@ module.exports = exports = class ParaQL extends ReadyResource {
|
|
|
64
70
|
async _close() {
|
|
65
71
|
if (this.opened) {
|
|
66
72
|
try {
|
|
67
|
-
for (const stmt of this._cache.values()) {
|
|
68
|
-
await stmt.finalize()
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
this._cache.clear()
|
|
72
73
|
await binding.close(this._handle)
|
|
73
74
|
} catch (err) {
|
|
74
75
|
throw errors.from(err)
|
|
@@ -78,6 +79,34 @@ module.exports = exports = class ParaQL extends ReadyResource {
|
|
|
78
79
|
await this._vfs.close()
|
|
79
80
|
}
|
|
80
81
|
|
|
82
|
+
async _on_authorize(action, param1, param2, param3, param4, callback) {
|
|
83
|
+
if (!this._initiator || this.key.equals(this._initiator)) return callback(true)
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
const result = await this._authorize(
|
|
87
|
+
this._initiator,
|
|
88
|
+
action,
|
|
89
|
+
param1,
|
|
90
|
+
param2,
|
|
91
|
+
param3,
|
|
92
|
+
param4,
|
|
93
|
+
)
|
|
94
|
+
callback(!!result)
|
|
95
|
+
} catch {
|
|
96
|
+
callback(false)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
static async deserialize(store, data, options) {
|
|
101
|
+
const db = new ParaQL(store, null, options)
|
|
102
|
+
|
|
103
|
+
await db.ready()
|
|
104
|
+
|
|
105
|
+
await db._vfs.deserialize(data)
|
|
106
|
+
|
|
107
|
+
return db
|
|
108
|
+
}
|
|
109
|
+
|
|
81
110
|
async addWriter(key) {
|
|
82
111
|
await this._vfs.addWriter(key)
|
|
83
112
|
}
|
|
@@ -98,11 +127,28 @@ module.exports = exports = class ParaQL extends ReadyResource {
|
|
|
98
127
|
return this._vfs.info()
|
|
99
128
|
}
|
|
100
129
|
|
|
101
|
-
async
|
|
130
|
+
async serialize() {
|
|
131
|
+
if (!this.opened) await this.ready()
|
|
132
|
+
|
|
133
|
+
if (this.closed) throw errors.ALREADY_CLOSED()
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
const data = await binding.serialize(this._handle)
|
|
137
|
+
|
|
138
|
+
return Buffer.from(data)
|
|
139
|
+
} catch (err) {
|
|
140
|
+
throw errors.from(err)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async _exec(sql, initiator) {
|
|
102
145
|
try {
|
|
146
|
+
this._initiator = initiator
|
|
103
147
|
await binding.exec(this._handle, sql)
|
|
104
148
|
} catch (err) {
|
|
105
149
|
throw errors.from(err)
|
|
150
|
+
} finally {
|
|
151
|
+
this._initiator = null
|
|
106
152
|
}
|
|
107
153
|
}
|
|
108
154
|
|
|
@@ -114,35 +160,27 @@ module.exports = exports = class ParaQL extends ReadyResource {
|
|
|
114
160
|
await this._vfs.exec(sql)
|
|
115
161
|
}
|
|
116
162
|
|
|
117
|
-
async prepare(sql) {
|
|
163
|
+
async prepare(sql, initiator = this.local) {
|
|
118
164
|
if (!this.opened) await this.ready()
|
|
119
165
|
|
|
120
166
|
if (this.closed) throw errors.ALREADY_CLOSED()
|
|
121
167
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (stmt) {
|
|
125
|
-
this._cache.delete(sql)
|
|
126
|
-
this._cache.set(sql, stmt)
|
|
127
|
-
return stmt
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
stmt = new ParaQLStatement(this, sql)
|
|
131
|
-
|
|
132
|
-
await stmt.ready()
|
|
168
|
+
this._initiator = initiator
|
|
133
169
|
|
|
134
|
-
|
|
170
|
+
try {
|
|
171
|
+
const stmt = new ParaQLStatement(this, sql)
|
|
135
172
|
|
|
136
|
-
|
|
137
|
-
const oldest = this._cache.values().next().value
|
|
173
|
+
await stmt.ready()
|
|
138
174
|
|
|
139
|
-
|
|
175
|
+
return stmt
|
|
176
|
+
} finally {
|
|
177
|
+
this._initiator = null
|
|
140
178
|
}
|
|
141
|
-
|
|
142
|
-
return stmt
|
|
143
179
|
}
|
|
144
180
|
}
|
|
145
181
|
|
|
182
|
+
exports.AUTHORIZE_ACTION = constants.AUTHORIZE_ACTION
|
|
183
|
+
|
|
146
184
|
function isObject(o) {
|
|
147
185
|
return typeof o === "object" && o && !Buffer.isBuffer(o)
|
|
148
186
|
}
|
package/lib/codecs.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const c = require("compact-encoding")
|
|
2
2
|
const IndexEncoder = require("index-encoder")
|
|
3
|
-
const zlib = require("zlib")
|
|
4
3
|
|
|
5
4
|
const { OPERATION, PAGE_SIZE } = require("./constants")
|
|
6
5
|
|
|
@@ -9,6 +8,10 @@ const op = {
|
|
|
9
8
|
c.uint8.preencode(state, operation.type)
|
|
10
9
|
|
|
11
10
|
switch (operation.type) {
|
|
11
|
+
case OPERATION.DESERIALIZE: {
|
|
12
|
+
c.buffer.preencode(state, operation.data)
|
|
13
|
+
break
|
|
14
|
+
}
|
|
12
15
|
case OPERATION.WRITER_ADD:
|
|
13
16
|
case OPERATION.WRITER_DEL: {
|
|
14
17
|
c.fixed32.preencode(state, operation.key)
|
|
@@ -24,22 +27,16 @@ const op = {
|
|
|
24
27
|
c.any.preencode(state, operation.positional)
|
|
25
28
|
break
|
|
26
29
|
}
|
|
27
|
-
case OPERATION.STMT: {
|
|
28
|
-
c.string.preencode(state, operation.sql)
|
|
29
|
-
}
|
|
30
|
-
case OPERATION.BATCH: {
|
|
31
|
-
c.any.preencode(state, operation.named)
|
|
32
|
-
c.any.preencode(state, operation.positional)
|
|
33
|
-
}
|
|
34
|
-
case OPERATION.FLUSH: {
|
|
35
|
-
break
|
|
36
|
-
}
|
|
37
30
|
}
|
|
38
31
|
},
|
|
39
32
|
encode(state, operation) {
|
|
40
33
|
c.uint8.encode(state, operation.type)
|
|
41
34
|
|
|
42
35
|
switch (operation.type) {
|
|
36
|
+
case OPERATION.DESERIALIZE: {
|
|
37
|
+
c.buffer.encode(state, operation.data)
|
|
38
|
+
break
|
|
39
|
+
}
|
|
43
40
|
case OPERATION.WRITER_ADD:
|
|
44
41
|
case OPERATION.WRITER_DEL: {
|
|
45
42
|
c.fixed32.encode(state, operation.key)
|
|
@@ -55,16 +52,6 @@ const op = {
|
|
|
55
52
|
c.any.encode(state, operation.positional)
|
|
56
53
|
break
|
|
57
54
|
}
|
|
58
|
-
case OPERATION.STMT: {
|
|
59
|
-
c.string.encode(state, operation.sql)
|
|
60
|
-
}
|
|
61
|
-
case OPERATION.BATCH: {
|
|
62
|
-
c.any.encode(state, operation.named)
|
|
63
|
-
c.any.encode(state, operation.positional)
|
|
64
|
-
}
|
|
65
|
-
case OPERATION.FLUSH: {
|
|
66
|
-
break
|
|
67
|
-
}
|
|
68
55
|
}
|
|
69
56
|
},
|
|
70
57
|
decode(state) {
|
|
@@ -73,6 +60,10 @@ const op = {
|
|
|
73
60
|
const operation = { type }
|
|
74
61
|
|
|
75
62
|
switch (type) {
|
|
63
|
+
case OPERATION.DESERIALIZE: {
|
|
64
|
+
operation.data = c.buffer.decode(state)
|
|
65
|
+
break
|
|
66
|
+
}
|
|
76
67
|
case OPERATION.WRITER_ADD:
|
|
77
68
|
case OPERATION.WRITER_DEL: {
|
|
78
69
|
operation.key = c.fixed32.decode(state)
|
|
@@ -88,16 +79,6 @@ const op = {
|
|
|
88
79
|
operation.positional = c.any.decode(state)
|
|
89
80
|
break
|
|
90
81
|
}
|
|
91
|
-
case OPERATION.STMT: {
|
|
92
|
-
operation.sql = c.string.decode(state)
|
|
93
|
-
}
|
|
94
|
-
case OPERATION.BATCH: {
|
|
95
|
-
operation.named = c.any.decode(state)
|
|
96
|
-
operation.positional = c.any.decode(state)
|
|
97
|
-
}
|
|
98
|
-
case OPERATION.FLUSH: {
|
|
99
|
-
break
|
|
100
|
-
}
|
|
101
82
|
}
|
|
102
83
|
|
|
103
84
|
return operation
|
|
@@ -114,25 +95,3 @@ module.exports.Operation = {
|
|
|
114
95
|
return c.decode(op, operation)
|
|
115
96
|
},
|
|
116
97
|
}
|
|
117
|
-
|
|
118
|
-
module.exports.deflate = async function (buffer, options) {
|
|
119
|
-
return new Promise((resolve, reject) =>
|
|
120
|
-
zlib.deflate(buffer, { chunkSize: PAGE_SIZE, ...options }, (err, result) => {
|
|
121
|
-
if (err) {
|
|
122
|
-
return reject(result)
|
|
123
|
-
}
|
|
124
|
-
resolve(result)
|
|
125
|
-
}),
|
|
126
|
-
)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
module.exports.inflate = async function (buffer, options) {
|
|
130
|
-
return new Promise((resolve, reject) =>
|
|
131
|
-
zlib.inflate(buffer, { chunkSize: PAGE_SIZE, ...options }, (err, result) => {
|
|
132
|
-
if (err) {
|
|
133
|
-
return reject(result)
|
|
134
|
-
}
|
|
135
|
-
resolve(result)
|
|
136
|
-
}),
|
|
137
|
-
)
|
|
138
|
-
}
|
package/lib/constants.js
CHANGED
|
@@ -1,10 +1,43 @@
|
|
|
1
1
|
module.exports.PAGE_SIZE = 4096
|
|
2
2
|
module.exports.OPERATION = {
|
|
3
|
+
DESERIALIZE: 0,
|
|
3
4
|
WRITER_ADD: 1,
|
|
4
5
|
WRITER_DEL: 2,
|
|
5
6
|
EXEC: 8,
|
|
6
7
|
RUN: 9,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
}
|
|
9
|
+
module.exports.AUTHORIZE_ACTION = {
|
|
10
|
+
CREATE_INDEX: 1,
|
|
11
|
+
CREATE_TABLE: 2,
|
|
12
|
+
CREATE_TEMP_INDEX: 3,
|
|
13
|
+
CREATE_TEMP_TABLE: 4,
|
|
14
|
+
CREATE_TEMP_TRIGGER: 5,
|
|
15
|
+
CREATE_TEMP_VIEW: 6,
|
|
16
|
+
CREATE_TRIGGER: 7,
|
|
17
|
+
CREATE_VIEW: 8,
|
|
18
|
+
DELETE: 9,
|
|
19
|
+
DROP_INDEX: 10,
|
|
20
|
+
DROP_TABLE: 11,
|
|
21
|
+
DROP_TEMP_INDEX: 12,
|
|
22
|
+
DROP_TEMP_TABLE: 13,
|
|
23
|
+
DROP_TEMP_TRIGGER: 14,
|
|
24
|
+
DROP_TEMP_VIEW: 15,
|
|
25
|
+
DROP_TRIGGER: 16,
|
|
26
|
+
DROP_VIEW: 17,
|
|
27
|
+
INSERT: 18,
|
|
28
|
+
PRAGMA: 19,
|
|
29
|
+
READ: 20,
|
|
30
|
+
SELECT: 21,
|
|
31
|
+
TRANSACTION: 22,
|
|
32
|
+
UPDATE: 23,
|
|
33
|
+
ATTACH: 24,
|
|
34
|
+
DETACH: 25,
|
|
35
|
+
ALTER_TABLE: 26,
|
|
36
|
+
REINDEX: 27,
|
|
37
|
+
ANALYZE: 28,
|
|
38
|
+
CREATE_VTABLE: 29,
|
|
39
|
+
DROP_VTABLE: 30,
|
|
40
|
+
FUNCTION: 31,
|
|
41
|
+
SAVEPOINT: 32,
|
|
42
|
+
RECURSIVE: 33,
|
|
10
43
|
}
|
package/lib/statement.d.ts
CHANGED
|
@@ -3,11 +3,6 @@ import Buffer from "bare-buffer"
|
|
|
3
3
|
|
|
4
4
|
interface ParaQLStatement extends ReadyResource {
|
|
5
5
|
readonly sourceSQL: string
|
|
6
|
-
readonly batching: boolean
|
|
7
|
-
|
|
8
|
-
batch(on: boolean): void
|
|
9
|
-
|
|
10
|
-
flush(): Promise<ParaQLStatement.FlushResult>
|
|
11
6
|
|
|
12
7
|
finalize(): Promise<void>
|
|
13
8
|
|
|
@@ -44,12 +39,6 @@ declare namespace ParaQLStatement {
|
|
|
44
39
|
changes: number
|
|
45
40
|
lastInsertRowid: number
|
|
46
41
|
}
|
|
47
|
-
|
|
48
|
-
export interface FlushResult {
|
|
49
|
-
changes: number
|
|
50
|
-
lastInsertRowid: number
|
|
51
|
-
errors: number
|
|
52
|
-
}
|
|
53
42
|
}
|
|
54
43
|
|
|
55
44
|
export = ParaQLStatement
|
package/lib/statement.js
CHANGED
|
@@ -11,7 +11,6 @@ module.exports = class ParaQLStatement extends ReadyResource {
|
|
|
11
11
|
this._db = db
|
|
12
12
|
this._sourceSQL = sql
|
|
13
13
|
this._handle = null
|
|
14
|
-
this._queue = null
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
async _open() {
|
|
@@ -27,8 +26,6 @@ module.exports = class ParaQLStatement extends ReadyResource {
|
|
|
27
26
|
try {
|
|
28
27
|
await binding.finalize(this._handle)
|
|
29
28
|
this._handle = null
|
|
30
|
-
this._queue = null
|
|
31
|
-
this._db._cache.delete(this._sourceSQL)
|
|
32
29
|
} catch (err) {
|
|
33
30
|
throw errors.from(err)
|
|
34
31
|
}
|
|
@@ -39,28 +36,10 @@ module.exports = class ParaQLStatement extends ReadyResource {
|
|
|
39
36
|
return this._sourceSQL
|
|
40
37
|
}
|
|
41
38
|
|
|
42
|
-
get batching() {
|
|
43
|
-
return !!this._queue
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
batch(on) {
|
|
47
|
-
if (on === false) {
|
|
48
|
-
this._queue = null
|
|
49
|
-
} else {
|
|
50
|
-
this._queue = this._queue ?? []
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
39
|
async finalize() {
|
|
55
40
|
await this.close()
|
|
56
41
|
}
|
|
57
42
|
|
|
58
|
-
async flush() {
|
|
59
|
-
const queue = this._queue
|
|
60
|
-
this._queue = []
|
|
61
|
-
return this._db._vfs.flush(this._sourceSQL, queue)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
43
|
async _bind(named, positional) {
|
|
65
44
|
for (const key in named) {
|
|
66
45
|
if (Array.isArray(named[key])) named[key] = JSON.stringify(named[key])
|
|
@@ -117,12 +96,7 @@ module.exports = class ParaQLStatement extends ReadyResource {
|
|
|
117
96
|
|
|
118
97
|
const [named, positional] = splitParameters(params)
|
|
119
98
|
|
|
120
|
-
|
|
121
|
-
this._queue.push({ named, positional })
|
|
122
|
-
return null
|
|
123
|
-
} else {
|
|
124
|
-
return this._db._vfs.run(this._sourceSQL, named, positional)
|
|
125
|
-
}
|
|
99
|
+
return this._db._vfs.run(this._sourceSQL, named, positional)
|
|
126
100
|
}
|
|
127
101
|
|
|
128
102
|
async *iterate(...params) {
|
package/lib/vfs.js
CHANGED
|
@@ -6,7 +6,7 @@ const ReadyResource = require("ready-resource")
|
|
|
6
6
|
const RocksDB = require("rocksdb-native")
|
|
7
7
|
|
|
8
8
|
const binding = require("../binding")
|
|
9
|
-
const { PageKey, Operation
|
|
9
|
+
const { PageKey, Operation } = require("./codecs")
|
|
10
10
|
const { OPERATION, PAGE_SIZE } = require("./constants")
|
|
11
11
|
const Deferred = require("./deferred")
|
|
12
12
|
const Encryption = require("./encryption")
|
|
@@ -19,8 +19,6 @@ module.exports = class ParaVFS extends ReadyResource {
|
|
|
19
19
|
keyPair = null,
|
|
20
20
|
encrypted = false,
|
|
21
21
|
encryptionKey = null,
|
|
22
|
-
compressed = false,
|
|
23
|
-
compressionLevel = 6,
|
|
24
22
|
} = options
|
|
25
23
|
|
|
26
24
|
super()
|
|
@@ -30,8 +28,6 @@ module.exports = class ParaVFS extends ReadyResource {
|
|
|
30
28
|
this._name = name
|
|
31
29
|
|
|
32
30
|
this._encryption = null
|
|
33
|
-
this._compressed = compressed
|
|
34
|
-
this._compressionLevel = compressionLevel
|
|
35
31
|
|
|
36
32
|
this.store = store.namespace(name)
|
|
37
33
|
this.bee = new Autobee(this.store, key, {
|
|
@@ -76,10 +72,6 @@ module.exports = class ParaVFS extends ReadyResource {
|
|
|
76
72
|
return !!this._encryption
|
|
77
73
|
}
|
|
78
74
|
|
|
79
|
-
get compressed() {
|
|
80
|
-
return !!this._compressed
|
|
81
|
-
}
|
|
82
|
-
|
|
83
75
|
async _open() {
|
|
84
76
|
await this.bee.ready()
|
|
85
77
|
|
|
@@ -113,15 +105,22 @@ module.exports = class ParaVFS extends ReadyResource {
|
|
|
113
105
|
}
|
|
114
106
|
|
|
115
107
|
async _apply(nodes, view, host) {
|
|
116
|
-
let stmt = null
|
|
117
|
-
let changes = 0
|
|
118
|
-
let lastInsertRowid = 0
|
|
119
|
-
let errors = 0
|
|
120
|
-
|
|
121
108
|
for (const node of nodes) {
|
|
122
|
-
const op = Operation.decode(
|
|
109
|
+
const op = Operation.decode(node.value)
|
|
123
110
|
|
|
124
111
|
switch (op.type) {
|
|
112
|
+
case OPERATION.DESERIALIZE: {
|
|
113
|
+
this._write(view)
|
|
114
|
+
try {
|
|
115
|
+
await this._xWrite(this.name, op.data, 0, () => {})
|
|
116
|
+
await this._flush(this.name)
|
|
117
|
+
this._interactive?.resolve()
|
|
118
|
+
} catch (err) {
|
|
119
|
+
this._interactive?.reject(err)
|
|
120
|
+
}
|
|
121
|
+
this._write(null)
|
|
122
|
+
break
|
|
123
|
+
}
|
|
125
124
|
case OPERATION.WRITER_ADD: {
|
|
126
125
|
const batch = view.write()
|
|
127
126
|
host.addWriter(op.key)
|
|
@@ -137,7 +136,7 @@ module.exports = class ParaVFS extends ReadyResource {
|
|
|
137
136
|
case OPERATION.EXEC: {
|
|
138
137
|
this._write(view)
|
|
139
138
|
try {
|
|
140
|
-
await this._db._exec(op.sql)
|
|
139
|
+
await this._db._exec(op.sql, node.key)
|
|
141
140
|
this._interactive?.resolve()
|
|
142
141
|
} catch (err) {
|
|
143
142
|
this._interactive?.reject(err)
|
|
@@ -147,39 +146,19 @@ module.exports = class ParaVFS extends ReadyResource {
|
|
|
147
146
|
}
|
|
148
147
|
case OPERATION.RUN: {
|
|
149
148
|
this._write(view)
|
|
149
|
+
let stmt = null
|
|
150
150
|
try {
|
|
151
|
-
stmt = await this._db.prepare(op.sql)
|
|
151
|
+
stmt = await this._db.prepare(op.sql, node.key)
|
|
152
152
|
const result = await stmt._run(op.named, op.positional)
|
|
153
153
|
this._interactive?.resolve(result)
|
|
154
154
|
} catch (err) {
|
|
155
155
|
this._interactive?.reject(err)
|
|
156
|
+
} finally {
|
|
157
|
+
await stmt?.finalize()
|
|
156
158
|
}
|
|
157
159
|
this._write(null)
|
|
158
160
|
break
|
|
159
161
|
}
|
|
160
|
-
case OPERATION.STMT: {
|
|
161
|
-
try {
|
|
162
|
-
stmt = await this._db.prepare(op.sql)
|
|
163
|
-
} catch (err) {
|
|
164
|
-
throw errors.INTERNAL(`Received invalid statement: ${op.sql}`)
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
case OPERATION.BATCH: {
|
|
168
|
-
this._write(view)
|
|
169
|
-
try {
|
|
170
|
-
const result = await stmt._run(op.named, op.positional)
|
|
171
|
-
changes += result.changes
|
|
172
|
-
lastInsertRowid = result.lastInsertRowid
|
|
173
|
-
} catch (err) {
|
|
174
|
-
errors++
|
|
175
|
-
}
|
|
176
|
-
this._write(null)
|
|
177
|
-
break
|
|
178
|
-
}
|
|
179
|
-
case OPERATION.FLUSH: {
|
|
180
|
-
this._interactive?.resolve({ changes, lastInsertRowid, errors })
|
|
181
|
-
break
|
|
182
|
-
}
|
|
183
162
|
}
|
|
184
163
|
}
|
|
185
164
|
}
|
|
@@ -193,23 +172,11 @@ module.exports = class ParaVFS extends ReadyResource {
|
|
|
193
172
|
}
|
|
194
173
|
|
|
195
174
|
async addWriter(key) {
|
|
196
|
-
await this.bee.append(
|
|
197
|
-
this.compressed
|
|
198
|
-
? await deflate(Operation.encode({ type: OPERATION.WRITER_ADD, key }), {
|
|
199
|
-
level: this._compressionLevel,
|
|
200
|
-
})
|
|
201
|
-
: Operation.encode({ type: OPERATION.WRITER_ADD, key }),
|
|
202
|
-
)
|
|
175
|
+
await this.bee.append(Operation.encode({ type: OPERATION.WRITER_ADD, key }))
|
|
203
176
|
}
|
|
204
177
|
|
|
205
178
|
async removeWriter(key) {
|
|
206
|
-
await this.bee.append(
|
|
207
|
-
this.compressed
|
|
208
|
-
? await deflate(Operation.encode({ type: OPERATION.WRITER_DEL, key }), {
|
|
209
|
-
level: this._compressionLevel,
|
|
210
|
-
})
|
|
211
|
-
: Operation.encode({ type: OPERATION.WRITER_DEL, key }),
|
|
212
|
-
)
|
|
179
|
+
await this.bee.append(Operation.encode({ type: OPERATION.WRITER_DEL, key }))
|
|
213
180
|
}
|
|
214
181
|
|
|
215
182
|
replicate(isInitiator) {
|
|
@@ -249,17 +216,13 @@ module.exports = class ParaVFS extends ReadyResource {
|
|
|
249
216
|
return { database, temporary, total: database + temporary }
|
|
250
217
|
}
|
|
251
218
|
|
|
252
|
-
async
|
|
219
|
+
async deserialize(data) {
|
|
253
220
|
this._interactive = new Deferred()
|
|
254
221
|
try {
|
|
255
|
-
const promise = this.bee.append(
|
|
256
|
-
|
|
257
|
-
? await deflate(Operation.encode({ type: OPERATION.EXEC, sql }), {
|
|
258
|
-
level: this._compressionLevel,
|
|
259
|
-
})
|
|
260
|
-
: Operation.encode({ type: OPERATION.EXEC, sql }),
|
|
222
|
+
const promise = await this.bee.append(
|
|
223
|
+
Operation.encode({ type: OPERATION.DESERIALIZE, data }),
|
|
261
224
|
)
|
|
262
|
-
await this._interactive.promise
|
|
225
|
+
return await this._interactive.promise
|
|
263
226
|
.then(() => promise)
|
|
264
227
|
.catch(async (err) => {
|
|
265
228
|
await promise
|
|
@@ -270,21 +233,12 @@ module.exports = class ParaVFS extends ReadyResource {
|
|
|
270
233
|
}
|
|
271
234
|
}
|
|
272
235
|
|
|
273
|
-
async
|
|
236
|
+
async exec(sql) {
|
|
274
237
|
this._interactive = new Deferred()
|
|
275
238
|
try {
|
|
276
|
-
const promise = this.bee.append(
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
level: this._compressionLevel,
|
|
280
|
-
})
|
|
281
|
-
: Operation.encode({ type: OPERATION.RUN, sql, named, positional }),
|
|
282
|
-
)
|
|
283
|
-
return await this._interactive.promise
|
|
284
|
-
.then(async (result) => {
|
|
285
|
-
await promise
|
|
286
|
-
return result
|
|
287
|
-
})
|
|
239
|
+
const promise = this.bee.append(Operation.encode({ type: OPERATION.EXEC, sql }))
|
|
240
|
+
await this._interactive.promise
|
|
241
|
+
.then(() => promise)
|
|
288
242
|
.catch(async (err) => {
|
|
289
243
|
await promise
|
|
290
244
|
throw err
|
|
@@ -294,23 +248,11 @@ module.exports = class ParaVFS extends ReadyResource {
|
|
|
294
248
|
}
|
|
295
249
|
}
|
|
296
250
|
|
|
297
|
-
async
|
|
251
|
+
async run(sql, named, positional) {
|
|
298
252
|
this._interactive = new Deferred()
|
|
299
253
|
try {
|
|
300
254
|
const promise = this.bee.append(
|
|
301
|
-
|
|
302
|
-
? await Promise.all(
|
|
303
|
-
[
|
|
304
|
-
{ type: OPERATION.STMT, sql },
|
|
305
|
-
...operations.map((op) => ({ type: OPERATION.BATCH, ...op })),
|
|
306
|
-
{ type: OPERATION.FLUSH },
|
|
307
|
-
].map((op) => deflate(Operation.encode(op), { level: this._compressionLevel })),
|
|
308
|
-
)
|
|
309
|
-
: [
|
|
310
|
-
{ type: OPERATION.STMT, sql },
|
|
311
|
-
...operations.map((op) => ({ type: OPERATION.BATCH, ...op })),
|
|
312
|
-
{ type: OPERATION.FLUSH },
|
|
313
|
-
].map(Operation.encode),
|
|
255
|
+
Operation.encode({ type: OPERATION.RUN, sql, named, positional }),
|
|
314
256
|
)
|
|
315
257
|
return await this._interactive.promise
|
|
316
258
|
.then(async (result) => {
|
|
@@ -343,10 +285,6 @@ module.exports = class ParaVFS extends ReadyResource {
|
|
|
343
285
|
value = entry?.value ?? null
|
|
344
286
|
}
|
|
345
287
|
|
|
346
|
-
if (value && this.compressed) {
|
|
347
|
-
value = await inflate(value)
|
|
348
|
-
}
|
|
349
|
-
|
|
350
288
|
return value
|
|
351
289
|
}
|
|
352
290
|
|
|
@@ -374,10 +312,6 @@ module.exports = class ParaVFS extends ReadyResource {
|
|
|
374
312
|
|
|
375
313
|
this._files.set(name, batch)
|
|
376
314
|
|
|
377
|
-
if (this.compressed) {
|
|
378
|
-
value = await deflate(value, { level: this._compressionLevel })
|
|
379
|
-
}
|
|
380
|
-
|
|
381
315
|
if (tmp && this.encrypted) {
|
|
382
316
|
value = this._encryption.encrypt(value, name, index)
|
|
383
317
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bullet./paraql",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Fast, parallel, multi-writer relational database with SQL syntax. Native support for encryption, compression, and vector search.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Tomas Ravinskas",
|
|
7
7
|
"email": "tomas@tomasrav.me",
|
|
@@ -49,10 +49,6 @@
|
|
|
49
49
|
"path": {
|
|
50
50
|
"bare": "bare-path",
|
|
51
51
|
"default": "path"
|
|
52
|
-
},
|
|
53
|
-
"zlib": {
|
|
54
|
-
"bare": "bare-zlib",
|
|
55
|
-
"default": "zlib"
|
|
56
52
|
}
|
|
57
53
|
},
|
|
58
54
|
"homepage": "https://github.com/getbullet-app/paraql",
|
|
@@ -72,11 +68,10 @@
|
|
|
72
68
|
"vector-search"
|
|
73
69
|
],
|
|
74
70
|
"dependencies": {
|
|
75
|
-
"autobee": "^
|
|
71
|
+
"autobee": "^2.7.2",
|
|
76
72
|
"bare-buffer": "^3.6.2",
|
|
77
73
|
"bare-fs": "^4.7.4",
|
|
78
74
|
"bare-path": "^3.1.1",
|
|
79
|
-
"bare-zlib": "^1.4.1",
|
|
80
75
|
"compact-encoding": "^3.3.0",
|
|
81
76
|
"index-encoder": "^3.5.0",
|
|
82
77
|
"ready-resource": "^1.2.0",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|