inibase 1.0.0-rc.100 → 1.0.0-rc.101
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/dist/index.js +31 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1249,17 +1249,24 @@ export default class Inibase {
|
|
|
1249
1249
|
* @return {boolean | null} {(Promise<boolean | null>)}
|
|
1250
1250
|
*/
|
|
1251
1251
|
async delete(tableName, where, _id) {
|
|
1252
|
-
const renameList = [];
|
|
1253
1252
|
const tablePath = join(this.databasePath, tableName);
|
|
1254
1253
|
await this.throwErrorIfTableEmpty(tableName);
|
|
1255
1254
|
if (!where) {
|
|
1256
1255
|
try {
|
|
1257
1256
|
await File.lock(join(tablePath, ".tmp"));
|
|
1257
|
+
let lastId;
|
|
1258
|
+
if (await File.isExists(join(tablePath, ".cache", ".pagination")))
|
|
1259
|
+
lastId = (await readFile(join(tablePath, ".cache", ".pagination"), "utf8"))
|
|
1260
|
+
.split(",")
|
|
1261
|
+
.map(Number)[0];
|
|
1262
|
+
else
|
|
1263
|
+
lastId = Number(Object.keys((await File.get(join(tablePath, `id${this.getFileExtension(tableName)}`), -1, "number", undefined, this.salt, true))?.[0] ?? 0));
|
|
1258
1264
|
await Promise.all((await readdir(tablePath))
|
|
1259
1265
|
?.filter((fileName) => fileName.endsWith(this.getFileExtension(tableName)))
|
|
1260
1266
|
.map(async (file) => unlink(join(tablePath, file))));
|
|
1261
1267
|
if (this.tables[tableName].config.cache)
|
|
1262
1268
|
await this.clearCache(tableName);
|
|
1269
|
+
await writeFile(join(tablePath, ".cache", ".pagination"), `${lastId},0`);
|
|
1263
1270
|
return true;
|
|
1264
1271
|
}
|
|
1265
1272
|
finally {
|
|
@@ -1276,18 +1283,34 @@ export default class Inibase {
|
|
|
1276
1283
|
// "where" in this case, is the line(s) number(s) and not id(s)
|
|
1277
1284
|
const files = (await readdir(tablePath))?.filter((fileName) => fileName.endsWith(this.getFileExtension(tableName)));
|
|
1278
1285
|
if (files.length) {
|
|
1286
|
+
const renameList = [];
|
|
1279
1287
|
try {
|
|
1280
1288
|
await File.lock(join(tablePath, ".tmp"));
|
|
1281
|
-
|
|
1282
|
-
await
|
|
1283
|
-
|
|
1284
|
-
await this.clearCache(tableName);
|
|
1285
|
-
if (await File.isExists(join(tablePath, ".cache", ".pagination"))) {
|
|
1286
|
-
const [lastId, totalItems] = (await readFile(join(tablePath, ".cache", ".pagination"), "utf8"))
|
|
1289
|
+
let lastId;
|
|
1290
|
+
if (await File.isExists(join(tablePath, ".cache", ".pagination")))
|
|
1291
|
+
[lastId, this.totalItems[`${tableName}-*`]] = (await readFile(join(tablePath, ".cache", ".pagination"), "utf8"))
|
|
1287
1292
|
.split(",")
|
|
1288
1293
|
.map(Number);
|
|
1289
|
-
|
|
1294
|
+
else {
|
|
1295
|
+
lastId = Number(Object.keys((await File.get(join(tablePath, `id${this.getFileExtension(tableName)}`), -1, "number", undefined, this.salt, true))?.[0] ?? 0));
|
|
1296
|
+
if (!this.totalItems[`${tableName}-*`])
|
|
1297
|
+
this.totalItems[`${tableName}-*`] = await File.count(join(tablePath, `id${this.getFileExtension(tableName)}`));
|
|
1298
|
+
}
|
|
1299
|
+
if (this.totalItems[`${tableName}-*`] &&
|
|
1300
|
+
this.totalItems[`${tableName}-*`] -
|
|
1301
|
+
(Array.isArray(where) ? where.length : 1) >
|
|
1302
|
+
0) {
|
|
1303
|
+
await Promise.all(files.map(async (file) => renameList.push(await File.remove(join(tablePath, file), where))));
|
|
1304
|
+
await Promise.all(renameList.map(async ([tempPath, filePath]) => rename(tempPath, filePath)));
|
|
1290
1305
|
}
|
|
1306
|
+
else
|
|
1307
|
+
await Promise.all((await readdir(tablePath))
|
|
1308
|
+
?.filter((fileName) => fileName.endsWith(this.getFileExtension(tableName)))
|
|
1309
|
+
.map(async (file) => unlink(join(tablePath, file))));
|
|
1310
|
+
if (this.tables[tableName].config.cache)
|
|
1311
|
+
await this.clearCache(tableName);
|
|
1312
|
+
await writeFile(join(tablePath, ".cache", ".pagination"), `${lastId},${this.totalItems[`${tableName}-*`] -
|
|
1313
|
+
(Array.isArray(where) ? where.length : 1)}`);
|
|
1291
1314
|
return true;
|
|
1292
1315
|
}
|
|
1293
1316
|
finally {
|