@oino-ts/db 0.5.2 → 0.6.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/cjs/OINODbFactory.js +4 -0
- package/dist/cjs/OINODbSqlParams.js +1 -1
- package/dist/esm/OINODbFactory.js +4 -0
- package/dist/esm/OINODbSqlParams.js +1 -1
- package/dist/types/OINODb.d.ts +6 -1
- package/package.json +3 -3
- package/src/OINODb.ts +7 -1
- package/src/OINODbApi.test.ts +2 -2
- package/src/OINODbFactory.ts +4 -0
- package/src/OINODbSqlParams.ts +1 -1
|
@@ -39,6 +39,10 @@ class OINODbFactory {
|
|
|
39
39
|
throw new Error("Unsupported database type: " + params.type);
|
|
40
40
|
}
|
|
41
41
|
await result.connect();
|
|
42
|
+
const validate_res = await result.validate();
|
|
43
|
+
if (validate_res.success == false) {
|
|
44
|
+
throw new Error("Database connection validation failed: " + validate_res.statusMessage);
|
|
45
|
+
}
|
|
42
46
|
return result;
|
|
43
47
|
}
|
|
44
48
|
/**
|
|
@@ -412,7 +412,7 @@ class OINODbSqlAggregate {
|
|
|
412
412
|
result += f.printSqlColumnName() + ",";
|
|
413
413
|
}
|
|
414
414
|
}
|
|
415
|
-
|
|
415
|
+
// OINOLog.debug("OINODbSqlAggregate.toSql", {result:result})
|
|
416
416
|
return result.substring(0, result.length - 1);
|
|
417
417
|
}
|
|
418
418
|
/**
|
|
@@ -36,6 +36,10 @@ export class OINODbFactory {
|
|
|
36
36
|
throw new Error("Unsupported database type: " + params.type);
|
|
37
37
|
}
|
|
38
38
|
await result.connect();
|
|
39
|
+
const validate_res = await result.validate();
|
|
40
|
+
if (validate_res.success == false) {
|
|
41
|
+
throw new Error("Database connection validation failed: " + validate_res.statusMessage);
|
|
42
|
+
}
|
|
39
43
|
return result;
|
|
40
44
|
}
|
|
41
45
|
/**
|
|
@@ -406,7 +406,7 @@ export class OINODbSqlAggregate {
|
|
|
406
406
|
result += f.printSqlColumnName() + ",";
|
|
407
407
|
}
|
|
408
408
|
}
|
|
409
|
-
OINOLog.debug("OINODbSqlAggregate.toSql", {
|
|
409
|
+
// OINOLog.debug("OINODbSqlAggregate.toSql", {result:result})
|
|
410
410
|
return result.substring(0, result.length - 1);
|
|
411
411
|
}
|
|
412
412
|
/**
|
package/dist/types/OINODb.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OINODbParams, OINODbApi, OINODataCell, OINODataRow } from "./index.js";
|
|
1
|
+
import { OINODbParams, OINODbApi, OINODataCell, OINODataRow, OINOResult } from "./index.js";
|
|
2
2
|
/**
|
|
3
3
|
* Base class for database abstraction, implementing methods for connecting, making queries and parsing/formatting data
|
|
4
4
|
* between SQL and serialization formats.
|
|
@@ -18,6 +18,11 @@ export declare abstract class OINODb {
|
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
20
|
abstract connect(): Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* Validate connection to database is working.
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
abstract validate(): Promise<OINOResult>;
|
|
21
26
|
/**
|
|
22
27
|
* Print a table name using database specific SQL escaping.
|
|
23
28
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oino-ts/db",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "OINO TS library package for publishing an SQL database tables as a REST API.",
|
|
5
5
|
"author": "Matias Kiviniemi (pragmatta)",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"module": "./dist/esm/index.js",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@oino-ts/common": "0.
|
|
22
|
+
"@oino-ts/common": "0.6.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^20.14.10",
|
|
26
26
|
"@types/bun": "^1.1.14",
|
|
27
|
-
"@oino-ts/types": "0.
|
|
27
|
+
"@oino-ts/types": "0.6.0",
|
|
28
28
|
"typedoc": "^0.25.13"
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
package/src/OINODb.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { OINODbParams, OINODbApi, OINODataCell, OINO_ERROR_PREFIX, OINODataRow, OINODB_EMPTY_ROW } from "./index.js"
|
|
7
|
+
import { OINODbParams, OINODbApi, OINODataCell, OINO_ERROR_PREFIX, OINODataRow, OINODB_EMPTY_ROW, OINOResult } from "./index.js"
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Base class for database abstraction, implementing methods for connecting, making queries and parsing/formatting data
|
|
@@ -33,6 +33,12 @@ export abstract class OINODb {
|
|
|
33
33
|
*/
|
|
34
34
|
abstract connect(): Promise<boolean>
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Validate connection to database is working.
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
abstract validate(): Promise<OINOResult>
|
|
41
|
+
|
|
36
42
|
/**
|
|
37
43
|
* Print a table name using database specific SQL escaping.
|
|
38
44
|
*
|
package/src/OINODbApi.test.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { OINODbBunSqlite } from "@oino-ts/db-bunsqlite"
|
|
|
12
12
|
import { OINODbPostgresql } from "@oino-ts/db-postgresql"
|
|
13
13
|
import { OINODbMariadb } from "@oino-ts/db-mariadb"
|
|
14
14
|
import { OINODbMsSql } from "@oino-ts/db-mssql"
|
|
15
|
-
import { OINODbSqlAggregate } from "./OINODbSqlParams.js";
|
|
15
|
+
import { OINODbSqlAggregate, OINODbSqlSelect } from "./OINODbSqlParams.js";
|
|
16
16
|
|
|
17
17
|
const OINODB_POSTGRESQL_TOKEN = process.env.OINODB_POSTGRESQL_TOKEN || console.error("OINODB_POSTGRESQL_TOKEN not set") || ""
|
|
18
18
|
const OINODB_MARIADB_TOKEN = process.env.OINODB_MARIADB_TOKEN || console.error("OINODB_MARIADB_TOKEN not set") || ""
|
|
@@ -67,7 +67,7 @@ const api_tests:OINOTestParams[] = [
|
|
|
67
67
|
name: "API 4",
|
|
68
68
|
apiParams: { apiName: "OrderDetails", tableName: "OrderDetails" },
|
|
69
69
|
requestParams: {
|
|
70
|
-
sqlParams: { aggregate: OINODbSqlAggregate.parse("count(ProductID),avg(UnitPrice),sum(Quantity),
|
|
70
|
+
sqlParams: { aggregate: OINODbSqlAggregate.parse("count(OrderID),count(ProductID),avg(UnitPrice),sum(Quantity)"), select: OINODbSqlSelect.parse("OrderID,ProductID,UnitPrice,Quantity,Discount"), order: OINODbSqlOrder.parse("Discount asc") }
|
|
71
71
|
},
|
|
72
72
|
postRow: [10249,77,12.34,56,0],
|
|
73
73
|
putRow: [10249,77,23.45,67,0]
|
package/src/OINODbFactory.ts
CHANGED
|
@@ -40,6 +40,10 @@ export class OINODbFactory {
|
|
|
40
40
|
throw new Error("Unsupported database type: " + params.type)
|
|
41
41
|
}
|
|
42
42
|
await result.connect()
|
|
43
|
+
const validate_res = await result.validate()
|
|
44
|
+
if (validate_res.success == false) {
|
|
45
|
+
throw new Error("Database connection validation failed: " + validate_res.statusMessage)
|
|
46
|
+
}
|
|
43
47
|
return result
|
|
44
48
|
}
|
|
45
49
|
|
package/src/OINODbSqlParams.ts
CHANGED
|
@@ -411,7 +411,7 @@ export class OINODbSqlAggregate {
|
|
|
411
411
|
result += f.printSqlColumnName() + ","
|
|
412
412
|
}
|
|
413
413
|
}
|
|
414
|
-
OINOLog.debug("OINODbSqlAggregate.toSql", {result:result})
|
|
414
|
+
// OINOLog.debug("OINODbSqlAggregate.toSql", {result:result})
|
|
415
415
|
return result.substring(0, result.length-1)
|
|
416
416
|
}
|
|
417
417
|
|