@deterministic-code/datasources-mysql 0.1.4 → 0.1.6

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.
@@ -37,6 +37,7 @@ export class MysqlConnection {
37
37
  this.client = await this.connect(this.url);
38
38
  }
39
39
  await this.client.query("SET SESSION sql_mode = CONCAT(@@sql_mode, ',ANSI_QUOTES')");
40
+ await this.client.query("SET time_zone = '+00:00'");
40
41
  this.isOpen = true;
41
42
  }
42
43
  async close() {
@@ -1,7 +1,14 @@
1
1
  import { TypeConverter } from "@deterministic-code/datasources";
2
2
  const stamp = (date) => date.toISOString().replace("T", " ").replace("Z", "");
3
+ const utcDate = (text) => {
4
+ const iso = /[zZ]|[+-]\d{2}:\d{2}$/.test(text)
5
+ ? text
6
+ : `${text.includes("T") ? text : text.replace(" ", "T")}Z`;
7
+ const date = new Date(iso);
8
+ return Number.isNaN(date.getTime()) ? text : date;
9
+ };
3
10
  export class DateTimeConverter extends TypeConverter {
4
- convert = (from) => typeof from === "string" ? new Date(from) : from;
11
+ convert = (from) => typeof from === "string" ? utcDate(from) : from;
5
12
  reverseConvert = (to) => to instanceof Date
6
13
  ? stamp(to)
7
14
  : typeof to === "string" && /^\d{4}-\d{2}-\d{2}T/.test(to)
@@ -22,6 +22,7 @@ export type Mysql2Module = {
22
22
  createConnection: (options: {
23
23
  uri: string;
24
24
  namedPlaceholders: boolean;
25
+ timezone: string;
25
26
  }) => Promise<IMysqlClient>;
26
27
  };
27
28
  export declare const mysql2Connect: (mysql: Mysql2Module) => MysqlCreateConnection;
@@ -2,6 +2,7 @@ export const mysql2Connect = (mysql) => async (uri) => {
2
2
  const client = (await mysql.createConnection({
3
3
  uri,
4
4
  namedPlaceholders: true,
5
+ timezone: "Z",
5
6
  }));
6
7
  return {
7
8
  query: (sql, params) => client.query(sql, params),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deterministic-code/datasources-mysql",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
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.4",
21
+ "@deterministic-code/datasources": "^0.1.6",
22
22
  "mysql2": "^3.14.0"
23
23
  }
24
24
  }