@photostructure/sqlite 0.0.1 → 0.2.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/CHANGELOG.md +38 -2
- package/README.md +47 -483
- package/SECURITY.md +27 -83
- package/binding.gyp +69 -22
- package/dist/index.cjs +185 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +552 -100
- package/dist/index.d.mts +552 -100
- package/dist/index.d.ts +552 -100
- package/dist/index.mjs +183 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +51 -41
- package/prebuilds/darwin-arm64/@photostructure+sqlite.glibc.node +0 -0
- package/prebuilds/darwin-x64/@photostructure+sqlite.glibc.node +0 -0
- package/prebuilds/linux-arm64/@photostructure+sqlite.glibc.node +0 -0
- package/prebuilds/linux-arm64/@photostructure+sqlite.musl.node +0 -0
- package/prebuilds/linux-x64/@photostructure+sqlite.glibc.node +0 -0
- package/prebuilds/linux-x64/@photostructure+sqlite.musl.node +0 -0
- package/prebuilds/test_extension.so +0 -0
- package/prebuilds/win32-arm64/@photostructure+sqlite.glibc.node +0 -0
- package/prebuilds/win32-x64/@photostructure+sqlite.glibc.node +0 -0
- package/src/aggregate_function.cpp +503 -235
- package/src/aggregate_function.h +57 -42
- package/src/binding.cpp +117 -14
- package/src/dirname.ts +1 -1
- package/src/index.ts +122 -332
- package/src/lru-cache.ts +84 -0
- package/src/shims/env-inl.h +6 -15
- package/src/shims/node_errors.h +7 -1
- package/src/shims/sqlite_errors.h +168 -0
- package/src/shims/util.h +29 -4
- package/src/sql-tag-store.ts +140 -0
- package/src/sqlite_exception.h +49 -0
- package/src/sqlite_impl.cpp +736 -129
- package/src/sqlite_impl.h +84 -6
- package/src/{stack_path.ts → stack-path.ts} +7 -1
- package/src/types/aggregate-options.ts +22 -0
- package/src/types/changeset-apply-options.ts +18 -0
- package/src/types/database-sync-instance.ts +203 -0
- package/src/types/database-sync-options.ts +69 -0
- package/src/types/session-options.ts +10 -0
- package/src/types/sql-tag-store-instance.ts +51 -0
- package/src/types/sqlite-authorization-actions.ts +77 -0
- package/src/types/sqlite-authorization-results.ts +15 -0
- package/src/types/sqlite-changeset-conflict-types.ts +19 -0
- package/src/types/sqlite-changeset-resolution.ts +15 -0
- package/src/types/sqlite-open-flags.ts +50 -0
- package/src/types/statement-sync-instance.ts +73 -0
- package/src/types/user-functions-options.ts +14 -0
- package/src/upstream/node_sqlite.cc +960 -259
- package/src/upstream/node_sqlite.h +127 -2
- package/src/upstream/sqlite.js +1 -14
- package/src/upstream/sqlite3.c +4510 -1411
- package/src/upstream/sqlite3.h +390 -195
- package/src/upstream/sqlite3ext.h +7 -0
- package/src/user_function.cpp +88 -36
- package/src/user_function.h +2 -1
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
5
|
|
|
6
6
|
#include "base_object.h"
|
|
7
|
+
#include "lru_cache-inl.h"
|
|
7
8
|
#include "node_mem.h"
|
|
8
9
|
#include "sqlite3.h"
|
|
9
10
|
#include "util.h"
|
|
10
11
|
|
|
12
|
+
#include <list>
|
|
11
13
|
#include <map>
|
|
12
14
|
#include <unordered_set>
|
|
13
15
|
|
|
@@ -39,19 +41,86 @@ class DatabaseOpenConfiguration {
|
|
|
39
41
|
|
|
40
42
|
inline int get_timeout() { return timeout_; }
|
|
41
43
|
|
|
44
|
+
inline void set_use_big_ints(bool flag) { use_big_ints_ = flag; }
|
|
45
|
+
|
|
46
|
+
inline bool get_use_big_ints() const { return use_big_ints_; }
|
|
47
|
+
|
|
48
|
+
inline void set_return_arrays(bool flag) { return_arrays_ = flag; }
|
|
49
|
+
|
|
50
|
+
inline bool get_return_arrays() const { return return_arrays_; }
|
|
51
|
+
|
|
52
|
+
inline void set_allow_bare_named_params(bool flag) {
|
|
53
|
+
allow_bare_named_params_ = flag;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
inline bool get_allow_bare_named_params() const {
|
|
57
|
+
return allow_bare_named_params_;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
inline void set_allow_unknown_named_params(bool flag) {
|
|
61
|
+
allow_unknown_named_params_ = flag;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
inline bool get_allow_unknown_named_params() const {
|
|
65
|
+
return allow_unknown_named_params_;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
inline void set_enable_defensive(bool flag) { defensive_ = flag; }
|
|
69
|
+
|
|
70
|
+
inline bool get_enable_defensive() const { return defensive_; }
|
|
71
|
+
|
|
42
72
|
private:
|
|
43
73
|
std::string location_;
|
|
44
74
|
bool read_only_ = false;
|
|
45
75
|
bool enable_foreign_keys_ = true;
|
|
46
76
|
bool enable_dqs_ = false;
|
|
47
77
|
int timeout_ = 0;
|
|
78
|
+
bool use_big_ints_ = false;
|
|
79
|
+
bool return_arrays_ = false;
|
|
80
|
+
bool allow_bare_named_params_ = true;
|
|
81
|
+
bool allow_unknown_named_params_ = false;
|
|
82
|
+
bool defensive_ = false;
|
|
48
83
|
};
|
|
49
84
|
|
|
85
|
+
class DatabaseSync;
|
|
86
|
+
class StatementSyncIterator;
|
|
50
87
|
class StatementSync;
|
|
51
88
|
class BackupJob;
|
|
52
89
|
|
|
90
|
+
class StatementExecutionHelper {
|
|
91
|
+
public:
|
|
92
|
+
static v8::MaybeLocal<v8::Value> All(Environment* env,
|
|
93
|
+
DatabaseSync* db,
|
|
94
|
+
sqlite3_stmt* stmt,
|
|
95
|
+
bool return_arrays,
|
|
96
|
+
bool use_big_ints);
|
|
97
|
+
static v8::MaybeLocal<v8::Object> Run(Environment* env,
|
|
98
|
+
DatabaseSync* db,
|
|
99
|
+
sqlite3_stmt* stmt,
|
|
100
|
+
bool use_big_ints);
|
|
101
|
+
static BaseObjectPtr<StatementSyncIterator> Iterate(
|
|
102
|
+
Environment* env, BaseObjectPtr<StatementSync> stmt);
|
|
103
|
+
static v8::MaybeLocal<v8::Value> ColumnToValue(Environment* env,
|
|
104
|
+
sqlite3_stmt* stmt,
|
|
105
|
+
const int column,
|
|
106
|
+
bool use_big_ints);
|
|
107
|
+
static v8::MaybeLocal<v8::Name> ColumnNameToName(Environment* env,
|
|
108
|
+
sqlite3_stmt* stmt,
|
|
109
|
+
const int column);
|
|
110
|
+
static v8::MaybeLocal<v8::Value> Get(Environment* env,
|
|
111
|
+
DatabaseSync* db,
|
|
112
|
+
sqlite3_stmt* stmt,
|
|
113
|
+
bool return_arrays,
|
|
114
|
+
bool use_big_ints);
|
|
115
|
+
};
|
|
116
|
+
|
|
53
117
|
class DatabaseSync : public BaseObject {
|
|
54
118
|
public:
|
|
119
|
+
enum InternalFields {
|
|
120
|
+
kAuthorizerCallback = BaseObject::kInternalFieldCount,
|
|
121
|
+
kInternalFieldCount
|
|
122
|
+
};
|
|
123
|
+
|
|
55
124
|
DatabaseSync(Environment* env,
|
|
56
125
|
v8::Local<v8::Object> object,
|
|
57
126
|
DatabaseOpenConfiguration&& open_config,
|
|
@@ -64,8 +133,10 @@ class DatabaseSync : public BaseObject {
|
|
|
64
133
|
static void IsTransactionGetter(
|
|
65
134
|
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
66
135
|
static void Close(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
136
|
+
static void Dispose(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
67
137
|
static void Prepare(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
68
138
|
static void Exec(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
139
|
+
static void CreateTagStore(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
69
140
|
static void Location(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
70
141
|
static void CustomFunction(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
71
142
|
static void AggregateFunction(
|
|
@@ -74,13 +145,29 @@ class DatabaseSync : public BaseObject {
|
|
|
74
145
|
static void ApplyChangeset(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
75
146
|
static void EnableLoadExtension(
|
|
76
147
|
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
148
|
+
static void EnableDefensive(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
77
149
|
static void LoadExtension(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
150
|
+
static void SetAuthorizer(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
151
|
+
static int AuthorizerCallback(void* user_data,
|
|
152
|
+
int action_code,
|
|
153
|
+
const char* param1,
|
|
154
|
+
const char* param2,
|
|
155
|
+
const char* param3,
|
|
156
|
+
const char* param4);
|
|
78
157
|
void FinalizeStatements();
|
|
79
158
|
void RemoveBackup(BackupJob* backup);
|
|
80
159
|
void AddBackup(BackupJob* backup);
|
|
81
160
|
void FinalizeBackups();
|
|
82
161
|
void UntrackStatement(StatementSync* statement);
|
|
83
162
|
bool IsOpen();
|
|
163
|
+
bool use_big_ints() const { return open_config_.get_use_big_ints(); }
|
|
164
|
+
bool return_arrays() const { return open_config_.get_return_arrays(); }
|
|
165
|
+
bool allow_bare_named_params() const {
|
|
166
|
+
return open_config_.get_allow_bare_named_params();
|
|
167
|
+
}
|
|
168
|
+
bool allow_unknown_named_params() const {
|
|
169
|
+
return open_config_.get_allow_unknown_named_params();
|
|
170
|
+
}
|
|
84
171
|
sqlite3* Connection();
|
|
85
172
|
|
|
86
173
|
// In some situations, such as when using custom functions, it is possible
|
|
@@ -109,6 +196,8 @@ class DatabaseSync : public BaseObject {
|
|
|
109
196
|
std::unordered_set<StatementSync*> statements_;
|
|
110
197
|
|
|
111
198
|
friend class Session;
|
|
199
|
+
friend class SQLTagStore;
|
|
200
|
+
friend class StatementExecutionHelper;
|
|
112
201
|
};
|
|
113
202
|
|
|
114
203
|
class StatementSync : public BaseObject {
|
|
@@ -137,6 +226,8 @@ class StatementSync : public BaseObject {
|
|
|
137
226
|
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
138
227
|
static void SetReadBigInts(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
139
228
|
static void SetReturnArrays(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
229
|
+
v8::MaybeLocal<v8::Value> ColumnToValue(const int column);
|
|
230
|
+
v8::MaybeLocal<v8::Name> ColumnNameToName(const int column);
|
|
140
231
|
void Finalize();
|
|
141
232
|
bool IsFinalized();
|
|
142
233
|
|
|
@@ -154,10 +245,10 @@ class StatementSync : public BaseObject {
|
|
|
154
245
|
std::optional<std::map<std::string, std::string>> bare_named_params_;
|
|
155
246
|
bool BindParams(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
156
247
|
bool BindValue(const v8::Local<v8::Value>& value, const int index);
|
|
157
|
-
v8::MaybeLocal<v8::Value> ColumnToValue(const int column);
|
|
158
|
-
v8::MaybeLocal<v8::Name> ColumnNameToName(const int column);
|
|
159
248
|
|
|
160
249
|
friend class StatementSyncIterator;
|
|
250
|
+
friend class SQLTagStore;
|
|
251
|
+
friend class StatementExecutionHelper;
|
|
161
252
|
};
|
|
162
253
|
|
|
163
254
|
class StatementSyncIterator : public BaseObject {
|
|
@@ -194,6 +285,7 @@ class Session : public BaseObject {
|
|
|
194
285
|
template <Sqlite3ChangesetGenFunc sqliteChangesetFunc>
|
|
195
286
|
static void Changeset(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
196
287
|
static void Close(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
288
|
+
static void Dispose(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
197
289
|
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
|
|
198
290
|
Environment* env);
|
|
199
291
|
static BaseObjectPtr<Session> Create(Environment* env,
|
|
@@ -210,6 +302,39 @@ class Session : public BaseObject {
|
|
|
210
302
|
BaseObjectWeakPtr<DatabaseSync> database_; // The Parent Database
|
|
211
303
|
};
|
|
212
304
|
|
|
305
|
+
class SQLTagStore : public BaseObject {
|
|
306
|
+
public:
|
|
307
|
+
SQLTagStore(Environment* env,
|
|
308
|
+
v8::Local<v8::Object> object,
|
|
309
|
+
BaseObjectWeakPtr<DatabaseSync> database,
|
|
310
|
+
int capacity);
|
|
311
|
+
~SQLTagStore() override;
|
|
312
|
+
static BaseObjectPtr<SQLTagStore> Create(
|
|
313
|
+
Environment* env, BaseObjectWeakPtr<DatabaseSync> database, int capacity);
|
|
314
|
+
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
|
|
315
|
+
Environment* env);
|
|
316
|
+
static void All(const v8::FunctionCallbackInfo<v8::Value>& info);
|
|
317
|
+
static void Get(const v8::FunctionCallbackInfo<v8::Value>& info);
|
|
318
|
+
static void Iterate(const v8::FunctionCallbackInfo<v8::Value>& info);
|
|
319
|
+
static void Run(const v8::FunctionCallbackInfo<v8::Value>& info);
|
|
320
|
+
static void Size(const v8::FunctionCallbackInfo<v8::Value>& info);
|
|
321
|
+
static void Capacity(const v8::FunctionCallbackInfo<v8::Value>& info);
|
|
322
|
+
static void Reset(const v8::FunctionCallbackInfo<v8::Value>& info);
|
|
323
|
+
static void Clear(const v8::FunctionCallbackInfo<v8::Value>& info);
|
|
324
|
+
static void DatabaseGetter(const v8::FunctionCallbackInfo<v8::Value>& info);
|
|
325
|
+
void MemoryInfo(MemoryTracker* tracker) const override;
|
|
326
|
+
SET_MEMORY_INFO_NAME(SQLTagStore)
|
|
327
|
+
SET_SELF_SIZE(SQLTagStore)
|
|
328
|
+
|
|
329
|
+
private:
|
|
330
|
+
static BaseObjectPtr<StatementSync> PrepareStatement(
|
|
331
|
+
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
332
|
+
BaseObjectWeakPtr<DatabaseSync> database_;
|
|
333
|
+
LRUCache<std::string, BaseObjectPtr<StatementSync>> sql_tags_;
|
|
334
|
+
int capacity_;
|
|
335
|
+
friend class StatementExecutionHelper;
|
|
336
|
+
};
|
|
337
|
+
|
|
213
338
|
class UserDefinedFunction {
|
|
214
339
|
public:
|
|
215
340
|
UserDefinedFunction(Environment* env,
|
package/src/upstream/sqlite.js
CHANGED
|
@@ -1,19 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {
|
|
3
|
-
SymbolDispose,
|
|
4
|
-
} = primordials;
|
|
5
2
|
const { emitExperimentalWarning } = require('internal/util');
|
|
6
|
-
const binding = internalBinding('sqlite');
|
|
7
3
|
|
|
8
4
|
emitExperimentalWarning('SQLite');
|
|
9
5
|
|
|
10
|
-
|
|
11
|
-
binding.DatabaseSync.prototype[SymbolDispose] = function() {
|
|
12
|
-
try {
|
|
13
|
-
this.close();
|
|
14
|
-
} catch {
|
|
15
|
-
// Ignore errors.
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
module.exports = binding;
|
|
6
|
+
module.exports = internalBinding('sqlite');
|