@oino-ts/db-mariadb 1.1.1 → 1.1.3

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.
@@ -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 select!", "OINODbMariadb.validate");
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
- c.COLUMN_NAME,
373
- c.COLUMN_TYPE,
374
- c.IS_NULLABLE,
375
- c.COLUMN_KEY,
376
- c.COLUMN_DEFAULT,
377
- c.EXTRA,
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(c.COLUMN_NAME) AS COLUMN_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}';`;
@@ -413,7 +407,7 @@ WHERE C.TABLE_SCHEMA = '${dbName}';`;
413
407
  isAutoInc: extra.indexOf('auto_increment') >= 0,
414
408
  isNotNull: row[2] == "NO"
415
409
  };
416
- if ((sql_type == "int") || (sql_type == "smallint") || (sql_type == "float") || (sql_type == "double")) {
410
+ if ((sql_type == "int") || (sql_type == "smallint") || (sql_type == "mediumint") || (sql_type == "bigint") || (sql_type == "float") || (sql_type == "double")) {
417
411
  fields.push(new common_2.OINONumberDataField(this, field_name, sql_type, field_params));
418
412
  }
419
413
  else if ((sql_type == "date") || (sql_type == "datetime") || (sql_type == "timestamp")) {
@@ -472,7 +466,7 @@ WHERE C.TABLE_SCHEMA = '${dbName}';`;
472
466
  case "string":
473
467
  return (schema.maxLength || 0) > 0 ? "varchar(" + schema.maxLength + ")" : "longtext";
474
468
  case "number":
475
- return "double";
469
+ return schema.fieldParams?.isAutoInc ? "bigint" : "double";
476
470
  case "boolean":
477
471
  return "bit(1)";
478
472
  case "datetime":
@@ -483,5 +477,8 @@ WHERE C.TABLE_SCHEMA = '${dbName}';`;
483
477
  throw new Error(common_1.OINO_ERROR_PREFIX + ": OINODbMariadb.getNativeDataType - unsupported field type '" + schema.type + "'");
484
478
  }
485
479
  }
480
+ _printColumnAutoInc() {
481
+ return "AUTO_INCREMENT";
482
+ }
486
483
  }
487
484
  exports.OINODbMariadb = OINODbMariadb;
@@ -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 select!", "OINODbMariadb.validate");
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
- c.COLUMN_NAME,
370
- c.COLUMN_TYPE,
371
- c.IS_NULLABLE,
372
- c.COLUMN_KEY,
373
- c.COLUMN_DEFAULT,
374
- c.EXTRA,
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(c.COLUMN_NAME) AS COLUMN_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}';`;
@@ -410,7 +404,7 @@ WHERE C.TABLE_SCHEMA = '${dbName}';`;
410
404
  isAutoInc: extra.indexOf('auto_increment') >= 0,
411
405
  isNotNull: row[2] == "NO"
412
406
  };
413
- if ((sql_type == "int") || (sql_type == "smallint") || (sql_type == "float") || (sql_type == "double")) {
407
+ if ((sql_type == "int") || (sql_type == "smallint") || (sql_type == "mediumint") || (sql_type == "bigint") || (sql_type == "float") || (sql_type == "double")) {
414
408
  fields.push(new OINONumberDataField(this, field_name, sql_type, field_params));
415
409
  }
416
410
  else if ((sql_type == "date") || (sql_type == "datetime") || (sql_type == "timestamp")) {
@@ -469,7 +463,7 @@ WHERE C.TABLE_SCHEMA = '${dbName}';`;
469
463
  case "string":
470
464
  return (schema.maxLength || 0) > 0 ? "varchar(" + schema.maxLength + ")" : "longtext";
471
465
  case "number":
472
- return "double";
466
+ return schema.fieldParams?.isAutoInc ? "bigint" : "double";
473
467
  case "boolean":
474
468
  return "bit(1)";
475
469
  case "datetime":
@@ -480,4 +474,7 @@ WHERE C.TABLE_SCHEMA = '${dbName}';`;
480
474
  throw new Error(OINO_ERROR_PREFIX + ": OINODbMariadb.getNativeDataType - unsupported field type '" + schema.type + "'");
481
475
  }
482
476
  }
477
+ _printColumnAutoInc() {
478
+ return "AUTO_INCREMENT";
479
+ }
483
480
  }
@@ -107,4 +107,5 @@ export declare class OINODbMariadb extends OINODb {
107
107
  *
108
108
  */
109
109
  getNativeDataType(schema: OINODataFieldSchema): string;
110
+ protected _printColumnAutoInc(): string;
110
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oino-ts/db-mariadb",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
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.1",
25
- "@oino-ts/db": "^1.1.1",
24
+ "@oino-ts/common": "^1.1.3",
25
+ "@oino-ts/db": "^1.1.3",
26
26
  "mariadb": "^3.2.3"
27
27
  },
28
28
  "devDependencies": {
29
- "@types/bun": "^1.1.14",
29
+ "@types/bun": "^1.1.34",
30
30
  "@types/node": "^20.12.7",
31
31
  "typescript": "~5.9.0"
32
32
  },
@@ -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 select!", "OINODbMariadb.validate")
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
- c.COLUMN_NAME,
396
- c.COLUMN_TYPE,
397
- c.IS_NULLABLE,
398
- c.COLUMN_KEY,
399
- c.COLUMN_DEFAULT,
400
- c.EXTRA,
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(c.COLUMN_NAME) AS COLUMN_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}';`
@@ -440,7 +434,7 @@ WHERE C.TABLE_SCHEMA = '${dbName}';`
440
434
  isAutoInc: extra.indexOf('auto_increment') >= 0,
441
435
  isNotNull: row[2] == "NO"
442
436
  }
443
- if ((sql_type == "int") || (sql_type == "smallint") || (sql_type == "float") || (sql_type == "double")) {
437
+ if ((sql_type == "int") || (sql_type == "smallint") || (sql_type == "mediumint") || (sql_type == "bigint") || (sql_type == "float") || (sql_type == "double")) {
444
438
  fields.push(new OINONumberDataField(this, field_name, sql_type, field_params))
445
439
  } else if ((sql_type == "date") || (sql_type == "datetime") || (sql_type == "timestamp")) {
446
440
  fields.push(new OINODatetimeDataField(this, field_name, sql_type, field_params))
@@ -494,7 +488,7 @@ WHERE C.TABLE_SCHEMA = '${dbName}';`
494
488
  case "string":
495
489
  return (schema.maxLength || 0) > 0 ? "varchar(" + schema.maxLength + ")" : "longtext"
496
490
  case "number":
497
- return "double"
491
+ return schema.fieldParams?.isAutoInc ? "bigint" : "double"
498
492
  case "boolean":
499
493
  return "bit(1)"
500
494
  case "datetime":
@@ -505,6 +499,10 @@ WHERE C.TABLE_SCHEMA = '${dbName}';`
505
499
  throw new Error(OINO_ERROR_PREFIX + ": OINODbMariadb.getNativeDataType - unsupported field type '" + schema.type + "'")
506
500
  }
507
501
  }
502
+
503
+ protected _printColumnAutoInc(): string {
504
+ return "AUTO_INCREMENT"
505
+ }
508
506
  }
509
507
 
510
508