@oino-ts/db-mariadb 1.1.0 → 1.1.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/cjs/OINODbMariadb.js +26 -14
- package/dist/esm/OINODbMariadb.js +26 -14
- package/dist/types/OINODbMariadb.d.ts +5 -0
- package/package.json +4 -4
- package/src/OINODbMariadb.ts +27 -14
|
@@ -307,13 +307,7 @@ class OINODbMariadb extends db_1.OINODb {
|
|
|
307
307
|
const sql = this._getValidateSql(this.dbParams.database);
|
|
308
308
|
const sql_res = await this._query(sql);
|
|
309
309
|
if (sql_res.isEmpty()) {
|
|
310
|
-
result.setError(400, "DB returned no rows for
|
|
311
|
-
}
|
|
312
|
-
else if (sql_res.getRow().length == 0) {
|
|
313
|
-
result.setError(400, "DB returned no values for database!", "OINODbMariadb.validate");
|
|
314
|
-
}
|
|
315
|
-
else if (sql_res.getRow()[0] == "0") {
|
|
316
|
-
result.setError(400, "DB returned no schema for database!", "OINODbMariadb.validate");
|
|
310
|
+
result.setError(400, "DB returned no rows for schema!", "OINODbMariadb.validate");
|
|
317
311
|
}
|
|
318
312
|
else {
|
|
319
313
|
this.isValidated = true;
|
|
@@ -369,12 +363,12 @@ class OINODbMariadb extends db_1.OINODb {
|
|
|
369
363
|
}
|
|
370
364
|
_getSchemaSql(dbName, tableName) {
|
|
371
365
|
const sql = `SELECT
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
366
|
+
C.COLUMN_NAME,
|
|
367
|
+
C.COLUMN_TYPE,
|
|
368
|
+
C.IS_NULLABLE,
|
|
369
|
+
C.COLUMN_KEY,
|
|
370
|
+
C.COLUMN_DEFAULT,
|
|
371
|
+
C.EXTRA,
|
|
378
372
|
KCU.CONSTRAINT_NAME AS ForeignKeyName
|
|
379
373
|
FROM information_schema.COLUMNS C
|
|
380
374
|
LEFT JOIN information_schema.KEY_COLUMN_USAGE KCU ON KCU.TABLE_SCHEMA = C.TABLE_SCHEMA AND KCU.TABLE_NAME = C.TABLE_NAME AND C.COLUMN_NAME = KCU.COLUMN_NAME and KCU.REFERENCED_TABLE_NAME IS NOT NULL
|
|
@@ -384,7 +378,7 @@ ORDER BY C.ORDINAL_POSITION;`;
|
|
|
384
378
|
}
|
|
385
379
|
_getValidateSql(dbName) {
|
|
386
380
|
const sql = `SELECT
|
|
387
|
-
Count(
|
|
381
|
+
Count(C.COLUMN_NAME) AS COLUMN_COUNT
|
|
388
382
|
FROM information_schema.COLUMNS C
|
|
389
383
|
LEFT JOIN information_schema.KEY_COLUMN_USAGE KCU ON KCU.TABLE_SCHEMA = C.TABLE_SCHEMA AND KCU.TABLE_NAME = C.TABLE_NAME AND C.COLUMN_NAME = KCU.COLUMN_NAME and KCU.REFERENCED_TABLE_NAME IS NOT NULL
|
|
390
384
|
WHERE C.TABLE_SCHEMA = '${dbName}';`;
|
|
@@ -443,6 +437,24 @@ WHERE C.TABLE_SCHEMA = '${dbName}';`;
|
|
|
443
437
|
}
|
|
444
438
|
return fields;
|
|
445
439
|
}
|
|
440
|
+
/**
|
|
441
|
+
* Get the names of all user (base) tables in the database schema, excluding system tables and views.
|
|
442
|
+
*
|
|
443
|
+
*/
|
|
444
|
+
async getSchemaTables() {
|
|
445
|
+
const tables = [];
|
|
446
|
+
const sql = "SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = '" + this.dbParams.database + "' AND TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME;";
|
|
447
|
+
const tables_res = await this._query(sql);
|
|
448
|
+
while (!tables_res.isEof()) {
|
|
449
|
+
const row = tables_res.getRow();
|
|
450
|
+
const table_name = row[0]?.toString() || "";
|
|
451
|
+
if (table_name) {
|
|
452
|
+
tables.push(table_name);
|
|
453
|
+
}
|
|
454
|
+
await tables_res.next();
|
|
455
|
+
}
|
|
456
|
+
return tables;
|
|
457
|
+
}
|
|
446
458
|
/**
|
|
447
459
|
* Resolve the optimal native (SQL) type for a serialized field schema.
|
|
448
460
|
*
|
|
@@ -304,13 +304,7 @@ export class OINODbMariadb extends OINODb {
|
|
|
304
304
|
const sql = this._getValidateSql(this.dbParams.database);
|
|
305
305
|
const sql_res = await this._query(sql);
|
|
306
306
|
if (sql_res.isEmpty()) {
|
|
307
|
-
result.setError(400, "DB returned no rows for
|
|
308
|
-
}
|
|
309
|
-
else if (sql_res.getRow().length == 0) {
|
|
310
|
-
result.setError(400, "DB returned no values for database!", "OINODbMariadb.validate");
|
|
311
|
-
}
|
|
312
|
-
else if (sql_res.getRow()[0] == "0") {
|
|
313
|
-
result.setError(400, "DB returned no schema for database!", "OINODbMariadb.validate");
|
|
307
|
+
result.setError(400, "DB returned no rows for schema!", "OINODbMariadb.validate");
|
|
314
308
|
}
|
|
315
309
|
else {
|
|
316
310
|
this.isValidated = true;
|
|
@@ -366,12 +360,12 @@ export class OINODbMariadb extends OINODb {
|
|
|
366
360
|
}
|
|
367
361
|
_getSchemaSql(dbName, tableName) {
|
|
368
362
|
const sql = `SELECT
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
363
|
+
C.COLUMN_NAME,
|
|
364
|
+
C.COLUMN_TYPE,
|
|
365
|
+
C.IS_NULLABLE,
|
|
366
|
+
C.COLUMN_KEY,
|
|
367
|
+
C.COLUMN_DEFAULT,
|
|
368
|
+
C.EXTRA,
|
|
375
369
|
KCU.CONSTRAINT_NAME AS ForeignKeyName
|
|
376
370
|
FROM information_schema.COLUMNS C
|
|
377
371
|
LEFT JOIN information_schema.KEY_COLUMN_USAGE KCU ON KCU.TABLE_SCHEMA = C.TABLE_SCHEMA AND KCU.TABLE_NAME = C.TABLE_NAME AND C.COLUMN_NAME = KCU.COLUMN_NAME and KCU.REFERENCED_TABLE_NAME IS NOT NULL
|
|
@@ -381,7 +375,7 @@ ORDER BY C.ORDINAL_POSITION;`;
|
|
|
381
375
|
}
|
|
382
376
|
_getValidateSql(dbName) {
|
|
383
377
|
const sql = `SELECT
|
|
384
|
-
Count(
|
|
378
|
+
Count(C.COLUMN_NAME) AS COLUMN_COUNT
|
|
385
379
|
FROM information_schema.COLUMNS C
|
|
386
380
|
LEFT JOIN information_schema.KEY_COLUMN_USAGE KCU ON KCU.TABLE_SCHEMA = C.TABLE_SCHEMA AND KCU.TABLE_NAME = C.TABLE_NAME AND C.COLUMN_NAME = KCU.COLUMN_NAME and KCU.REFERENCED_TABLE_NAME IS NOT NULL
|
|
387
381
|
WHERE C.TABLE_SCHEMA = '${dbName}';`;
|
|
@@ -440,6 +434,24 @@ WHERE C.TABLE_SCHEMA = '${dbName}';`;
|
|
|
440
434
|
}
|
|
441
435
|
return fields;
|
|
442
436
|
}
|
|
437
|
+
/**
|
|
438
|
+
* Get the names of all user (base) tables in the database schema, excluding system tables and views.
|
|
439
|
+
*
|
|
440
|
+
*/
|
|
441
|
+
async getSchemaTables() {
|
|
442
|
+
const tables = [];
|
|
443
|
+
const sql = "SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = '" + this.dbParams.database + "' AND TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME;";
|
|
444
|
+
const tables_res = await this._query(sql);
|
|
445
|
+
while (!tables_res.isEof()) {
|
|
446
|
+
const row = tables_res.getRow();
|
|
447
|
+
const table_name = row[0]?.toString() || "";
|
|
448
|
+
if (table_name) {
|
|
449
|
+
tables.push(table_name);
|
|
450
|
+
}
|
|
451
|
+
await tables_res.next();
|
|
452
|
+
}
|
|
453
|
+
return tables;
|
|
454
|
+
}
|
|
443
455
|
/**
|
|
444
456
|
* Resolve the optimal native (SQL) type for a serialized field schema.
|
|
445
457
|
*
|
|
@@ -95,6 +95,11 @@ export declare class OINODbMariadb extends OINODb {
|
|
|
95
95
|
*
|
|
96
96
|
*/
|
|
97
97
|
getSchemaFields(tableName: string): Promise<OINODataField[]>;
|
|
98
|
+
/**
|
|
99
|
+
* Get the names of all user (base) tables in the database schema, excluding system tables and views.
|
|
100
|
+
*
|
|
101
|
+
*/
|
|
102
|
+
getSchemaTables(): Promise<string[]>;
|
|
98
103
|
/**
|
|
99
104
|
* Resolve the optimal native (SQL) type for a serialized field schema.
|
|
100
105
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oino-ts/db-mariadb",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "OINO TS package for using Mariadb databases.",
|
|
5
5
|
"author": "Matias Kiviniemi (pragmatta)",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"module": "./dist/esm/index.js",
|
|
22
22
|
"types": "./dist/types/index.d.ts",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@oino-ts/common": "^1.1.
|
|
25
|
-
"@oino-ts/db": "^1.1.
|
|
24
|
+
"@oino-ts/common": "^1.1.2",
|
|
25
|
+
"@oino-ts/db": "^1.1.2",
|
|
26
26
|
"mariadb": "^3.2.3"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@types/bun": "^1.1.
|
|
29
|
+
"@types/bun": "^1.1.24",
|
|
30
30
|
"@types/node": "^20.12.7",
|
|
31
31
|
"typescript": "~5.9.0"
|
|
32
32
|
},
|
package/src/OINODbMariadb.ts
CHANGED
|
@@ -326,13 +326,7 @@ export class OINODbMariadb extends OINODb {
|
|
|
326
326
|
const sql = this._getValidateSql(this.dbParams.database)
|
|
327
327
|
const sql_res:OINODataSet = await this._query(sql)
|
|
328
328
|
if (sql_res.isEmpty()) {
|
|
329
|
-
result.setError(400, "DB returned no rows for
|
|
330
|
-
|
|
331
|
-
} else if (sql_res.getRow().length == 0) {
|
|
332
|
-
result.setError(400, "DB returned no values for database!", "OINODbMariadb.validate")
|
|
333
|
-
|
|
334
|
-
} else if (sql_res.getRow()[0] == "0") {
|
|
335
|
-
result.setError(400, "DB returned no schema for database!", "OINODbMariadb.validate")
|
|
329
|
+
result.setError(400, "DB returned no rows for schema!", "OINODbMariadb.validate")
|
|
336
330
|
|
|
337
331
|
} else {
|
|
338
332
|
this.isValidated = true
|
|
@@ -392,12 +386,12 @@ export class OINODbMariadb extends OINODb {
|
|
|
392
386
|
private _getSchemaSql(dbName:string, tableName:string):string {
|
|
393
387
|
const sql =
|
|
394
388
|
`SELECT
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
389
|
+
C.COLUMN_NAME,
|
|
390
|
+
C.COLUMN_TYPE,
|
|
391
|
+
C.IS_NULLABLE,
|
|
392
|
+
C.COLUMN_KEY,
|
|
393
|
+
C.COLUMN_DEFAULT,
|
|
394
|
+
C.EXTRA,
|
|
401
395
|
KCU.CONSTRAINT_NAME AS ForeignKeyName
|
|
402
396
|
FROM information_schema.COLUMNS C
|
|
403
397
|
LEFT JOIN information_schema.KEY_COLUMN_USAGE KCU ON KCU.TABLE_SCHEMA = C.TABLE_SCHEMA AND KCU.TABLE_NAME = C.TABLE_NAME AND C.COLUMN_NAME = KCU.COLUMN_NAME and KCU.REFERENCED_TABLE_NAME IS NOT NULL
|
|
@@ -409,7 +403,7 @@ ORDER BY C.ORDINAL_POSITION;`
|
|
|
409
403
|
private _getValidateSql(dbName:string):string {
|
|
410
404
|
const sql =
|
|
411
405
|
`SELECT
|
|
412
|
-
Count(
|
|
406
|
+
Count(C.COLUMN_NAME) AS COLUMN_COUNT
|
|
413
407
|
FROM information_schema.COLUMNS C
|
|
414
408
|
LEFT JOIN information_schema.KEY_COLUMN_USAGE KCU ON KCU.TABLE_SCHEMA = C.TABLE_SCHEMA AND KCU.TABLE_NAME = C.TABLE_NAME AND C.COLUMN_NAME = KCU.COLUMN_NAME and KCU.REFERENCED_TABLE_NAME IS NOT NULL
|
|
415
409
|
WHERE C.TABLE_SCHEMA = '${dbName}';`
|
|
@@ -464,6 +458,25 @@ WHERE C.TABLE_SCHEMA = '${dbName}';`
|
|
|
464
458
|
return fields
|
|
465
459
|
}
|
|
466
460
|
|
|
461
|
+
/**
|
|
462
|
+
* Get the names of all user (base) tables in the database schema, excluding system tables and views.
|
|
463
|
+
*
|
|
464
|
+
*/
|
|
465
|
+
async getSchemaTables(): Promise<string[]> {
|
|
466
|
+
const tables:string[] = []
|
|
467
|
+
const sql:string = "SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = '" + this.dbParams.database + "' AND TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME;"
|
|
468
|
+
const tables_res:OINODataSet = await this._query(sql)
|
|
469
|
+
while (!tables_res.isEof()) {
|
|
470
|
+
const row:OINODataRow = tables_res.getRow()
|
|
471
|
+
const table_name:string = row[0]?.toString() || ""
|
|
472
|
+
if (table_name) {
|
|
473
|
+
tables.push(table_name)
|
|
474
|
+
}
|
|
475
|
+
await tables_res.next()
|
|
476
|
+
}
|
|
477
|
+
return tables
|
|
478
|
+
}
|
|
479
|
+
|
|
467
480
|
/**
|
|
468
481
|
* Resolve the optimal native (SQL) type for a serialized field schema.
|
|
469
482
|
*
|