@tursodatabase/sync-react-native 0.5.0-pre.4
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 +117 -0
- package/android/CMakeLists.txt +53 -0
- package/android/build.gradle +84 -0
- package/android/cpp-adapter.cpp +49 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/turso/sync/reactnative/TursoBridge.java +44 -0
- package/android/src/main/java/com/turso/sync/reactnative/TursoModule.java +82 -0
- package/android/src/main/java/com/turso/sync/reactnative/TursoPackage.java +29 -0
- package/cpp/TursoConnectionHostObject.cpp +179 -0
- package/cpp/TursoConnectionHostObject.h +52 -0
- package/cpp/TursoDatabaseHostObject.cpp +98 -0
- package/cpp/TursoDatabaseHostObject.h +49 -0
- package/cpp/TursoHostObject.cpp +561 -0
- package/cpp/TursoHostObject.h +24 -0
- package/cpp/TursoStatementHostObject.cpp +414 -0
- package/cpp/TursoStatementHostObject.h +65 -0
- package/cpp/TursoSyncChangesHostObject.cpp +41 -0
- package/cpp/TursoSyncChangesHostObject.h +52 -0
- package/cpp/TursoSyncDatabaseHostObject.cpp +328 -0
- package/cpp/TursoSyncDatabaseHostObject.h +61 -0
- package/cpp/TursoSyncIoItemHostObject.cpp +304 -0
- package/cpp/TursoSyncIoItemHostObject.h +52 -0
- package/cpp/TursoSyncOperationHostObject.cpp +168 -0
- package/cpp/TursoSyncOperationHostObject.h +53 -0
- package/ios/TursoModule.h +8 -0
- package/ios/TursoModule.mm +95 -0
- package/lib/commonjs/Database.js +445 -0
- package/lib/commonjs/Database.js.map +1 -0
- package/lib/commonjs/Statement.js +339 -0
- package/lib/commonjs/Statement.js.map +1 -0
- package/lib/commonjs/index.js +229 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/internal/asyncOperation.js +124 -0
- package/lib/commonjs/internal/asyncOperation.js.map +1 -0
- package/lib/commonjs/internal/ioProcessor.js +315 -0
- package/lib/commonjs/internal/ioProcessor.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/types.js +133 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/Database.js +441 -0
- package/lib/module/Database.js.map +1 -0
- package/lib/module/Statement.js +335 -0
- package/lib/module/Statement.js.map +1 -0
- package/lib/module/index.js +205 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/internal/asyncOperation.js +116 -0
- package/lib/module/internal/asyncOperation.js.map +1 -0
- package/lib/module/internal/ioProcessor.js +309 -0
- package/lib/module/internal/ioProcessor.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +163 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/Database.d.ts +140 -0
- package/lib/typescript/Database.d.ts.map +1 -0
- package/lib/typescript/Statement.d.ts +105 -0
- package/lib/typescript/Statement.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +175 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/internal/asyncOperation.d.ts +39 -0
- package/lib/typescript/internal/asyncOperation.d.ts.map +1 -0
- package/lib/typescript/internal/ioProcessor.d.ts +48 -0
- package/lib/typescript/internal/ioProcessor.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +316 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/package.json +97 -0
- package/src/Database.ts +480 -0
- package/src/Statement.ts +372 -0
- package/src/index.ts +240 -0
- package/src/internal/asyncOperation.ts +147 -0
- package/src/internal/ioProcessor.ts +328 -0
- package/src/types.ts +391 -0
- package/turso-sync-react-native.podspec +56 -0
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
#include "TursoStatementHostObject.h"
|
|
2
|
+
|
|
3
|
+
extern "C" {
|
|
4
|
+
#include <turso.h>
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
namespace turso {
|
|
8
|
+
|
|
9
|
+
TursoStatementHostObject::~TursoStatementHostObject() {
|
|
10
|
+
if (stmt_) {
|
|
11
|
+
turso_statement_deinit(stmt_);
|
|
12
|
+
stmt_ = nullptr;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
void TursoStatementHostObject::throwError(jsi::Runtime &rt, const char *error) {
|
|
17
|
+
throw jsi::JSError(rt, error ? error : "Unknown error");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
jsi::Value TursoStatementHostObject::get(jsi::Runtime &rt, const jsi::PropNameID &name) {
|
|
21
|
+
auto propName = name.utf8(rt);
|
|
22
|
+
|
|
23
|
+
if (propName == "bindPositionalNull") {
|
|
24
|
+
return jsi::Function::createFromHostFunction(rt, name, 1,
|
|
25
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
26
|
+
return this->bindPositionalNull(rt, args, count);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (propName == "bindPositionalInt") {
|
|
30
|
+
return jsi::Function::createFromHostFunction(rt, name, 2,
|
|
31
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
32
|
+
return this->bindPositionalInt(rt, args, count);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (propName == "bindPositionalDouble") {
|
|
36
|
+
return jsi::Function::createFromHostFunction(rt, name, 2,
|
|
37
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
38
|
+
return this->bindPositionalDouble(rt, args, count);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (propName == "bindPositionalBlob") {
|
|
42
|
+
return jsi::Function::createFromHostFunction(rt, name, 2,
|
|
43
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
44
|
+
return this->bindPositionalBlob(rt, args, count);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (propName == "bindPositionalText") {
|
|
48
|
+
return jsi::Function::createFromHostFunction(rt, name, 2,
|
|
49
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
50
|
+
return this->bindPositionalText(rt, args, count);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if (propName == "execute") {
|
|
54
|
+
return jsi::Function::createFromHostFunction(rt, name, 0,
|
|
55
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *, size_t) -> jsi::Value {
|
|
56
|
+
return this->execute(rt);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (propName == "step") {
|
|
60
|
+
return jsi::Function::createFromHostFunction(rt, name, 0,
|
|
61
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *, size_t) -> jsi::Value {
|
|
62
|
+
return this->step(rt);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (propName == "runIo") {
|
|
66
|
+
return jsi::Function::createFromHostFunction(rt, name, 0,
|
|
67
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *, size_t) -> jsi::Value {
|
|
68
|
+
return this->runIo(rt);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (propName == "reset") {
|
|
72
|
+
return jsi::Function::createFromHostFunction(rt, name, 0,
|
|
73
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *, size_t) -> jsi::Value {
|
|
74
|
+
return this->reset(rt);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (propName == "finalize") {
|
|
78
|
+
return jsi::Function::createFromHostFunction(rt, name, 0,
|
|
79
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *, size_t) -> jsi::Value {
|
|
80
|
+
return this->finalize(rt);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (propName == "nChange") {
|
|
84
|
+
return jsi::Function::createFromHostFunction(rt, name, 0,
|
|
85
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *, size_t) -> jsi::Value {
|
|
86
|
+
return this->nChange(rt);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (propName == "columnCount") {
|
|
90
|
+
return jsi::Function::createFromHostFunction(rt, name, 0,
|
|
91
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *, size_t) -> jsi::Value {
|
|
92
|
+
return this->columnCount(rt);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (propName == "columnName") {
|
|
96
|
+
return jsi::Function::createFromHostFunction(rt, name, 1,
|
|
97
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
98
|
+
return this->columnName(rt, args, count);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (propName == "rowValueKind") {
|
|
102
|
+
return jsi::Function::createFromHostFunction(rt, name, 1,
|
|
103
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
104
|
+
return this->rowValueKind(rt, args, count);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (propName == "rowValueBytesCount") {
|
|
108
|
+
return jsi::Function::createFromHostFunction(rt, name, 1,
|
|
109
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
110
|
+
return this->rowValueBytesCount(rt, args, count);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
if (propName == "rowValueBytesPtr") {
|
|
114
|
+
return jsi::Function::createFromHostFunction(rt, name, 1,
|
|
115
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
116
|
+
return this->rowValueBytesPtr(rt, args, count);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (propName == "rowValueText") {
|
|
120
|
+
return jsi::Function::createFromHostFunction(rt, name, 1,
|
|
121
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
122
|
+
return this->rowValueText(rt, args, count);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
if (propName == "rowValueInt") {
|
|
126
|
+
return jsi::Function::createFromHostFunction(rt, name, 1,
|
|
127
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
128
|
+
return this->rowValueInt(rt, args, count);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
if (propName == "rowValueDouble") {
|
|
132
|
+
return jsi::Function::createFromHostFunction(rt, name, 1,
|
|
133
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
134
|
+
return this->rowValueDouble(rt, args, count);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (propName == "namedPosition") {
|
|
138
|
+
return jsi::Function::createFromHostFunction(rt, name, 1,
|
|
139
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
140
|
+
return this->namedPosition(rt, args, count);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
if (propName == "parametersCount") {
|
|
144
|
+
return jsi::Function::createFromHostFunction(rt, name, 0,
|
|
145
|
+
[this](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *, size_t) -> jsi::Value {
|
|
146
|
+
return this->parametersCount(rt);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return jsi::Value::undefined();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
void TursoStatementHostObject::set(jsi::Runtime &rt, const jsi::PropNameID &name, const jsi::Value &value) {
|
|
154
|
+
// Read-only object
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
std::vector<jsi::PropNameID> TursoStatementHostObject::getPropertyNames(jsi::Runtime &rt) {
|
|
158
|
+
std::vector<jsi::PropNameID> props;
|
|
159
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "bindPositionalNull"));
|
|
160
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "bindPositionalInt"));
|
|
161
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "bindPositionalDouble"));
|
|
162
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "bindPositionalBlob"));
|
|
163
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "bindPositionalText"));
|
|
164
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "execute"));
|
|
165
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "step"));
|
|
166
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "runIo"));
|
|
167
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "reset"));
|
|
168
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "finalize"));
|
|
169
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "nChange"));
|
|
170
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "columnCount"));
|
|
171
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "columnName"));
|
|
172
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "rowValueKind"));
|
|
173
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "rowValueBytesCount"));
|
|
174
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "rowValueBytesPtr"));
|
|
175
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "rowValueText"));
|
|
176
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "rowValueInt"));
|
|
177
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "rowValueDouble"));
|
|
178
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "namedPosition"));
|
|
179
|
+
props.emplace_back(jsi::PropNameID::forAscii(rt, "parametersCount"));
|
|
180
|
+
return props;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// 1:1 C API mapping - NO logic, just calls through to C API
|
|
184
|
+
|
|
185
|
+
jsi::Value TursoStatementHostObject::bindPositionalNull(jsi::Runtime &rt, const jsi::Value *args, size_t count) {
|
|
186
|
+
if (count < 1 || !args[0].isNumber()) {
|
|
187
|
+
throw jsi::JSError(rt, "bindPositionalNull: expected number argument (position)");
|
|
188
|
+
}
|
|
189
|
+
size_t position = static_cast<size_t>(args[0].asNumber());
|
|
190
|
+
turso_status_code_t status = turso_statement_bind_positional_null(stmt_, position);
|
|
191
|
+
return jsi::Value(static_cast<int>(status));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
jsi::Value TursoStatementHostObject::bindPositionalInt(jsi::Runtime &rt, const jsi::Value *args, size_t count) {
|
|
195
|
+
if (count < 2 || !args[0].isNumber() || !args[1].isNumber()) {
|
|
196
|
+
throw jsi::JSError(rt, "bindPositionalInt: expected two number arguments (position, value)");
|
|
197
|
+
}
|
|
198
|
+
size_t position = static_cast<size_t>(args[0].asNumber());
|
|
199
|
+
int64_t value = static_cast<int64_t>(args[1].asNumber());
|
|
200
|
+
turso_status_code_t status = turso_statement_bind_positional_int(stmt_, position, value);
|
|
201
|
+
return jsi::Value(static_cast<int>(status));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
jsi::Value TursoStatementHostObject::bindPositionalDouble(jsi::Runtime &rt, const jsi::Value *args, size_t count) {
|
|
205
|
+
if (count < 2 || !args[0].isNumber() || !args[1].isNumber()) {
|
|
206
|
+
throw jsi::JSError(rt, "bindPositionalDouble: expected two number arguments (position, value)");
|
|
207
|
+
}
|
|
208
|
+
size_t position = static_cast<size_t>(args[0].asNumber());
|
|
209
|
+
double value = args[1].asNumber();
|
|
210
|
+
turso_status_code_t status = turso_statement_bind_positional_double(stmt_, position, value);
|
|
211
|
+
return jsi::Value(static_cast<int>(status));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
jsi::Value TursoStatementHostObject::bindPositionalBlob(jsi::Runtime &rt, const jsi::Value *args, size_t count) {
|
|
215
|
+
if (count < 2 || !args[0].isNumber() || !args[1].isObject()) {
|
|
216
|
+
throw jsi::JSError(rt, "bindPositionalBlob: expected number and ArrayBuffer arguments");
|
|
217
|
+
}
|
|
218
|
+
size_t position = static_cast<size_t>(args[0].asNumber());
|
|
219
|
+
|
|
220
|
+
// Get ArrayBuffer
|
|
221
|
+
auto arrayBuffer = args[1].asObject(rt).getArrayBuffer(rt);
|
|
222
|
+
const char* data = reinterpret_cast<const char*>(arrayBuffer.data(rt));
|
|
223
|
+
size_t len = arrayBuffer.size(rt);
|
|
224
|
+
|
|
225
|
+
turso_status_code_t status = turso_statement_bind_positional_blob(stmt_, position, data, len);
|
|
226
|
+
return jsi::Value(static_cast<int>(status));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
jsi::Value TursoStatementHostObject::bindPositionalText(jsi::Runtime &rt, const jsi::Value *args, size_t count) {
|
|
230
|
+
if (count < 2 || !args[0].isNumber() || !args[1].isString()) {
|
|
231
|
+
throw jsi::JSError(rt, "bindPositionalText: expected number and string arguments");
|
|
232
|
+
}
|
|
233
|
+
size_t position = static_cast<size_t>(args[0].asNumber());
|
|
234
|
+
std::string value = args[1].asString(rt).utf8(rt);
|
|
235
|
+
turso_status_code_t status = turso_statement_bind_positional_text(stmt_, position, value.c_str(), value.length());
|
|
236
|
+
return jsi::Value(static_cast<int>(status));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
jsi::Value TursoStatementHostObject::execute(jsi::Runtime &rt) {
|
|
240
|
+
uint64_t rows_changed = 0;
|
|
241
|
+
const char* error = nullptr;
|
|
242
|
+
turso_status_code_t status = turso_statement_execute(stmt_, &rows_changed, &error);
|
|
243
|
+
|
|
244
|
+
if (status != TURSO_OK && status != TURSO_DONE && status != TURSO_IO) {
|
|
245
|
+
throwError(rt, error);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Return object with status and rows_changed
|
|
249
|
+
jsi::Object result(rt);
|
|
250
|
+
result.setProperty(rt, "status", jsi::Value(static_cast<int>(status)));
|
|
251
|
+
result.setProperty(rt, "rowsChanged", jsi::Value(static_cast<double>(rows_changed)));
|
|
252
|
+
return result;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
jsi::Value TursoStatementHostObject::step(jsi::Runtime &rt) {
|
|
256
|
+
const char* error = nullptr;
|
|
257
|
+
turso_status_code_t status = turso_statement_step(stmt_, &error);
|
|
258
|
+
|
|
259
|
+
if (status != TURSO_OK && status != TURSO_DONE && status != TURSO_ROW && status != TURSO_IO) {
|
|
260
|
+
throwError(rt, error);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return jsi::Value(static_cast<int>(status));
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
jsi::Value TursoStatementHostObject::runIo(jsi::Runtime &rt) {
|
|
267
|
+
const char* error = nullptr;
|
|
268
|
+
turso_status_code_t status = turso_statement_run_io(stmt_, &error);
|
|
269
|
+
|
|
270
|
+
if (status != TURSO_OK) {
|
|
271
|
+
throwError(rt, error);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return jsi::Value(static_cast<int>(status));
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
jsi::Value TursoStatementHostObject::reset(jsi::Runtime &rt) {
|
|
278
|
+
const char* error = nullptr;
|
|
279
|
+
turso_status_code_t status = turso_statement_reset(stmt_, &error);
|
|
280
|
+
|
|
281
|
+
if (status != TURSO_OK) {
|
|
282
|
+
throwError(rt, error);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return jsi::Value::undefined();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
jsi::Value TursoStatementHostObject::finalize(jsi::Runtime &rt) {
|
|
289
|
+
const char* error = nullptr;
|
|
290
|
+
turso_status_code_t status = turso_statement_finalize(stmt_, &error);
|
|
291
|
+
|
|
292
|
+
if (status != TURSO_DONE && status != TURSO_IO) {
|
|
293
|
+
throwError(rt, error);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return jsi::Value(static_cast<int>(status));
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
jsi::Value TursoStatementHostObject::nChange(jsi::Runtime &rt) {
|
|
300
|
+
int64_t n = turso_statement_n_change(stmt_);
|
|
301
|
+
return jsi::Value(static_cast<double>(n));
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
jsi::Value TursoStatementHostObject::columnCount(jsi::Runtime &rt) {
|
|
305
|
+
int64_t count = turso_statement_column_count(stmt_);
|
|
306
|
+
return jsi::Value(static_cast<double>(count));
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
jsi::Value TursoStatementHostObject::columnName(jsi::Runtime &rt, const jsi::Value *args, size_t count) {
|
|
310
|
+
if (count < 1 || !args[0].isNumber()) {
|
|
311
|
+
throw jsi::JSError(rt, "columnName: expected number argument (index)");
|
|
312
|
+
}
|
|
313
|
+
size_t index = static_cast<size_t>(args[0].asNumber());
|
|
314
|
+
const char* name = turso_statement_column_name(stmt_, index);
|
|
315
|
+
|
|
316
|
+
if (!name) {
|
|
317
|
+
return jsi::Value::null();
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
std::string nameStr(name);
|
|
321
|
+
turso_str_deinit(name); // Free the C string
|
|
322
|
+
|
|
323
|
+
return jsi::String::createFromUtf8(rt, nameStr);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
jsi::Value TursoStatementHostObject::rowValueKind(jsi::Runtime &rt, const jsi::Value *args, size_t count) {
|
|
327
|
+
if (count < 1 || !args[0].isNumber()) {
|
|
328
|
+
throw jsi::JSError(rt, "rowValueKind: expected number argument (index)");
|
|
329
|
+
}
|
|
330
|
+
size_t index = static_cast<size_t>(args[0].asNumber());
|
|
331
|
+
turso_type_t kind = turso_statement_row_value_kind(stmt_, index);
|
|
332
|
+
return jsi::Value(static_cast<int>(kind));
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
jsi::Value TursoStatementHostObject::rowValueBytesCount(jsi::Runtime &rt, const jsi::Value *args, size_t count) {
|
|
336
|
+
if (count < 1 || !args[0].isNumber()) {
|
|
337
|
+
throw jsi::JSError(rt, "rowValueBytesCount: expected number argument (index)");
|
|
338
|
+
}
|
|
339
|
+
size_t index = static_cast<size_t>(args[0].asNumber());
|
|
340
|
+
int64_t bytes = turso_statement_row_value_bytes_count(stmt_, index);
|
|
341
|
+
return jsi::Value(static_cast<double>(bytes));
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
jsi::Value TursoStatementHostObject::rowValueBytesPtr(jsi::Runtime &rt, const jsi::Value *args, size_t count) {
|
|
345
|
+
if (count < 1 || !args[0].isNumber()) {
|
|
346
|
+
throw jsi::JSError(rt, "rowValueBytesPtr: expected number argument (index)");
|
|
347
|
+
}
|
|
348
|
+
size_t index = static_cast<size_t>(args[0].asNumber());
|
|
349
|
+
const char* ptr = turso_statement_row_value_bytes_ptr(stmt_, index);
|
|
350
|
+
int64_t bytes = turso_statement_row_value_bytes_count(stmt_, index);
|
|
351
|
+
|
|
352
|
+
if (!ptr || bytes <= 0) {
|
|
353
|
+
return jsi::Value::null();
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Create ArrayBuffer and copy data
|
|
357
|
+
jsi::Function arrayBufferCtor = rt.global().getPropertyAsFunction(rt, "ArrayBuffer");
|
|
358
|
+
jsi::Object arrayBuffer = arrayBufferCtor.callAsConstructor(rt, static_cast<int>(bytes)).asObject(rt);
|
|
359
|
+
jsi::ArrayBuffer buf = arrayBuffer.getArrayBuffer(rt);
|
|
360
|
+
memcpy(buf.data(rt), ptr, bytes);
|
|
361
|
+
|
|
362
|
+
return arrayBuffer;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
jsi::Value TursoStatementHostObject::rowValueText(jsi::Runtime &rt, const jsi::Value *args, size_t count) {
|
|
366
|
+
if (count < 1 || !args[0].isNumber()) {
|
|
367
|
+
throw jsi::JSError(rt, "rowValueText: expected number argument (index)");
|
|
368
|
+
}
|
|
369
|
+
size_t index = static_cast<size_t>(args[0].asNumber());
|
|
370
|
+
const char* ptr = turso_statement_row_value_bytes_ptr(stmt_, index);
|
|
371
|
+
int64_t bytes = turso_statement_row_value_bytes_count(stmt_, index);
|
|
372
|
+
|
|
373
|
+
if (!ptr || bytes < 0) {
|
|
374
|
+
return jsi::String::createFromUtf8(rt, "");
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// Create jsi::String directly from UTF-8 bytes
|
|
378
|
+
// This avoids the round-trip through ArrayBuffer and decoding in JS
|
|
379
|
+
return jsi::String::createFromUtf8(rt, reinterpret_cast<const uint8_t*>(ptr), static_cast<size_t>(bytes));
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
jsi::Value TursoStatementHostObject::rowValueInt(jsi::Runtime &rt, const jsi::Value *args, size_t count) {
|
|
383
|
+
if (count < 1 || !args[0].isNumber()) {
|
|
384
|
+
throw jsi::JSError(rt, "rowValueInt: expected number argument (index)");
|
|
385
|
+
}
|
|
386
|
+
size_t index = static_cast<size_t>(args[0].asNumber());
|
|
387
|
+
int64_t value = turso_statement_row_value_int(stmt_, index);
|
|
388
|
+
return jsi::Value(static_cast<double>(value));
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
jsi::Value TursoStatementHostObject::rowValueDouble(jsi::Runtime &rt, const jsi::Value *args, size_t count) {
|
|
392
|
+
if (count < 1 || !args[0].isNumber()) {
|
|
393
|
+
throw jsi::JSError(rt, "rowValueDouble: expected number argument (index)");
|
|
394
|
+
}
|
|
395
|
+
size_t index = static_cast<size_t>(args[0].asNumber());
|
|
396
|
+
double value = turso_statement_row_value_double(stmt_, index);
|
|
397
|
+
return jsi::Value(value);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
jsi::Value TursoStatementHostObject::namedPosition(jsi::Runtime &rt, const jsi::Value *args, size_t count) {
|
|
401
|
+
if (count < 1 || !args[0].isString()) {
|
|
402
|
+
throw jsi::JSError(rt, "namedPosition: expected string argument (name)");
|
|
403
|
+
}
|
|
404
|
+
std::string name = args[0].asString(rt).utf8(rt);
|
|
405
|
+
int64_t position = turso_statement_named_position(stmt_, name.c_str());
|
|
406
|
+
return jsi::Value(static_cast<double>(position));
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
jsi::Value TursoStatementHostObject::parametersCount(jsi::Runtime &rt) {
|
|
410
|
+
int64_t count = turso_statement_parameters_count(stmt_);
|
|
411
|
+
return jsi::Value(static_cast<double>(count));
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
} // namespace turso
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
#include <memory>
|
|
5
|
+
#include <string>
|
|
6
|
+
|
|
7
|
+
// Forward declarations for Turso C API types
|
|
8
|
+
extern "C" {
|
|
9
|
+
struct turso_statement;
|
|
10
|
+
typedef struct turso_statement turso_statement_t;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
namespace turso {
|
|
14
|
+
|
|
15
|
+
using namespace facebook;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* TursoStatementHostObject wraps turso_statement_t* (core SDK-KIT type for prepared statement).
|
|
19
|
+
* This is a THIN wrapper - 1:1 mapping of SDK-KIT C API with NO logic.
|
|
20
|
+
* All logic belongs in TypeScript or Rust, not here.
|
|
21
|
+
*/
|
|
22
|
+
class TursoStatementHostObject : public jsi::HostObject {
|
|
23
|
+
public:
|
|
24
|
+
TursoStatementHostObject(turso_statement_t* stmt) : stmt_(stmt) {}
|
|
25
|
+
~TursoStatementHostObject();
|
|
26
|
+
|
|
27
|
+
// JSI HostObject interface
|
|
28
|
+
jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &name) override;
|
|
29
|
+
void set(jsi::Runtime &rt, const jsi::PropNameID &name, const jsi::Value &value) override;
|
|
30
|
+
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
|
|
31
|
+
|
|
32
|
+
// Direct access to wrapped pointer (for internal use)
|
|
33
|
+
turso_statement_t* getStatement() const { return stmt_; }
|
|
34
|
+
|
|
35
|
+
private:
|
|
36
|
+
turso_statement_t* stmt_ = nullptr;
|
|
37
|
+
|
|
38
|
+
// Helper to throw JS errors
|
|
39
|
+
void throwError(jsi::Runtime &rt, const char *error);
|
|
40
|
+
|
|
41
|
+
// 1:1 C API mapping methods (NO logic - just calls through to C API)
|
|
42
|
+
jsi::Value bindPositionalNull(jsi::Runtime &rt, const jsi::Value *args, size_t count);
|
|
43
|
+
jsi::Value bindPositionalInt(jsi::Runtime &rt, const jsi::Value *args, size_t count);
|
|
44
|
+
jsi::Value bindPositionalDouble(jsi::Runtime &rt, const jsi::Value *args, size_t count);
|
|
45
|
+
jsi::Value bindPositionalBlob(jsi::Runtime &rt, const jsi::Value *args, size_t count);
|
|
46
|
+
jsi::Value bindPositionalText(jsi::Runtime &rt, const jsi::Value *args, size_t count);
|
|
47
|
+
jsi::Value execute(jsi::Runtime &rt);
|
|
48
|
+
jsi::Value step(jsi::Runtime &rt);
|
|
49
|
+
jsi::Value runIo(jsi::Runtime &rt);
|
|
50
|
+
jsi::Value reset(jsi::Runtime &rt);
|
|
51
|
+
jsi::Value finalize(jsi::Runtime &rt);
|
|
52
|
+
jsi::Value nChange(jsi::Runtime &rt);
|
|
53
|
+
jsi::Value columnCount(jsi::Runtime &rt);
|
|
54
|
+
jsi::Value columnName(jsi::Runtime &rt, const jsi::Value *args, size_t count);
|
|
55
|
+
jsi::Value rowValueKind(jsi::Runtime &rt, const jsi::Value *args, size_t count);
|
|
56
|
+
jsi::Value rowValueBytesCount(jsi::Runtime &rt, const jsi::Value *args, size_t count);
|
|
57
|
+
jsi::Value rowValueBytesPtr(jsi::Runtime &rt, const jsi::Value *args, size_t count);
|
|
58
|
+
jsi::Value rowValueText(jsi::Runtime &rt, const jsi::Value *args, size_t count);
|
|
59
|
+
jsi::Value rowValueInt(jsi::Runtime &rt, const jsi::Value *args, size_t count);
|
|
60
|
+
jsi::Value rowValueDouble(jsi::Runtime &rt, const jsi::Value *args, size_t count);
|
|
61
|
+
jsi::Value namedPosition(jsi::Runtime &rt, const jsi::Value *args, size_t count);
|
|
62
|
+
jsi::Value parametersCount(jsi::Runtime &rt);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
} // namespace turso
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#include "TursoSyncChangesHostObject.h"
|
|
2
|
+
|
|
3
|
+
extern "C" {
|
|
4
|
+
#include <turso_sync.h>
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
namespace turso {
|
|
8
|
+
|
|
9
|
+
TursoSyncChangesHostObject::~TursoSyncChangesHostObject() {
|
|
10
|
+
// Only deinit if not consumed (ownership not transferred to applyChanges)
|
|
11
|
+
if (changes_ && !consumed_) {
|
|
12
|
+
turso_sync_changes_deinit(changes_);
|
|
13
|
+
changes_ = nullptr;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
void TursoSyncChangesHostObject::throwError(jsi::Runtime &rt, const char *error) {
|
|
18
|
+
throw jsi::JSError(rt, error ? error : "Unknown error");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
jsi::Value TursoSyncChangesHostObject::get(jsi::Runtime &rt, const jsi::PropNameID &name) {
|
|
22
|
+
auto propName = name.utf8(rt);
|
|
23
|
+
|
|
24
|
+
// Currently, turso_sync_changes_t is mostly opaque in the C API
|
|
25
|
+
// No methods exposed yet (like isEmpty)
|
|
26
|
+
// This object is primarily meant to be passed to applyChanges()
|
|
27
|
+
|
|
28
|
+
// If the C API adds methods in the future, they can be added here
|
|
29
|
+
|
|
30
|
+
return jsi::Value::undefined();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
void TursoSyncChangesHostObject::set(jsi::Runtime &rt, const jsi::PropNameID &name, const jsi::Value &value) {
|
|
34
|
+
// Read-only object
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
std::vector<jsi::PropNameID> TursoSyncChangesHostObject::getPropertyNames(jsi::Runtime &rt) {
|
|
38
|
+
return {};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
} // namespace turso
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
#include <memory>
|
|
5
|
+
#include <string>
|
|
6
|
+
|
|
7
|
+
// Forward declarations for Turso C API types
|
|
8
|
+
extern "C" {
|
|
9
|
+
struct turso_sync_changes;
|
|
10
|
+
typedef struct turso_sync_changes turso_sync_changes_t;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
namespace turso {
|
|
14
|
+
|
|
15
|
+
using namespace facebook;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* TursoSyncChangesHostObject wraps turso_sync_changes_t* (changes fetched from remote).
|
|
19
|
+
* This is a THIN wrapper - 1:1 mapping of SDK-KIT C API with NO logic.
|
|
20
|
+
* All logic belongs in TypeScript or Rust, not here.
|
|
21
|
+
*
|
|
22
|
+
* IMPORTANT: This object can be consumed by applyChanges(), after which it must NOT be used.
|
|
23
|
+
*/
|
|
24
|
+
class TursoSyncChangesHostObject : public jsi::HostObject {
|
|
25
|
+
public:
|
|
26
|
+
TursoSyncChangesHostObject(turso_sync_changes_t* changes) : changes_(changes), consumed_(false) {}
|
|
27
|
+
~TursoSyncChangesHostObject();
|
|
28
|
+
|
|
29
|
+
// JSI HostObject interface
|
|
30
|
+
jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &name) override;
|
|
31
|
+
void set(jsi::Runtime &rt, const jsi::PropNameID &name, const jsi::Value &value) override;
|
|
32
|
+
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
|
|
33
|
+
|
|
34
|
+
// Direct access to wrapped pointer (for internal use)
|
|
35
|
+
turso_sync_changes_t* getChanges() const { return changes_; }
|
|
36
|
+
|
|
37
|
+
// Mark this object as consumed (ownership transferred to applyChanges)
|
|
38
|
+
void markConsumed() { consumed_ = true; }
|
|
39
|
+
|
|
40
|
+
private:
|
|
41
|
+
turso_sync_changes_t* changes_ = nullptr;
|
|
42
|
+
bool consumed_ = false; // If true, changes ownership was transferred
|
|
43
|
+
|
|
44
|
+
// Helper to throw JS errors
|
|
45
|
+
void throwError(jsi::Runtime &rt, const char *error);
|
|
46
|
+
|
|
47
|
+
// 1:1 C API mapping methods (NO logic - just calls through to C API)
|
|
48
|
+
// Currently, there are no operations on turso_sync_changes_t other than passing it to applyChanges
|
|
49
|
+
// The C API doesn't expose methods like isEmpty() yet, so this object is mostly opaque
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
} // namespace turso
|