inibase 1.5.4 → 1.5.5
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 +18 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -195,7 +195,7 @@ export default class Inibase {
|
|
|
195
195
|
await writeFile(join(tablePath, "0.schema"), "");
|
|
196
196
|
await writeFile(join(tablePath, "0-0.pagination"), "");
|
|
197
197
|
}
|
|
198
|
-
// Function to replace the string in one schema
|
|
198
|
+
// Function to replace the string in one schema file
|
|
199
199
|
async replaceStringInFile(filePath, targetString, replaceString) {
|
|
200
200
|
const data = await readFile(filePath, "utf8");
|
|
201
201
|
if (data.includes(targetString)) {
|
|
@@ -223,7 +223,7 @@ export default class Inibase {
|
|
|
223
223
|
value: schemaIdFilePath ? Number(parse(schemaIdFilePath).name) : 0,
|
|
224
224
|
};
|
|
225
225
|
schema = Utils.addIdToSchema(schema, lastSchemaID);
|
|
226
|
-
// if schema
|
|
226
|
+
// if schema file exists, update columns files names based on field id
|
|
227
227
|
if ((await File.isExists(join(tablePath, `schema.${this.schemaFileExtension}`))) &&
|
|
228
228
|
table.schema?.length) {
|
|
229
229
|
const replaceOldPathes = Utils.findChangedProperties(this.schemaToIdsPath(tableName, table.schema), this.schemaToIdsPath(tableName, schema));
|
|
@@ -333,7 +333,7 @@ export default class Inibase {
|
|
|
333
333
|
throw this.createError("TABLE_NOT_EXISTS", tableName);
|
|
334
334
|
if (!globalConfig[this.databasePath].tables.has(tableName) ||
|
|
335
335
|
globalConfig[this.databasePath].tables.get(tableName).timestamp !==
|
|
336
|
-
(await File.getFileDate(join(tablePath,
|
|
336
|
+
(await File.getFileDate(join(tablePath, `schema.${this.schemaFileExtension}`))))
|
|
337
337
|
globalConfig[this.databasePath].tables.set(tableName, {
|
|
338
338
|
schema: await this.getTableSchema(tableName),
|
|
339
339
|
config: {
|
|
@@ -342,7 +342,7 @@ export default class Inibase {
|
|
|
342
342
|
prepend: await File.isExists(join(tablePath, ".prepend.config")),
|
|
343
343
|
decodeID: await File.isExists(join(tablePath, ".decodeID.config")),
|
|
344
344
|
},
|
|
345
|
-
timestamp: await File.getFileDate(join(tablePath,
|
|
345
|
+
timestamp: await File.getFileDate(join(tablePath, `schema.${this.schemaFileExtension}`)),
|
|
346
346
|
});
|
|
347
347
|
return globalConfig[this.databasePath].tables.get(tableName);
|
|
348
348
|
}
|
|
@@ -1018,9 +1018,9 @@ export default class Inibase {
|
|
|
1018
1018
|
else if (allTrue)
|
|
1019
1019
|
return null;
|
|
1020
1020
|
}
|
|
1021
|
-
let searchOperator
|
|
1022
|
-
let searchComparedAtValue
|
|
1023
|
-
let searchLogicalOperator
|
|
1021
|
+
let searchOperator;
|
|
1022
|
+
let searchComparedAtValue;
|
|
1023
|
+
let searchLogicalOperator;
|
|
1024
1024
|
if (Utils.isObject(value)) {
|
|
1025
1025
|
/* nested object with .and / .or inside */
|
|
1026
1026
|
const nestedAnd = value.and;
|
|
@@ -1353,18 +1353,22 @@ export default class Inibase {
|
|
|
1353
1353
|
(Utils.isObject(RETURN) && !Object.keys(RETURN).length) ||
|
|
1354
1354
|
(Array.isArray(RETURN) && !RETURN.length))
|
|
1355
1355
|
return null;
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1356
|
+
let total;
|
|
1357
|
+
if (Utils.isObject(where))
|
|
1358
|
+
total = Math.min(...[...this.totalItems.entries()]
|
|
1359
1359
|
.filter(([k]) => k.startsWith(`${tableName}-`))
|
|
1360
1360
|
.map(([, v]) => v));
|
|
1361
|
+
else
|
|
1362
|
+
total = this.totalItems.has(`${tableName}-*`)
|
|
1363
|
+
? this.totalItems.get(`${tableName}-*`)
|
|
1364
|
+
: Math.max(...[...this.totalItems.entries()]
|
|
1365
|
+
.filter(([k]) => k.startsWith(`${tableName}-`))
|
|
1366
|
+
.map(([, v]) => v));
|
|
1361
1367
|
this.pageInfo[tableName] = {
|
|
1362
1368
|
...(({ columns, ...restOfOptions }) => restOfOptions)(options),
|
|
1363
1369
|
perPage: Array.isArray(RETURN) ? RETURN.length : 1,
|
|
1364
|
-
totalPages: options.perPage < 0
|
|
1365
|
-
|
|
1366
|
-
: Math.ceil(greatestTotalItems / options.perPage),
|
|
1367
|
-
total: greatestTotalItems,
|
|
1370
|
+
totalPages: options.perPage < 0 ? 1 : Math.ceil(total / options.perPage),
|
|
1371
|
+
total: total,
|
|
1368
1372
|
};
|
|
1369
1373
|
return onlyOne && Array.isArray(RETURN) ? RETURN[0] : RETURN;
|
|
1370
1374
|
}
|