@deterministic-code/datasources-mysql 0.1.12 → 0.1.15

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.
@@ -1,6 +1,8 @@
1
- import { AlterTableStatementTextRenderer, type AlterAction, type Column } from "@deterministic-code/datasources";
1
+ import { AlterTableStatementTextRenderer, type AlterAction, type Column, type NotNull } from "@deterministic-code/datasources";
2
2
  export declare class MysqlAlterTableStatementRenderer extends AlterTableStatementTextRenderer {
3
3
  protected typeName(column: Column): string;
4
+ protected columnDefault(column: Column): string;
5
+ protected notNullSql(value?: NotNull): string;
4
6
  protected identity(column: Column): string;
5
7
  protected actionSql(action: AlterAction): string;
6
8
  }
@@ -4,6 +4,12 @@ export class MysqlAlterTableStatementRenderer extends AlterTableStatementTextRen
4
4
  typeName(column) {
5
5
  return columnTypes[column.type] ?? column.type;
6
6
  }
7
+ columnDefault(column) {
8
+ return column.default == null ? "" : ` DEFAULT ${column.default.value}`;
9
+ }
10
+ notNullSql(value) {
11
+ return value == null ? "" : " NOT NULL";
12
+ }
7
13
  identity(column) {
8
14
  return column.identity ? " AUTO_INCREMENT" : "";
9
15
  }
@@ -1,5 +1,7 @@
1
- import { CreateTableStatementTextRenderer, type Column } from "@deterministic-code/datasources";
1
+ import { CreateTableStatementTextRenderer, type Column, type NotNull } from "@deterministic-code/datasources";
2
2
  export declare class MysqlCreateTableStatementRenderer extends CreateTableStatementTextRenderer {
3
3
  protected typeName(column: Column): string;
4
+ protected columnDefault(column: Column): string;
5
+ protected notNullSql(value?: NotNull): string;
4
6
  protected identity(column: Column): string;
5
7
  }
@@ -4,6 +4,12 @@ export class MysqlCreateTableStatementRenderer extends CreateTableStatementTextR
4
4
  typeName(column) {
5
5
  return columnTypes[column.type] ?? column.type;
6
6
  }
7
+ columnDefault(column) {
8
+ return column.default == null ? "" : ` DEFAULT ${column.default.value}`;
9
+ }
10
+ notNullSql(value) {
11
+ return value == null ? "" : " NOT NULL";
12
+ }
7
13
  identity(column) {
8
14
  return column.identity ? " AUTO_INCREMENT" : "";
9
15
  }
@@ -1,4 +1,4 @@
1
- import { DatasourceError, DefaultValueConverter, DeterministicTypeConverter, StatementTextRenderer, } from "@deterministic-code/datasources";
1
+ import { DatasourceError, DefaultValueConverter, sqlStringLiteral, DeterministicTypeConverter, StatementTextRenderer, } from "@deterministic-code/datasources";
2
2
  import { MysqlConnection } from "./connection.js";
3
3
  import { MysqlCommand } from "./command.js";
4
4
  import { MysqlTransaction } from "./transaction.js";
@@ -63,8 +63,10 @@ export class MysqlDriver {
63
63
  utcNow: () => `(UTC_TIMESTAMP(3))`,
64
64
  booleanOn: "1",
65
65
  booleanOff: "0",
66
- hex: (arg) => `X'${arg}'`,
67
- hexReverse: /^X'(.*)'$/,
66
+ hex: (arg) => `(X'${arg}')`,
67
+ hexReverse: /^(?:\(X'(.*)'\)|X'(.*)')$/,
68
+ quote: (arg) => `(${sqlStringLiteral(arg)})`,
69
+ quoteReverse: /^(?:\('(.*)'\)|'(.*)')$/,
68
70
  });
69
71
  columnType = (name) => columnTypes[name] ??
70
72
  (() => {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { register } from "@deterministic-code/datasources-code-generators/common/sql-dialect";
2
+ import { MysqlDriver } from "./MysqlDriver.js";
3
+ register("mysql", new MysqlDriver());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deterministic-code/datasources-mysql",
3
- "version": "0.1.12",
3
+ "version": "0.1.15",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.js",
@@ -18,7 +18,7 @@
18
18
  "access": "public"
19
19
  },
20
20
  "dependencies": {
21
- "@deterministic-code/datasources": "^0.1.12",
21
+ "@deterministic-code/datasources": "^0.1.15",
22
22
  "mysql2": "^3.14.0"
23
23
  }
24
24
  }