@wxn0brp/db-storage-sqlite 0.110.1 → 0.110.2
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/find.js +5 -5
- package/package.json +1 -1
package/dist/find.js
CHANGED
|
@@ -4,15 +4,15 @@ import { toSqlValue } from "./index.js";
|
|
|
4
4
|
export async function find(slv, config) {
|
|
5
5
|
const { collection, search } = config;
|
|
6
6
|
let sqlResult = [];
|
|
7
|
-
|
|
7
|
+
const baseKeys = Object.keys(search)
|
|
8
|
+
.filter(k => search[k] !== undefined)
|
|
9
|
+
.filter(k => !k.startsWith("$"))
|
|
10
|
+
.filter(k => typeof search[k] !== "object");
|
|
11
|
+
if (typeof search === "function" || baseKeys.length === 0) {
|
|
8
12
|
const stmt = await slv._prepare(`SELECT * FROM ${collection}`);
|
|
9
13
|
sqlResult = await Promise.resolve(stmt.all());
|
|
10
14
|
}
|
|
11
15
|
else {
|
|
12
|
-
const baseKeys = Object.keys(search)
|
|
13
|
-
.filter(k => search[k] !== undefined)
|
|
14
|
-
.filter(k => !k.startsWith("$"))
|
|
15
|
-
.filter(k => typeof search[k] !== "object");
|
|
16
16
|
const baseSql = `SELECT * FROM ${collection} WHERE ${baseKeys.map(k => `${k} = ?`).join(" AND ")}`;
|
|
17
17
|
const baseValues = baseKeys.map(k => toSqlValue(search[k]));
|
|
18
18
|
const stmt = await slv._prepare(baseSql);
|