@wxn0brp/db-storage-sqlite 0.110.2 → 0.110.3
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 +6 -0
- package/dist/remove.js +6 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -73,6 +73,12 @@ await db.users.remove({ name: "John Doe" });
|
|
|
73
73
|
|
|
74
74
|
- All other methods (`add`, `find`, `update`, `remove`) are **fully compatible with ValtheraDB**, preserving all features like `_id` generation, complex filters (`hasFieldsAdvanced`), sorting, pagination, and function-based search.
|
|
75
75
|
|
|
76
|
+
## Environment Variables
|
|
77
|
+
|
|
78
|
+
| Variable | Default | Description |
|
|
79
|
+
|---|---|---|
|
|
80
|
+
| `VALTHERA_SQLITE_BATCH_SIZE` | `500` | Maximum number of rows processed per batch in `remove` operations. Reduces to stay under SQLite's variable limit (`SQLITE_MAX_VARIABLE_NUMBER`).
|
|
81
|
+
|
|
76
82
|
## License
|
|
77
83
|
|
|
78
84
|
MIT
|
package/dist/remove.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { find } from "./find.js";
|
|
2
|
+
const BATCH_SIZE = +process.env.VALTHERA_SQLITE_BATCH_SIZE || 500;
|
|
2
3
|
export async function remove(slv, query, one) {
|
|
3
4
|
const { collection } = query;
|
|
4
5
|
const toDelete = await find(slv, {
|
|
@@ -10,7 +11,10 @@ export async function remove(slv, query, one) {
|
|
|
10
11
|
if (!toDelete.length)
|
|
11
12
|
return [];
|
|
12
13
|
const key = slv.primaryKey[collection] || "_id";
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
for (let i = 0; i < toDelete.length; i += BATCH_SIZE) {
|
|
15
|
+
const batch = toDelete.slice(i, i + BATCH_SIZE);
|
|
16
|
+
const stmt = await slv._prepare(`DELETE FROM "${collection}" WHERE "${key}" IN (${batch.map(() => "?").join(", ")})`);
|
|
17
|
+
await Promise.resolve(stmt.run(...batch.map(d => d[key])));
|
|
18
|
+
}
|
|
15
19
|
return toDelete;
|
|
16
20
|
}
|