@wxn0brp/db-storage-sqlite 0.90.0 → 0.100.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/dist/find.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { Data } from "@wxn0brp/db-core/types/data";
2
- import { VQuery } from "@wxn0brp/db-core/types/query";
2
+ import { FindQuery } from "@wxn0brp/db-core/types/query";
3
3
  import { SQLiteValthera } from "./index.js";
4
- export declare function find(slv: SQLiteValthera, config: VQuery): Promise<Data[]>;
4
+ export declare function find(slv: SQLiteValthera, config: FindQuery): Promise<Data[]>;
package/dist/find.js CHANGED
@@ -1,8 +1,7 @@
1
- import { compareSafe } from "@wxn0brp/db-core/utils/compare";
1
+ import { findUtil } from "@wxn0brp/db-core/utils/action";
2
2
  import { hasFieldsAdvanced } from "@wxn0brp/db-core/utils/hasFieldsAdvanced";
3
- import { updateFindObject } from "@wxn0brp/db-core/utils/updateFindObject";
4
3
  export async function find(slv, config) {
5
- const { collection, search, findOpts, dbFindOpts, context } = config;
4
+ const { collection, search, context } = config;
6
5
  let sqlResult = [];
7
6
  if (typeof search === "function" || Object.keys(search).length === 0) {
8
7
  const stmt = await slv._prepare(`SELECT * FROM ${collection}`);
@@ -19,21 +18,9 @@ export async function find(slv, config) {
19
18
  sqlResult = await Promise.resolve(stmt.all(...baseValues));
20
19
  }
21
20
  let result = sqlResult.filter(entry => typeof search === "function" ? search(entry, context) : hasFieldsAdvanced(entry, search));
22
- const { reverse = false, limit = -1, offset = 0, sortBy, sortAsc = true } = dbFindOpts;
23
- if (reverse)
24
- result.reverse();
25
- if (sortBy) {
26
- const dir = sortAsc ? 1 : -1;
27
- result.sort((a, b) => compareSafe(a[sortBy], b[sortBy]) * dir);
28
- const start = offset;
29
- const end = limit !== -1 ? offset + limit : undefined;
30
- result = result.slice(start, end);
31
- }
32
- else {
33
- if (offset > 0)
34
- result.splice(0, offset);
35
- if (limit > 0)
36
- result.splice(limit);
37
- }
38
- return result.length ? result.map(res => updateFindObject(res, findOpts)) : [];
21
+ return findUtil(config, {
22
+ find() {
23
+ return result;
24
+ }
25
+ }, [null]);
39
26
  }
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ValtheraClass } from "@wxn0brp/db-core";
2
2
  import { ActionsBase } from "@wxn0brp/db-core/base/actions";
3
3
  import { Data } from "@wxn0brp/db-core/types/data";
4
- import { VQuery } from "@wxn0brp/db-core/types/query";
4
+ import * as Query from "@wxn0brp/db-core/types/query";
5
5
  import { SupportedDB, VStatement } from "./types.js";
6
6
  export declare class SQLiteValthera extends ActionsBase {
7
7
  db: SupportedDB;
@@ -9,15 +9,15 @@ export declare class SQLiteValthera extends ActionsBase {
9
9
  constructor(db: SupportedDB);
10
10
  _prepare(sql: string): Promise<VStatement>;
11
11
  getCollections(): Promise<string[]>;
12
- add(config: VQuery): Promise<Data>;
13
- find(config: VQuery): Promise<Data[]>;
14
- findOne(config: VQuery): Promise<Data | null>;
15
- update(config: VQuery): Promise<any[]>;
16
- updateOne(config: VQuery): Promise<any>;
17
- remove(config: VQuery): Promise<Data[]>;
18
- removeOne(config: VQuery): Promise<Data>;
19
- removeCollection(config: VQuery): Promise<boolean>;
20
- issetCollection(config: VQuery): Promise<boolean>;
21
- ensureCollection(config: VQuery): Promise<boolean>;
12
+ add(config: Query.AddQuery): Promise<Data>;
13
+ find(config: Query.FindQuery): Promise<Data[]>;
14
+ findOne(config: Query.FindQuery): Promise<Data | null>;
15
+ update(config: Query.UpdateQuery): Promise<import("@wxn0brp/db-core/types/data").DataInternal[]>;
16
+ updateOne(config: Query.UpdateQuery): Promise<import("@wxn0brp/db-core/types/data").DataInternal>;
17
+ remove(config: Query.RemoveQuery): Promise<import("@wxn0brp/db-core/types/data").DataInternal[]>;
18
+ removeOne(config: Query.RemoveQuery): Promise<import("@wxn0brp/db-core/types/data").DataInternal>;
19
+ removeCollection(collection: string): Promise<boolean>;
20
+ issetCollection(collection: string): Promise<boolean>;
21
+ ensureCollection(collection: string): Promise<boolean>;
22
22
  }
23
23
  export declare function createSQLiteValthera(sqlDB: SupportedDB): ValtheraClass;
package/dist/index.js CHANGED
@@ -48,36 +48,33 @@ export class SQLiteValthera extends ActionsBase {
48
48
  return result.length ? result[0] : null;
49
49
  }
50
50
  update(config) {
51
- return update(this, config.collection, false, config.search, config.updater, config.context);
51
+ return update(this, config, false);
52
52
  }
53
53
  async updateOne(config) {
54
- const res = await update(this, config.collection, true, config.search, config.updater, config.context);
54
+ const res = await update(this, config, true);
55
55
  return res[0] || null;
56
56
  }
57
57
  remove(config) {
58
- return remove(this, config.collection, false, config.search, config.context);
58
+ return remove(this, config, false);
59
59
  }
60
60
  async removeOne(config) {
61
- const res = await remove(this, config.collection, true, config.search, config.context);
61
+ const res = await remove(this, config, true);
62
62
  return res[0] || null;
63
63
  }
64
- async removeCollection(config) {
65
- const { collection } = config;
64
+ async removeCollection(collection) {
66
65
  const sql = `DROP TABLE IF EXISTS ${collection}`;
67
66
  const stmt = await this._prepare(sql);
68
67
  await Promise.resolve(stmt.run());
69
68
  return true;
70
69
  }
71
- async issetCollection(config) {
72
- const { collection } = config;
70
+ async issetCollection(collection) {
73
71
  const sql = `SELECT name FROM sqlite_master WHERE type='table' AND name=?`;
74
72
  const stmt = await this._prepare(sql);
75
73
  const result = await Promise.resolve(stmt.all(collection));
76
74
  return result.length > 0;
77
75
  }
78
- async ensureCollection(config) {
79
- const { collection } = config;
80
- const issetCollection = await this.issetCollection(config);
76
+ async ensureCollection(collection) {
77
+ const issetCollection = await this.issetCollection(collection);
81
78
  if (!issetCollection) {
82
79
  throw new Error(`Collection "${collection}" not found. Please create it first.`);
83
80
  }
package/dist/remove.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { Search } from "@wxn0brp/db-core/types/arg";
2
- import { Data } from "@wxn0brp/db-core/types/data";
3
- import { VContext } from "@wxn0brp/db-core/types/types";
1
+ import { DataInternal } from "@wxn0brp/db-core/types/data";
2
+ import { RemoveQuery } from "@wxn0brp/db-core/types/query";
4
3
  import { SQLiteValthera } from "./index.js";
5
- export declare function remove(slv: SQLiteValthera, collection: string, one: boolean, search: Search, context?: VContext): Promise<Data[]>;
4
+ export declare function remove(slv: SQLiteValthera, query: RemoveQuery, one: boolean): Promise<DataInternal[]>;
package/dist/remove.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { hasFieldsAdvanced } from "@wxn0brp/db-core/utils/hasFieldsAdvanced";
2
- export async function remove(slv, collection, one, search, context = {}) {
2
+ export async function remove(slv, query, one) {
3
+ const { collection, search, context } = query;
3
4
  let stmt = await slv._prepare(`SELECT * FROM "${collection}"`);
4
5
  const allEntries = await Promise.resolve(stmt.all());
5
6
  const toDelete = [];
package/dist/update.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Search, Updater } from "@wxn0brp/db-core/types/arg";
2
- import { VContext } from "@wxn0brp/db-core/types/types";
1
+ import { DataInternal } from "@wxn0brp/db-core/types/data";
2
+ import { UpdateQuery } from "@wxn0brp/db-core/types/query";
3
3
  import { SQLiteValthera } from "./index.js";
4
- export declare function update(slv: SQLiteValthera, collection: string, one: boolean, search: Search, updater: Updater, context?: VContext): Promise<any[]>;
4
+ export declare function update(slv: SQLiteValthera, query: UpdateQuery, one: boolean): Promise<DataInternal[]>;
package/dist/update.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { hasFieldsAdvanced } from "@wxn0brp/db-core/utils/hasFieldsAdvanced";
2
- export async function update(slv, collection, one, search, updater, context = {}) {
2
+ export async function update(slv, query, one) {
3
+ const { collection, search, updater, context } = query;
3
4
  const stmt = await slv._prepare(`SELECT * FROM "${collection}"`);
4
5
  const allEntries = await Promise.resolve(stmt.all());
5
6
  const matched = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/db-storage-sqlite",
3
- "version": "0.90.0",
3
+ "version": "0.100.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "A pure SQLite storage adapter for the ValtheraDB database library",
@@ -22,14 +22,14 @@
22
22
  "@types/better-sqlite3": "^7.6.13",
23
23
  "@types/bun": "*",
24
24
  "@types/node": "*",
25
- "@wxn0brp/db-core": "~0.9.0",
26
- "better-sqlite3": "^12.6.2",
25
+ "@wxn0brp/db-core": "~0.10.0",
26
+ "better-sqlite3": "^12.8.0",
27
27
  "tsc-alias": "*",
28
28
  "typescript": "*"
29
29
  },
30
30
  "peerDependencies": {
31
- "@wxn0brp/db-core": "~0.9.0",
32
- "better-sqlite3": "^12.6.2"
31
+ "@wxn0brp/db-core": "~0.10.0",
32
+ "better-sqlite3": "^12.8.0"
33
33
  },
34
34
  "peerDependenciesMeta": {
35
35
  "@wxn0brp/db-core": {