@rozenite/sqlite-plugin 1.13.0 → 2.1.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/CHANGELOG.md +23 -0
- package/dist/devtools/assets/panel-BarPLQ4-.css +1 -0
- package/dist/devtools/assets/{panel-DjRs5NTl.js → panel-BsdCagVv.js} +45 -44
- package/dist/devtools/panel.html +2 -2
- package/dist/react-native/chunks/index.require.js +4 -16
- package/dist/react-native/chunks/sql.require.js +1 -3
- package/dist/react-native/chunks/useRozeniteSqlitePlugin.require.js +92 -110
- package/dist/react-native/index.d.ts +2 -2
- package/dist/rozenite.json +1 -1
- package/package.json +27 -31
- package/react-native.ts +7 -14
- package/src/react-native/adapters/__tests__/expo-sqlite.test.ts +4 -14
- package/src/react-native/adapters/expo-sqlite.ts +11 -40
- package/src/react-native/adapters/generic.ts +5 -13
- package/src/react-native/adapters/index.ts +1 -4
- package/src/react-native/sqlite-view.ts +2 -8
- package/src/react-native/useRozeniteSqlitePlugin.ts +110 -130
- package/src/react-native/useSqliteAgentTools.ts +5 -14
- package/src/shared/__tests__/bridge-values.test.ts +6 -11
- package/src/shared/__tests__/sql.test.ts +4 -8
- package/src/shared/bridge-values.ts +2 -5
- package/src/shared/sql.ts +3 -7
- package/src/ui/__tests__/sql-editor-utils.test.ts +1 -5
- package/src/ui/__tests__/sqlite-drop-mutations.test.ts +138 -0
- package/src/ui/__tests__/sqlite-row-mutations.test.ts +1 -3
- package/src/ui/__tests__/sqlite-table-column-order.test.ts +4 -19
- package/src/ui/cell-detail-drawer.tsx +1 -6
- package/src/ui/globals.css +26 -65
- package/src/ui/panel.tsx +442 -568
- package/src/ui/query-result-table.tsx +8 -26
- package/src/ui/sql-editor-utils.ts +24 -55
- package/src/ui/sql-editor.tsx +13 -46
- package/src/ui/sqlite-data-table.tsx +11 -28
- package/src/ui/sqlite-drop-modal.tsx +193 -0
- package/src/ui/sqlite-drop-mutations.ts +53 -0
- package/src/ui/sqlite-introspection.ts +9 -25
- package/src/ui/sqlite-row-delete-modal.tsx +5 -12
- package/src/ui/sqlite-row-edit-modal.tsx +22 -64
- package/src/ui/sqlite-row-edit-value.ts +2 -11
- package/src/ui/sqlite-row-mutations.ts +10 -32
- package/src/ui/sqlite-table-column-order.ts +8 -23
- package/src/ui/use-sqlite-requests.ts +46 -86
- package/src/ui/utils.ts +1 -5
- package/src/ui/value-utils.tsx +3 -11
- package/dist/devtools/assets/panel-CIU0JBOs.css +0 -1
- package/postcss.config.js +0 -6
package/dist/devtools/panel.html
CHANGED
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
<script>
|
|
23
23
|
var __ROZENITE_PANEL__ = true;
|
|
24
24
|
</script>
|
|
25
|
-
<script type="module" crossorigin src="../devtools/assets/panel-
|
|
26
|
-
<link rel="stylesheet" crossorigin href="../devtools/assets/panel-
|
|
25
|
+
<script type="module" crossorigin src="../devtools/assets/panel-BsdCagVv.js"></script>
|
|
26
|
+
<link rel="stylesheet" crossorigin href="../devtools/assets/panel-BarPLQ4-.css">
|
|
27
27
|
</head>
|
|
28
28
|
<body>
|
|
29
29
|
<div id="root"></div>
|
|
@@ -25,17 +25,9 @@ const A = (e) => e.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+
|
|
|
25
25
|
databases: r
|
|
26
26
|
};
|
|
27
27
|
}, m = () => typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now(), j = (e) => g(e), q = (e, a = {}) => Object.assign(new Error(e), a), i = (e) => e == null || typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? e : e instanceof Uint8Array ? Array.from(e) : e instanceof ArrayBuffer ? Array.from(new Uint8Array(e)) : Array.isArray(e) ? e.map(i) : typeof e == "object" ? Object.fromEntries(
|
|
28
|
-
Object.entries(e).map(([a, t]) => [
|
|
29
|
-
a,
|
|
30
|
-
i(t)
|
|
31
|
-
])
|
|
28
|
+
Object.entries(e).map(([a, t]) => [a, i(t)])
|
|
32
29
|
) : String(e), O = (e) => e.map(
|
|
33
|
-
(a) => Object.fromEntries(
|
|
34
|
-
Object.entries(a).map(([t, r]) => [
|
|
35
|
-
t,
|
|
36
|
-
i(r)
|
|
37
|
-
])
|
|
38
|
-
)
|
|
30
|
+
(a) => Object.fromEntries(Object.entries(a).map(([t, r]) => [t, i(r)]))
|
|
39
31
|
), h = async (e, { sql: a, params: t }) => {
|
|
40
32
|
const r = S(a), n = y(r), o = m(), s = t === void 0 ? void 0 : x(t);
|
|
41
33
|
if (w(n)) {
|
|
@@ -90,9 +82,7 @@ const A = (e) => e.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+
|
|
|
90
82
|
t,
|
|
91
83
|
{
|
|
92
84
|
name: n.name ?? t,
|
|
93
|
-
executeStatements: u(
|
|
94
|
-
n.database
|
|
95
|
-
)
|
|
85
|
+
executeStatements: u(n.database)
|
|
96
86
|
}
|
|
97
87
|
];
|
|
98
88
|
})
|
|
@@ -105,9 +95,7 @@ const A = (e) => e.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+
|
|
|
105
95
|
const t = f(e.database);
|
|
106
96
|
return {
|
|
107
97
|
name: t.name ?? e.databaseName,
|
|
108
|
-
executeStatements: u(
|
|
109
|
-
t.database
|
|
110
|
-
)
|
|
98
|
+
executeStatements: u(t.database)
|
|
111
99
|
};
|
|
112
100
|
})()
|
|
113
101
|
};
|
|
@@ -169,9 +169,7 @@ const f = (n) => /\s/.test(n), a = (n) => {
|
|
|
169
169
|
return c && l(n.length), e;
|
|
170
170
|
}, h = (n, e) => {
|
|
171
171
|
const c = s(n);
|
|
172
|
-
return c.length === 0 ? null : c.find(
|
|
173
|
-
(t) => e >= t.start && e <= t.end + 1
|
|
174
|
-
) ?? c[0];
|
|
172
|
+
return c.length === 0 ? null : c.find((t) => e >= t.start && e <= t.end + 1) ?? c[0];
|
|
175
173
|
}, g = (n) => {
|
|
176
174
|
const e = a(n);
|
|
177
175
|
if (e === 0)
|
|
@@ -38,9 +38,7 @@ const z = "@rozenite/sqlite-plugin", C = (a) => a.flatMap(
|
|
|
38
38
|
const u = a.find((m) => m.id === e);
|
|
39
39
|
if (!u) {
|
|
40
40
|
const m = a.map((i) => i.id).join(", ");
|
|
41
|
-
throw new Error(
|
|
42
|
-
`Unknown databaseId "${e}". Available: ${m || "(none)"}`
|
|
43
|
-
);
|
|
41
|
+
throw new Error(`Unknown databaseId "${e}". Available: ${m || "(none)"}`);
|
|
44
42
|
}
|
|
45
43
|
return u;
|
|
46
44
|
},
|
|
@@ -93,10 +91,7 @@ const z = "@rozenite/sqlite-plugin", C = (a) => a.flatMap(
|
|
|
93
91
|
typeof c.failedStatementIndex == "number" ? c.failedStatementIndex : c.completedResults?.length ?? 0,
|
|
94
92
|
i.length - 1
|
|
95
93
|
)
|
|
96
|
-
), n = (c.completedResults ?? []).slice(
|
|
97
|
-
0,
|
|
98
|
-
S
|
|
99
|
-
);
|
|
94
|
+
), n = (c.completedResults ?? []).slice(0, S);
|
|
100
95
|
return {
|
|
101
96
|
databaseId: e,
|
|
102
97
|
totalStatementCount: i.length,
|
|
@@ -119,9 +114,7 @@ const z = "@rozenite/sqlite-plugin", C = (a) => a.flatMap(
|
|
|
119
114
|
}
|
|
120
115
|
}
|
|
121
116
|
});
|
|
122
|
-
}, w = (a) => x(a), k = (a) => a instanceof Error && ("completedResults" in a || "failedStatementIndex" in a), B = ({
|
|
123
|
-
adapters: a
|
|
124
|
-
}) => {
|
|
117
|
+
}, w = (a) => x(a), k = (a) => a instanceof Error && ("completedResults" in a || "failedStatementIndex" in a), B = ({ adapters: a }) => {
|
|
125
118
|
const p = I(() => C(a), [a]);
|
|
126
119
|
$(p);
|
|
127
120
|
const e = T({
|
|
@@ -184,113 +177,102 @@ const z = "@rozenite/sqlite-plugin", C = (a) => a.flatMap(
|
|
|
184
177
|
});
|
|
185
178
|
})
|
|
186
179
|
), u.current.push(
|
|
187
|
-
e.onMessage(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
error: w(s)
|
|
205
|
-
});
|
|
206
|
-
}
|
|
180
|
+
e.onMessage("sqlite:query", async ({ requestId: n, databaseId: t, sql: o, params: r }) => {
|
|
181
|
+
try {
|
|
182
|
+
const s = await i(
|
|
183
|
+
t,
|
|
184
|
+
() => S(t, o, r)
|
|
185
|
+
);
|
|
186
|
+
e.send("sqlite:query:result", {
|
|
187
|
+
requestId: n,
|
|
188
|
+
databaseId: t,
|
|
189
|
+
result: s
|
|
190
|
+
});
|
|
191
|
+
} catch (s) {
|
|
192
|
+
e.send("sqlite:query:result", {
|
|
193
|
+
requestId: n,
|
|
194
|
+
databaseId: t,
|
|
195
|
+
error: w(s)
|
|
196
|
+
});
|
|
207
197
|
}
|
|
208
|
-
)
|
|
198
|
+
})
|
|
209
199
|
), u.current.push(
|
|
210
|
-
e.onMessage(
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
index: q,
|
|
229
|
-
start: d.start,
|
|
230
|
-
end: d.end,
|
|
200
|
+
e.onMessage("sqlite:execute-script", async ({ requestId: n, databaseId: t, sql: o }) => {
|
|
201
|
+
try {
|
|
202
|
+
const r = await i(t, async () => {
|
|
203
|
+
const s = R(o);
|
|
204
|
+
if (s.length === 0)
|
|
205
|
+
throw new Error("Query cannot be empty.");
|
|
206
|
+
const f = s.map((l) => ({
|
|
207
|
+
sql: l.text
|
|
208
|
+
}));
|
|
209
|
+
try {
|
|
210
|
+
const l = await c(t, f);
|
|
211
|
+
return {
|
|
212
|
+
statements: s.map((d, q) => ({
|
|
213
|
+
index: q,
|
|
214
|
+
start: d.start,
|
|
215
|
+
end: d.end,
|
|
216
|
+
input: l.inputs[q],
|
|
217
|
+
execution: {
|
|
231
218
|
input: l.inputs[q],
|
|
219
|
+
result: l.results[q]
|
|
220
|
+
}
|
|
221
|
+
})),
|
|
222
|
+
totalStatementCount: s.length,
|
|
223
|
+
failedStatementIndex: null
|
|
224
|
+
};
|
|
225
|
+
} catch (l) {
|
|
226
|
+
if (!k(l))
|
|
227
|
+
throw l;
|
|
228
|
+
const d = Math.max(
|
|
229
|
+
0,
|
|
230
|
+
Math.min(
|
|
231
|
+
typeof l.failedStatementIndex == "number" ? l.failedStatementIndex : l.completedResults?.length ?? 0,
|
|
232
|
+
s.length - 1
|
|
233
|
+
)
|
|
234
|
+
);
|
|
235
|
+
return {
|
|
236
|
+
statements: [
|
|
237
|
+
...(l.completedResults ?? []).slice(
|
|
238
|
+
0,
|
|
239
|
+
d
|
|
240
|
+
).map((M, g) => ({
|
|
241
|
+
index: g,
|
|
242
|
+
start: s[g].start,
|
|
243
|
+
end: s[g].end,
|
|
244
|
+
input: f[g],
|
|
232
245
|
execution: {
|
|
233
|
-
input:
|
|
234
|
-
result:
|
|
246
|
+
input: f[g],
|
|
247
|
+
result: M
|
|
235
248
|
}
|
|
236
249
|
})),
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
execution: {
|
|
262
|
-
input: f[g],
|
|
263
|
-
result: M
|
|
264
|
-
}
|
|
265
|
-
})
|
|
266
|
-
),
|
|
267
|
-
{
|
|
268
|
-
index: d,
|
|
269
|
-
start: s[d].start,
|
|
270
|
-
end: s[d].end,
|
|
271
|
-
input: f[d],
|
|
272
|
-
error: w(l)
|
|
273
|
-
}
|
|
274
|
-
],
|
|
275
|
-
totalStatementCount: s.length,
|
|
276
|
-
failedStatementIndex: d
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
e.send("sqlite:execute-script:result", {
|
|
281
|
-
requestId: n,
|
|
282
|
-
databaseId: t,
|
|
283
|
-
result: r
|
|
284
|
-
});
|
|
285
|
-
} catch (r) {
|
|
286
|
-
e.send("sqlite:execute-script:result", {
|
|
287
|
-
requestId: n,
|
|
288
|
-
databaseId: t,
|
|
289
|
-
error: w(r)
|
|
290
|
-
});
|
|
291
|
-
}
|
|
250
|
+
{
|
|
251
|
+
index: d,
|
|
252
|
+
start: s[d].start,
|
|
253
|
+
end: s[d].end,
|
|
254
|
+
input: f[d],
|
|
255
|
+
error: w(l)
|
|
256
|
+
}
|
|
257
|
+
],
|
|
258
|
+
totalStatementCount: s.length,
|
|
259
|
+
failedStatementIndex: d
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
e.send("sqlite:execute-script:result", {
|
|
264
|
+
requestId: n,
|
|
265
|
+
databaseId: t,
|
|
266
|
+
result: r
|
|
267
|
+
});
|
|
268
|
+
} catch (r) {
|
|
269
|
+
e.send("sqlite:execute-script:result", {
|
|
270
|
+
requestId: n,
|
|
271
|
+
databaseId: t,
|
|
272
|
+
error: w(r)
|
|
273
|
+
});
|
|
292
274
|
}
|
|
293
|
-
)
|
|
275
|
+
})
|
|
294
276
|
), () => {
|
|
295
277
|
u.current.forEach((n) => n.remove()), u.current = [], m.current.clear();
|
|
296
278
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RozeniteDevToolsRequestClient } from '@rozenite/plugin-bridge';
|
|
2
2
|
|
|
3
3
|
export declare let classifySqlStatement: typeof classifySqlStatement_2;
|
|
4
4
|
|
|
@@ -203,6 +203,6 @@ declare const statementReturnsRows_2: (statementType: SqliteStatementType) => st
|
|
|
203
203
|
|
|
204
204
|
export declare let useRozeniteSqlitePlugin: typeof useRozeniteSqlitePlugin_2;
|
|
205
205
|
|
|
206
|
-
declare const useRozeniteSqlitePlugin_2: ({ adapters
|
|
206
|
+
declare const useRozeniteSqlitePlugin_2: ({ adapters }: RozeniteSqlitePluginOptions) => RozeniteDevToolsRequestClient<SqliteEventMap> | null;
|
|
207
207
|
|
|
208
208
|
export { }
|
package/dist/rozenite.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@rozenite/sqlite-plugin","version":"1.
|
|
1
|
+
{"name":"@rozenite/sqlite-plugin","version":"2.1.0","description":"SQLite inspector for Rozenite.","panels":[{"name":"SQLite","source":"/devtools/panel.html"}]}
|
package/package.json
CHANGED
|
@@ -1,26 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rozenite/sqlite-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "SQLite inspector for Rozenite.",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "./dist/react-native/index.cjs",
|
|
7
|
-
"module": "./dist/react-native/index.js",
|
|
8
|
-
"types": "./dist/react-native/index.d.ts",
|
|
9
5
|
"homepage": "https://github.com/callstackincubator/rozenite#readme",
|
|
10
6
|
"bugs": {
|
|
11
7
|
"url": "https://github.com/callstackincubator/rozenite/issues"
|
|
12
8
|
},
|
|
9
|
+
"license": "MIT",
|
|
13
10
|
"repository": {
|
|
14
11
|
"type": "git",
|
|
15
12
|
"url": "https://github.com/callstackincubator/rozenite.git"
|
|
16
13
|
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./dist/react-native/index.cjs",
|
|
16
|
+
"module": "./dist/react-native/index.js",
|
|
17
|
+
"types": "./dist/react-native/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/react-native/index.d.ts",
|
|
21
|
+
"import": "./dist/react-native/index.js",
|
|
22
|
+
"require": "./dist/react-native/index.cjs"
|
|
23
|
+
},
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
17
29
|
"dependencies": {
|
|
18
|
-
"@rozenite/agent-bridge": "1.
|
|
19
|
-
"@rozenite/plugin-bridge": "1.
|
|
30
|
+
"@rozenite/agent-bridge": "2.1.0",
|
|
31
|
+
"@rozenite/plugin-bridge": "2.1.0"
|
|
20
32
|
},
|
|
21
33
|
"devDependencies": {
|
|
22
|
-
"@dnd-kit/core": "^6.3.1",
|
|
23
|
-
"@dnd-kit/sortable": "^8.0.0",
|
|
24
34
|
"@codemirror/autocomplete": "^6.20.1",
|
|
25
35
|
"@codemirror/commands": "^6.10.3",
|
|
26
36
|
"@codemirror/lang-sql": "^6.10.0",
|
|
@@ -28,29 +38,27 @@
|
|
|
28
38
|
"@codemirror/search": "^6.6.0",
|
|
29
39
|
"@codemirror/state": "^6.6.0",
|
|
30
40
|
"@codemirror/view": "^6.40.0",
|
|
41
|
+
"@dnd-kit/core": "^6.3.1",
|
|
42
|
+
"@dnd-kit/sortable": "^8.0.0",
|
|
31
43
|
"@heroui/react": "^3.0.1",
|
|
32
44
|
"@heroui/styles": "^3.0.1",
|
|
33
45
|
"@lezer/highlight": "^1.2.3",
|
|
34
|
-
"@tailwindcss/postcss": "^4.2.2",
|
|
35
46
|
"@tanstack/react-table": "^8.21.3",
|
|
36
47
|
"@tanstack/react-virtual": "^3.0.0",
|
|
37
|
-
"@types/react": "~19.2.
|
|
38
|
-
"autoprefixer": "^10.4.21",
|
|
48
|
+
"@types/react": "~19.2.3",
|
|
39
49
|
"expo-sqlite": "^55.0.11",
|
|
40
50
|
"lucide-react": "^0.263.1",
|
|
41
|
-
"
|
|
42
|
-
"react": "19.2.
|
|
43
|
-
"react-dom": "19.2.0",
|
|
51
|
+
"react": "19.2.3",
|
|
52
|
+
"react-dom": "19.2.3",
|
|
44
53
|
"react-json-tree": "^0.20.0",
|
|
45
|
-
"react-native": "0.
|
|
54
|
+
"react-native": "0.86.0",
|
|
46
55
|
"react-native-web": "^0.21.2",
|
|
47
56
|
"sql-formatter": "^15.7.2",
|
|
48
|
-
"tailwindcss": "^4.2.2",
|
|
49
57
|
"typescript": "~5.9.3",
|
|
50
58
|
"vite": "^7.3.1",
|
|
51
59
|
"vitest": "^3.2.4",
|
|
52
|
-
"rozenite": "1.
|
|
53
|
-
"
|
|
60
|
+
"@rozenite/vite-plugin": "2.1.0",
|
|
61
|
+
"rozenite": "2.1.0"
|
|
54
62
|
},
|
|
55
63
|
"peerDependencies": {
|
|
56
64
|
"expo-sqlite": "*",
|
|
@@ -62,18 +70,6 @@
|
|
|
62
70
|
"optional": true
|
|
63
71
|
}
|
|
64
72
|
},
|
|
65
|
-
"license": "MIT",
|
|
66
|
-
"exports": {
|
|
67
|
-
".": {
|
|
68
|
-
"types": "./dist/react-native/index.d.ts",
|
|
69
|
-
"import": "./dist/react-native/index.js",
|
|
70
|
-
"require": "./dist/react-native/index.cjs"
|
|
71
|
-
},
|
|
72
|
-
"./package.json": "./package.json"
|
|
73
|
-
},
|
|
74
|
-
"publishConfig": {
|
|
75
|
-
"access": "public"
|
|
76
|
-
},
|
|
77
73
|
"scripts": {
|
|
78
74
|
"build": "rozenite build",
|
|
79
75
|
"dev": "rozenite dev",
|
package/react-native.ts
CHANGED
|
@@ -20,10 +20,8 @@ export type {
|
|
|
20
20
|
} from './src/react-native/adapters/expo-sqlite';
|
|
21
21
|
export type { SqlStatementSegment } from './src/shared/sql';
|
|
22
22
|
|
|
23
|
-
type CreateSqliteAdapter =
|
|
24
|
-
|
|
25
|
-
type CreateExpoSqliteAdapter =
|
|
26
|
-
typeof import('./src/react-native/adapters').createExpoSqliteAdapter;
|
|
23
|
+
type CreateSqliteAdapter = typeof import('./src/react-native/adapters').createSqliteAdapter;
|
|
24
|
+
type CreateExpoSqliteAdapter = typeof import('./src/react-native/adapters').createExpoSqliteAdapter;
|
|
27
25
|
|
|
28
26
|
export let createSqliteAdapter: CreateSqliteAdapter;
|
|
29
27
|
export let createExpoSqliteAdapter: CreateExpoSqliteAdapter;
|
|
@@ -36,24 +34,19 @@ export let decodeSqliteBridgeValue: typeof import('./src/shared/bridge-values').
|
|
|
36
34
|
export let formatSqliteError: typeof import('./src/shared/bridge-values').formatSqliteError;
|
|
37
35
|
|
|
38
36
|
const isDev = process.env.NODE_ENV !== 'production';
|
|
39
|
-
const isWeb =
|
|
40
|
-
typeof window !== 'undefined' && window.navigator.product !== 'ReactNative';
|
|
37
|
+
const isWeb = typeof window !== 'undefined' && window.navigator.product !== 'ReactNative';
|
|
41
38
|
const isServer = typeof window === 'undefined';
|
|
42
39
|
|
|
43
40
|
if (isDev && !isWeb && !isServer) {
|
|
44
|
-
createSqliteAdapter =
|
|
45
|
-
|
|
46
|
-
createExpoSqliteAdapter =
|
|
47
|
-
require('./src/react-native/adapters').createExpoSqliteAdapter;
|
|
41
|
+
createSqliteAdapter = require('./src/react-native/adapters').createSqliteAdapter;
|
|
42
|
+
createExpoSqliteAdapter = require('./src/react-native/adapters').createExpoSqliteAdapter;
|
|
48
43
|
useRozeniteSqlitePlugin =
|
|
49
44
|
require('./src/react-native/useRozeniteSqlitePlugin').useRozeniteSqlitePlugin;
|
|
50
45
|
classifySqlStatement = require('./src/shared/sql').classifySqlStatement;
|
|
51
|
-
normalizeSingleStatementSql =
|
|
52
|
-
require('./src/shared/sql').normalizeSingleStatementSql;
|
|
46
|
+
normalizeSingleStatementSql = require('./src/shared/sql').normalizeSingleStatementSql;
|
|
53
47
|
splitSqlStatements = require('./src/shared/sql').splitSqlStatements;
|
|
54
48
|
statementReturnsRows = require('./src/shared/sql').statementReturnsRows;
|
|
55
|
-
decodeSqliteBridgeValue =
|
|
56
|
-
require('./src/shared/bridge-values').decodeSqliteBridgeValue;
|
|
49
|
+
decodeSqliteBridgeValue = require('./src/shared/bridge-values').decodeSqliteBridgeValue;
|
|
57
50
|
formatSqliteError = require('./src/shared/bridge-values').formatSqliteError;
|
|
58
51
|
} else {
|
|
59
52
|
createSqliteAdapter = (options) => ({
|
|
@@ -19,12 +19,8 @@ describe('createExpoSqliteAdapter', () => {
|
|
|
19
19
|
{ sql: "INSERT INTO users(name) VALUES('Grace');" },
|
|
20
20
|
]);
|
|
21
21
|
|
|
22
|
-
expect(database.getAllAsync).toHaveBeenCalledWith(
|
|
23
|
-
|
|
24
|
-
);
|
|
25
|
-
expect(database.runAsync).toHaveBeenCalledWith(
|
|
26
|
-
"INSERT INTO users(name) VALUES('Grace')",
|
|
27
|
-
);
|
|
22
|
+
expect(database.getAllAsync).toHaveBeenCalledWith('SELECT id, name FROM users');
|
|
23
|
+
expect(database.runAsync).toHaveBeenCalledWith("INSERT INTO users(name) VALUES('Grace')");
|
|
28
24
|
expect(results).toHaveLength(2);
|
|
29
25
|
expect(results[0]?.metadata.statementType).toBe('select');
|
|
30
26
|
expect(results[1]?.metadata.statementType).toBe('insert');
|
|
@@ -43,17 +39,11 @@ describe('createExpoSqliteAdapter', () => {
|
|
|
43
39
|
});
|
|
44
40
|
const [mainDatabase] = adapter.databases;
|
|
45
41
|
|
|
46
|
-
const results = await mainDatabase.executeStatements([
|
|
47
|
-
{ sql: 'BEGIN;' },
|
|
48
|
-
{ sql: 'ROLLBACK;' },
|
|
49
|
-
]);
|
|
42
|
+
const results = await mainDatabase.executeStatements([{ sql: 'BEGIN;' }, { sql: 'ROLLBACK;' }]);
|
|
50
43
|
|
|
51
44
|
expect(database.runAsync).toHaveBeenNthCalledWith(1, 'BEGIN');
|
|
52
45
|
expect(database.runAsync).toHaveBeenNthCalledWith(2, 'ROLLBACK');
|
|
53
|
-
expect(results.map((result) => result.metadata.statementType)).toEqual([
|
|
54
|
-
'other',
|
|
55
|
-
'other',
|
|
56
|
-
]);
|
|
46
|
+
expect(results.map((result) => result.metadata.statementType)).toEqual(['other', 'other']);
|
|
57
47
|
});
|
|
58
48
|
|
|
59
49
|
it('throws batch execution metadata when a later statement fails', async () => {
|
|
@@ -3,10 +3,7 @@ import {
|
|
|
3
3
|
normalizeSingleStatementSql,
|
|
4
4
|
statementReturnsRows,
|
|
5
5
|
} from '../../shared/sql';
|
|
6
|
-
import {
|
|
7
|
-
decodeSqliteBridgeValue,
|
|
8
|
-
formatSqliteError,
|
|
9
|
-
} from '../../shared/bridge-values';
|
|
6
|
+
import { decodeSqliteBridgeValue, formatSqliteError } from '../../shared/bridge-values';
|
|
10
7
|
import type {
|
|
11
8
|
SqliteAdapter,
|
|
12
9
|
SqliteExecuteStatementsError,
|
|
@@ -14,10 +11,7 @@ import type {
|
|
|
14
11
|
SqliteStatementInput,
|
|
15
12
|
SqliteQueryResult,
|
|
16
13
|
} from '../../shared/types';
|
|
17
|
-
import {
|
|
18
|
-
createSqliteAdapter,
|
|
19
|
-
type CreateSqliteAdapterOptions,
|
|
20
|
-
} from './generic';
|
|
14
|
+
import { createSqliteAdapter, type CreateSqliteAdapterOptions } from './generic';
|
|
21
15
|
|
|
22
16
|
export type ExpoSqliteLike = {
|
|
23
17
|
getAllAsync: (...args: any[]) => Promise<Record<string, unknown>[]>;
|
|
@@ -35,17 +29,12 @@ type SingleDatabaseOptions = {
|
|
|
35
29
|
};
|
|
36
30
|
|
|
37
31
|
type MultiDatabaseOptions = {
|
|
38
|
-
databases: Record<
|
|
39
|
-
string,
|
|
40
|
-
ExpoSqliteLike | { database: ExpoSqliteLike; name?: string }
|
|
41
|
-
>;
|
|
32
|
+
databases: Record<string, ExpoSqliteLike | { database: ExpoSqliteLike; name?: string }>;
|
|
42
33
|
adapterId?: string;
|
|
43
34
|
adapterName?: string;
|
|
44
35
|
};
|
|
45
36
|
|
|
46
|
-
export type CreateExpoSqliteAdapterOptions =
|
|
47
|
-
| SingleDatabaseOptions
|
|
48
|
-
| MultiDatabaseOptions;
|
|
37
|
+
export type CreateExpoSqliteAdapterOptions = SingleDatabaseOptions | MultiDatabaseOptions;
|
|
49
38
|
|
|
50
39
|
const now = () =>
|
|
51
40
|
typeof performance !== 'undefined' && typeof performance.now === 'function'
|
|
@@ -87,10 +76,7 @@ const toBridgeSafeValue = (value: unknown): unknown => {
|
|
|
87
76
|
|
|
88
77
|
if (typeof value === 'object') {
|
|
89
78
|
return Object.fromEntries(
|
|
90
|
-
Object.entries(value).map(([key, nestedValue]) => [
|
|
91
|
-
key,
|
|
92
|
-
toBridgeSafeValue(nestedValue),
|
|
93
|
-
]),
|
|
79
|
+
Object.entries(value).map(([key, nestedValue]) => [key, toBridgeSafeValue(nestedValue)]),
|
|
94
80
|
);
|
|
95
81
|
}
|
|
96
82
|
|
|
@@ -99,12 +85,7 @@ const toBridgeSafeValue = (value: unknown): unknown => {
|
|
|
99
85
|
|
|
100
86
|
const normalizeRows = (rows: Record<string, unknown>[]) =>
|
|
101
87
|
rows.map((row) =>
|
|
102
|
-
Object.fromEntries(
|
|
103
|
-
Object.entries(row).map(([key, value]) => [
|
|
104
|
-
key,
|
|
105
|
-
toBridgeSafeValue(value),
|
|
106
|
-
]),
|
|
107
|
-
),
|
|
88
|
+
Object.fromEntries(Object.entries(row).map(([key, value]) => [key, toBridgeSafeValue(value)])),
|
|
108
89
|
);
|
|
109
90
|
|
|
110
91
|
const executeSingleStatement = async (
|
|
@@ -114,8 +95,7 @@ const executeSingleStatement = async (
|
|
|
114
95
|
const normalizedSql = normalizeSingleStatementSql(sql);
|
|
115
96
|
const statementType = classifySqlStatement(normalizedSql);
|
|
116
97
|
const startedAt = now();
|
|
117
|
-
const decodedParams =
|
|
118
|
-
params === undefined ? undefined : decodeSqliteBridgeValue(params);
|
|
98
|
+
const decodedParams = params === undefined ? undefined : decodeSqliteBridgeValue(params);
|
|
119
99
|
|
|
120
100
|
if (statementReturnsRows(statementType)) {
|
|
121
101
|
const rows = normalizeRows(
|
|
@@ -151,10 +131,7 @@ const executeSingleStatement = async (
|
|
|
151
131
|
statementType,
|
|
152
132
|
rowCount: 0,
|
|
153
133
|
changes: typeof result.changes === 'number' ? result.changes : null,
|
|
154
|
-
lastInsertRowId:
|
|
155
|
-
typeof result.lastInsertRowId === 'number'
|
|
156
|
-
? result.lastInsertRowId
|
|
157
|
-
: null,
|
|
134
|
+
lastInsertRowId: typeof result.lastInsertRowId === 'number' ? result.lastInsertRowId : null,
|
|
158
135
|
durationMs,
|
|
159
136
|
},
|
|
160
137
|
};
|
|
@@ -186,9 +163,7 @@ const resolveDatabaseConfig = (
|
|
|
186
163
|
config: ExpoSqliteLike | { database: ExpoSqliteLike; name?: string },
|
|
187
164
|
) => ('database' in config ? config : { database: config });
|
|
188
165
|
|
|
189
|
-
export const createExpoSqliteAdapter = (
|
|
190
|
-
options: CreateExpoSqliteAdapterOptions,
|
|
191
|
-
): SqliteAdapter => {
|
|
166
|
+
export const createExpoSqliteAdapter = (options: CreateExpoSqliteAdapterOptions): SqliteAdapter => {
|
|
192
167
|
const genericOptions: CreateSqliteAdapterOptions =
|
|
193
168
|
'databases' in options
|
|
194
169
|
? {
|
|
@@ -202,9 +177,7 @@ export const createExpoSqliteAdapter = (
|
|
|
202
177
|
key,
|
|
203
178
|
{
|
|
204
179
|
name: resolved.name ?? key,
|
|
205
|
-
executeStatements: createExpoExecuteStatementsRunner(
|
|
206
|
-
resolved.database,
|
|
207
|
-
),
|
|
180
|
+
executeStatements: createExpoExecuteStatementsRunner(resolved.database),
|
|
208
181
|
},
|
|
209
182
|
];
|
|
210
183
|
}),
|
|
@@ -219,9 +192,7 @@ export const createExpoSqliteAdapter = (
|
|
|
219
192
|
|
|
220
193
|
return {
|
|
221
194
|
name: resolved.name ?? options.databaseName,
|
|
222
|
-
executeStatements: createExpoExecuteStatementsRunner(
|
|
223
|
-
resolved.database,
|
|
224
|
-
),
|
|
195
|
+
executeStatements: createExpoExecuteStatementsRunner(resolved.database),
|
|
225
196
|
};
|
|
226
197
|
})(),
|
|
227
198
|
};
|
|
@@ -17,17 +17,12 @@ type SingleDatabaseOptions = {
|
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
type MultiDatabaseOptions = {
|
|
20
|
-
databases: Record<
|
|
21
|
-
string,
|
|
22
|
-
SqliteExecuteStatementsRunner | SqliteDatabaseConfig
|
|
23
|
-
>;
|
|
20
|
+
databases: Record<string, SqliteExecuteStatementsRunner | SqliteDatabaseConfig>;
|
|
24
21
|
adapterId?: string;
|
|
25
22
|
adapterName?: string;
|
|
26
23
|
};
|
|
27
24
|
|
|
28
|
-
export type CreateSqliteAdapterOptions =
|
|
29
|
-
| SingleDatabaseOptions
|
|
30
|
-
| MultiDatabaseOptions;
|
|
25
|
+
export type CreateSqliteAdapterOptions = SingleDatabaseOptions | MultiDatabaseOptions;
|
|
31
26
|
|
|
32
27
|
const slugify = (value: string) =>
|
|
33
28
|
value
|
|
@@ -39,9 +34,8 @@ const slugify = (value: string) =>
|
|
|
39
34
|
const createDatabaseId = (adapterId: string, seed: string, index: number) =>
|
|
40
35
|
`${adapterId}__${slugify(seed)}__${index.toString(36)}`;
|
|
41
36
|
|
|
42
|
-
const resolveDatabaseConfig = (
|
|
43
|
-
config:
|
|
44
|
-
) => (typeof config === 'function' ? { executeStatements: config } : config);
|
|
37
|
+
const resolveDatabaseConfig = (config: SqliteExecuteStatementsRunner | SqliteDatabaseConfig) =>
|
|
38
|
+
typeof config === 'function' ? { executeStatements: config } : config;
|
|
45
39
|
|
|
46
40
|
const toDatabaseNode = (
|
|
47
41
|
adapterId: string,
|
|
@@ -60,9 +54,7 @@ const toDatabaseNode = (
|
|
|
60
54
|
};
|
|
61
55
|
};
|
|
62
56
|
|
|
63
|
-
export const createSqliteAdapter = (
|
|
64
|
-
options: CreateSqliteAdapterOptions,
|
|
65
|
-
): SqliteAdapter => {
|
|
57
|
+
export const createSqliteAdapter = (options: CreateSqliteAdapterOptions): SqliteAdapter => {
|
|
66
58
|
const { adapterId = 'sqlite', adapterName = 'SQLite' } = options;
|
|
67
59
|
|
|
68
60
|
const databases =
|