@tmlmobilidade/sqlite 20260519.2046.53 → 20260525.1333.38
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/sqlite-db.d.ts +8 -2
- package/dist/sqlite-db.js +12 -1
- package/package.json +3 -2
package/dist/sqlite-db.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SQLiteDatabaseConfig, SQLiteTable } from './types.js';
|
|
2
|
-
import
|
|
2
|
+
import { type Database } from 'better-sqlite3';
|
|
3
3
|
import { Readable } from 'node:stream';
|
|
4
4
|
export declare class SQLiteDatabase {
|
|
5
5
|
databaseInstance: Database;
|
|
@@ -34,6 +34,12 @@ export declare class SQLiteTableInstance<T> {
|
|
|
34
34
|
* Clears all entries from the map.
|
|
35
35
|
*/
|
|
36
36
|
clear(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Finds all distinct values for a column in the table.
|
|
39
|
+
* @param column The column to find distinct values for.
|
|
40
|
+
* @returns An array of distinct values.
|
|
41
|
+
*/
|
|
42
|
+
distinct<K extends keyof T>(col: K): T[K][];
|
|
37
43
|
/**
|
|
38
44
|
* Flush current buffer into DB synchronously.
|
|
39
45
|
*/
|
|
@@ -52,7 +58,7 @@ export declare class SQLiteTableInstance<T> {
|
|
|
52
58
|
* @returns True if the row exists, false otherwise.
|
|
53
59
|
*/
|
|
54
60
|
has<K extends keyof T>(col: K, value: T[K]): boolean;
|
|
55
|
-
query(sqlQuery?: string, params?: (boolean | number | string)[]):
|
|
61
|
+
query(sqlQuery?: string, params?: (boolean | number | string)[]): unknown[];
|
|
56
62
|
/**
|
|
57
63
|
* Iterator to go through all rows in the table.
|
|
58
64
|
*/
|
package/dist/sqlite-db.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* * */
|
|
2
|
+
import { Logger } from '@tmlmobilidade/logger';
|
|
2
3
|
import { generateRandomString } from '@tmlmobilidade/strings';
|
|
3
4
|
import BSQLite3 from 'better-sqlite3';
|
|
4
5
|
import fs from 'node:fs';
|
|
@@ -24,6 +25,7 @@ export class SQLiteDatabase {
|
|
|
24
25
|
if (!config.instancePath && !config.memory) {
|
|
25
26
|
config.instancePath = `/tmp/${config.instanceName}/${config.instanceName}.db`;
|
|
26
27
|
fs.mkdirSync(`/tmp/${config.instanceName}`, { recursive: true });
|
|
28
|
+
Logger.info(`[SQLITE] Created database at ${config.instancePath}`);
|
|
27
29
|
}
|
|
28
30
|
if (!config.databaseInstance) {
|
|
29
31
|
config.databaseInstance = new BSQLite3(config.memory ? ':memory:' : config.instancePath);
|
|
@@ -109,6 +111,15 @@ export class SQLiteTableInstance {
|
|
|
109
111
|
.prepare(`DELETE FROM ${this.tableName}`)
|
|
110
112
|
.run();
|
|
111
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Finds all distinct values for a column in the table.
|
|
116
|
+
* @param column The column to find distinct values for.
|
|
117
|
+
* @returns An array of distinct values.
|
|
118
|
+
*/
|
|
119
|
+
distinct(col) {
|
|
120
|
+
const sql = `SELECT DISTINCT ${String(col)} FROM ${this.tableName}`;
|
|
121
|
+
return this.databaseInstance.prepare(sql).all().map(row => row[String(col)]);
|
|
122
|
+
}
|
|
112
123
|
/**
|
|
113
124
|
* Flush current buffer into DB synchronously.
|
|
114
125
|
*/
|
|
@@ -158,7 +169,7 @@ export class SQLiteTableInstance {
|
|
|
158
169
|
return !!this.databaseInstance.prepare(sql).get(value);
|
|
159
170
|
}
|
|
160
171
|
query(sqlQuery = '', params = []) {
|
|
161
|
-
return this.databaseInstance.prepare(sqlQuery).
|
|
172
|
+
return this.databaseInstance.prepare(sqlQuery).all(...params);
|
|
162
173
|
}
|
|
163
174
|
/**
|
|
164
175
|
* Iterator to go through all rows in the table.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmlmobilidade/sqlite",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "20260525.1333.38",
|
|
4
4
|
"author": {
|
|
5
5
|
"email": "iso@tmlmobilidade.pt",
|
|
6
6
|
"name": "TML-ISO"
|
|
@@ -36,13 +36,14 @@
|
|
|
36
36
|
"watch": "tsc-watch --onSuccess 'resolve-tspaths'"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
+
"@tmlmobilidade/logger": "*",
|
|
39
40
|
"@tmlmobilidade/strings": "*",
|
|
40
41
|
"better-sqlite3": "12.10.0"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
44
|
"@tmlmobilidade/tsconfig": "*",
|
|
44
45
|
"@types/better-sqlite3": "7.6.13",
|
|
45
|
-
"@types/node": "25.
|
|
46
|
+
"@types/node": "25.9.1",
|
|
46
47
|
"resolve-tspaths": "0.8.23",
|
|
47
48
|
"tsc-watch": "7.2.0",
|
|
48
49
|
"typescript": "5.9.3"
|