@photostructure/sqlite 0.0.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 +43 -0
- package/LICENSE +21 -0
- package/README.md +522 -0
- package/SECURITY.md +114 -0
- package/binding.gyp +94 -0
- package/dist/index.cjs +134 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +408 -0
- package/dist/index.d.mts +408 -0
- package/dist/index.d.ts +408 -0
- package/dist/index.mjs +103 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +144 -0
- package/prebuilds/darwin-arm64/@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/win32-x64/@photostructure+sqlite.glibc.node +0 -0
- package/scripts/post-build.mjs +21 -0
- package/scripts/prebuild-linux-glibc.sh +108 -0
- package/src/aggregate_function.cpp +417 -0
- package/src/aggregate_function.h +116 -0
- package/src/binding.cpp +160 -0
- package/src/dirname.ts +13 -0
- package/src/index.ts +465 -0
- package/src/shims/base_object-inl.h +8 -0
- package/src/shims/base_object.h +50 -0
- package/src/shims/debug_utils-inl.h +23 -0
- package/src/shims/env-inl.h +19 -0
- package/src/shims/memory_tracker-inl.h +17 -0
- package/src/shims/napi_extensions.h +73 -0
- package/src/shims/node.h +16 -0
- package/src/shims/node_errors.h +66 -0
- package/src/shims/node_mem-inl.h +8 -0
- package/src/shims/node_mem.h +31 -0
- package/src/shims/node_url.h +23 -0
- package/src/shims/promise_resolver.h +31 -0
- package/src/shims/util-inl.h +18 -0
- package/src/shims/util.h +101 -0
- package/src/sqlite_impl.cpp +2440 -0
- package/src/sqlite_impl.h +314 -0
- package/src/stack_path.ts +64 -0
- package/src/types/node-gyp-build.d.ts +4 -0
- package/src/upstream/node_sqlite.cc +2706 -0
- package/src/upstream/node_sqlite.h +234 -0
- package/src/upstream/sqlite.gyp +38 -0
- package/src/upstream/sqlite.js +19 -0
- package/src/upstream/sqlite3.c +262809 -0
- package/src/upstream/sqlite3.h +13773 -0
- package/src/upstream/sqlite3ext.h +723 -0
- package/src/user_function.cpp +225 -0
- package/src/user_function.h +40 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
#ifndef SRC_NODE_SQLITE_H_
|
|
2
|
+
#define SRC_NODE_SQLITE_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "base_object.h"
|
|
7
|
+
#include "node_mem.h"
|
|
8
|
+
#include "sqlite3.h"
|
|
9
|
+
#include "util.h"
|
|
10
|
+
|
|
11
|
+
#include <map>
|
|
12
|
+
#include <unordered_set>
|
|
13
|
+
|
|
14
|
+
namespace node {
|
|
15
|
+
namespace sqlite {
|
|
16
|
+
|
|
17
|
+
class DatabaseOpenConfiguration {
|
|
18
|
+
public:
|
|
19
|
+
explicit DatabaseOpenConfiguration(std::string&& location)
|
|
20
|
+
: location_(std::move(location)) {}
|
|
21
|
+
|
|
22
|
+
inline const std::string& location() const { return location_; }
|
|
23
|
+
|
|
24
|
+
inline bool get_read_only() const { return read_only_; }
|
|
25
|
+
|
|
26
|
+
inline void set_read_only(bool flag) { read_only_ = flag; }
|
|
27
|
+
|
|
28
|
+
inline bool get_enable_foreign_keys() const { return enable_foreign_keys_; }
|
|
29
|
+
|
|
30
|
+
inline void set_enable_foreign_keys(bool flag) {
|
|
31
|
+
enable_foreign_keys_ = flag;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
inline bool get_enable_dqs() const { return enable_dqs_; }
|
|
35
|
+
|
|
36
|
+
inline void set_enable_dqs(bool flag) { enable_dqs_ = flag; }
|
|
37
|
+
|
|
38
|
+
inline void set_timeout(int timeout) { timeout_ = timeout; }
|
|
39
|
+
|
|
40
|
+
inline int get_timeout() { return timeout_; }
|
|
41
|
+
|
|
42
|
+
private:
|
|
43
|
+
std::string location_;
|
|
44
|
+
bool read_only_ = false;
|
|
45
|
+
bool enable_foreign_keys_ = true;
|
|
46
|
+
bool enable_dqs_ = false;
|
|
47
|
+
int timeout_ = 0;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
class StatementSync;
|
|
51
|
+
class BackupJob;
|
|
52
|
+
|
|
53
|
+
class DatabaseSync : public BaseObject {
|
|
54
|
+
public:
|
|
55
|
+
DatabaseSync(Environment* env,
|
|
56
|
+
v8::Local<v8::Object> object,
|
|
57
|
+
DatabaseOpenConfiguration&& open_config,
|
|
58
|
+
bool open,
|
|
59
|
+
bool allow_load_extension);
|
|
60
|
+
void MemoryInfo(MemoryTracker* tracker) const override;
|
|
61
|
+
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
62
|
+
static void Open(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
63
|
+
static void IsOpenGetter(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
64
|
+
static void IsTransactionGetter(
|
|
65
|
+
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
66
|
+
static void Close(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
67
|
+
static void Prepare(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
68
|
+
static void Exec(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
69
|
+
static void Location(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
70
|
+
static void CustomFunction(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
71
|
+
static void AggregateFunction(
|
|
72
|
+
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
73
|
+
static void CreateSession(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
74
|
+
static void ApplyChangeset(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
75
|
+
static void EnableLoadExtension(
|
|
76
|
+
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
77
|
+
static void LoadExtension(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
78
|
+
void FinalizeStatements();
|
|
79
|
+
void RemoveBackup(BackupJob* backup);
|
|
80
|
+
void AddBackup(BackupJob* backup);
|
|
81
|
+
void FinalizeBackups();
|
|
82
|
+
void UntrackStatement(StatementSync* statement);
|
|
83
|
+
bool IsOpen();
|
|
84
|
+
sqlite3* Connection();
|
|
85
|
+
|
|
86
|
+
// In some situations, such as when using custom functions, it is possible
|
|
87
|
+
// that SQLite reports an error while JavaScript already has a pending
|
|
88
|
+
// exception. In this case, the SQLite error should be ignored. These methods
|
|
89
|
+
// enable that use case.
|
|
90
|
+
void SetIgnoreNextSQLiteError(bool ignore);
|
|
91
|
+
bool ShouldIgnoreSQLiteError();
|
|
92
|
+
|
|
93
|
+
SET_MEMORY_INFO_NAME(DatabaseSync)
|
|
94
|
+
SET_SELF_SIZE(DatabaseSync)
|
|
95
|
+
|
|
96
|
+
private:
|
|
97
|
+
bool Open();
|
|
98
|
+
void DeleteSessions();
|
|
99
|
+
|
|
100
|
+
~DatabaseSync() override;
|
|
101
|
+
DatabaseOpenConfiguration open_config_;
|
|
102
|
+
bool allow_load_extension_;
|
|
103
|
+
bool enable_load_extension_;
|
|
104
|
+
sqlite3* connection_;
|
|
105
|
+
bool ignore_next_sqlite_error_;
|
|
106
|
+
|
|
107
|
+
std::set<BackupJob*> backups_;
|
|
108
|
+
std::set<sqlite3_session*> sessions_;
|
|
109
|
+
std::unordered_set<StatementSync*> statements_;
|
|
110
|
+
|
|
111
|
+
friend class Session;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
class StatementSync : public BaseObject {
|
|
115
|
+
public:
|
|
116
|
+
StatementSync(Environment* env,
|
|
117
|
+
v8::Local<v8::Object> object,
|
|
118
|
+
BaseObjectPtr<DatabaseSync> db,
|
|
119
|
+
sqlite3_stmt* stmt);
|
|
120
|
+
void MemoryInfo(MemoryTracker* tracker) const override;
|
|
121
|
+
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
|
|
122
|
+
Environment* env);
|
|
123
|
+
static BaseObjectPtr<StatementSync> Create(Environment* env,
|
|
124
|
+
BaseObjectPtr<DatabaseSync> db,
|
|
125
|
+
sqlite3_stmt* stmt);
|
|
126
|
+
static void All(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
127
|
+
static void Iterate(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
128
|
+
static void Get(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
129
|
+
static void Run(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
130
|
+
static void Columns(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
131
|
+
static void SourceSQLGetter(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
132
|
+
static void ExpandedSQLGetter(
|
|
133
|
+
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
134
|
+
static void SetAllowBareNamedParameters(
|
|
135
|
+
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
136
|
+
static void SetAllowUnknownNamedParameters(
|
|
137
|
+
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
138
|
+
static void SetReadBigInts(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
139
|
+
static void SetReturnArrays(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
140
|
+
void Finalize();
|
|
141
|
+
bool IsFinalized();
|
|
142
|
+
|
|
143
|
+
SET_MEMORY_INFO_NAME(StatementSync)
|
|
144
|
+
SET_SELF_SIZE(StatementSync)
|
|
145
|
+
|
|
146
|
+
private:
|
|
147
|
+
~StatementSync() override;
|
|
148
|
+
BaseObjectPtr<DatabaseSync> db_;
|
|
149
|
+
sqlite3_stmt* statement_;
|
|
150
|
+
bool return_arrays_ = false;
|
|
151
|
+
bool use_big_ints_;
|
|
152
|
+
bool allow_bare_named_params_;
|
|
153
|
+
bool allow_unknown_named_params_;
|
|
154
|
+
std::optional<std::map<std::string, std::string>> bare_named_params_;
|
|
155
|
+
bool BindParams(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
156
|
+
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
|
+
|
|
160
|
+
friend class StatementSyncIterator;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
class StatementSyncIterator : public BaseObject {
|
|
164
|
+
public:
|
|
165
|
+
StatementSyncIterator(Environment* env,
|
|
166
|
+
v8::Local<v8::Object> object,
|
|
167
|
+
BaseObjectPtr<StatementSync> stmt);
|
|
168
|
+
void MemoryInfo(MemoryTracker* tracker) const override;
|
|
169
|
+
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
|
|
170
|
+
Environment* env);
|
|
171
|
+
static BaseObjectPtr<StatementSyncIterator> Create(
|
|
172
|
+
Environment* env, BaseObjectPtr<StatementSync> stmt);
|
|
173
|
+
static void Next(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
174
|
+
static void Return(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
175
|
+
|
|
176
|
+
SET_MEMORY_INFO_NAME(StatementSyncIterator)
|
|
177
|
+
SET_SELF_SIZE(StatementSyncIterator)
|
|
178
|
+
|
|
179
|
+
private:
|
|
180
|
+
~StatementSyncIterator() override;
|
|
181
|
+
BaseObjectPtr<StatementSync> stmt_;
|
|
182
|
+
bool done_;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
using Sqlite3ChangesetGenFunc = int (*)(sqlite3_session*, int*, void**);
|
|
186
|
+
|
|
187
|
+
class Session : public BaseObject {
|
|
188
|
+
public:
|
|
189
|
+
Session(Environment* env,
|
|
190
|
+
v8::Local<v8::Object> object,
|
|
191
|
+
BaseObjectWeakPtr<DatabaseSync> database,
|
|
192
|
+
sqlite3_session* session);
|
|
193
|
+
~Session() override;
|
|
194
|
+
template <Sqlite3ChangesetGenFunc sqliteChangesetFunc>
|
|
195
|
+
static void Changeset(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
196
|
+
static void Close(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
197
|
+
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
|
|
198
|
+
Environment* env);
|
|
199
|
+
static BaseObjectPtr<Session> Create(Environment* env,
|
|
200
|
+
BaseObjectWeakPtr<DatabaseSync> database,
|
|
201
|
+
sqlite3_session* session);
|
|
202
|
+
|
|
203
|
+
void MemoryInfo(MemoryTracker* tracker) const override;
|
|
204
|
+
SET_MEMORY_INFO_NAME(Session)
|
|
205
|
+
SET_SELF_SIZE(Session)
|
|
206
|
+
|
|
207
|
+
private:
|
|
208
|
+
void Delete();
|
|
209
|
+
sqlite3_session* session_;
|
|
210
|
+
BaseObjectWeakPtr<DatabaseSync> database_; // The Parent Database
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
class UserDefinedFunction {
|
|
214
|
+
public:
|
|
215
|
+
UserDefinedFunction(Environment* env,
|
|
216
|
+
v8::Local<v8::Function> fn,
|
|
217
|
+
DatabaseSync* db,
|
|
218
|
+
bool use_bigint_args);
|
|
219
|
+
~UserDefinedFunction();
|
|
220
|
+
static void xFunc(sqlite3_context* ctx, int argc, sqlite3_value** argv);
|
|
221
|
+
static void xDestroy(void* self);
|
|
222
|
+
|
|
223
|
+
private:
|
|
224
|
+
Environment* env_;
|
|
225
|
+
v8::Global<v8::Function> fn_;
|
|
226
|
+
DatabaseSync* db_;
|
|
227
|
+
bool use_bigint_args_;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
} // namespace sqlite
|
|
231
|
+
} // namespace node
|
|
232
|
+
|
|
233
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
234
|
+
#endif // SRC_NODE_SQLITE_H_
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
'variables': {
|
|
3
|
+
'sqlite_sources': [
|
|
4
|
+
'sqlite3.c',
|
|
5
|
+
],
|
|
6
|
+
},
|
|
7
|
+
'targets': [
|
|
8
|
+
{
|
|
9
|
+
'target_name': 'sqlite',
|
|
10
|
+
'type': 'static_library',
|
|
11
|
+
'cflags': ['-fvisibility=hidden'],
|
|
12
|
+
'xcode_settings': {
|
|
13
|
+
'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden
|
|
14
|
+
},
|
|
15
|
+
'defines': [
|
|
16
|
+
'SQLITE_DEFAULT_MEMSTATUS=0',
|
|
17
|
+
'SQLITE_ENABLE_COLUMN_METADATA',
|
|
18
|
+
'SQLITE_ENABLE_DBSTAT_VTAB',
|
|
19
|
+
'SQLITE_ENABLE_FTS3',
|
|
20
|
+
'SQLITE_ENABLE_FTS3_PARENTHESIS',
|
|
21
|
+
'SQLITE_ENABLE_FTS5',
|
|
22
|
+
'SQLITE_ENABLE_GEOPOLY',
|
|
23
|
+
'SQLITE_ENABLE_MATH_FUNCTIONS',
|
|
24
|
+
'SQLITE_ENABLE_PREUPDATE_HOOK',
|
|
25
|
+
'SQLITE_ENABLE_RBU',
|
|
26
|
+
'SQLITE_ENABLE_RTREE',
|
|
27
|
+
'SQLITE_ENABLE_SESSION',
|
|
28
|
+
],
|
|
29
|
+
'include_dirs': ['.'],
|
|
30
|
+
'sources': [
|
|
31
|
+
'<@(sqlite_sources)',
|
|
32
|
+
],
|
|
33
|
+
'direct_dependent_settings': {
|
|
34
|
+
'include_dirs': ['.'],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const {
|
|
3
|
+
SymbolDispose,
|
|
4
|
+
} = primordials;
|
|
5
|
+
const { emitExperimentalWarning } = require('internal/util');
|
|
6
|
+
const binding = internalBinding('sqlite');
|
|
7
|
+
|
|
8
|
+
emitExperimentalWarning('SQLite');
|
|
9
|
+
|
|
10
|
+
// TODO(cjihrig): Move this to C++ once Symbol.dispose reaches Stage 4.
|
|
11
|
+
binding.DatabaseSync.prototype[SymbolDispose] = function() {
|
|
12
|
+
try {
|
|
13
|
+
this.close();
|
|
14
|
+
} catch {
|
|
15
|
+
// Ignore errors.
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
module.exports = binding;
|