@malloydata/db-mysql 0.0.337 → 0.0.338

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/index.js CHANGED
@@ -20,6 +20,7 @@ const mysql_connection_2 = require("./mysql_connection");
20
20
  database: typeof config['database'] === 'string' ? config['database'] : undefined,
21
21
  user: typeof config['user'] === 'string' ? config['user'] : undefined,
22
22
  password: typeof config['password'] === 'string' ? config['password'] : undefined,
23
+ setupSQL: typeof config['setupSQL'] === 'string' ? config['setupSQL'] : undefined,
23
24
  });
24
25
  },
25
26
  properties: [
@@ -39,6 +40,13 @@ const mysql_connection_2 = require("./mysql_connection");
39
40
  type: 'password',
40
41
  optional: true,
41
42
  },
43
+ {
44
+ name: 'setupSQL',
45
+ displayName: 'Setup SQL',
46
+ type: 'text',
47
+ optional: true,
48
+ description: 'SQL statements to run when the connection is established',
49
+ },
42
50
  ],
43
51
  });
44
52
  //# sourceMappingURL=index.js.map
@@ -7,6 +7,7 @@ export interface MySQLConfiguration {
7
7
  database?: string;
8
8
  user?: string;
9
9
  password?: string;
10
+ setupSQL?: string;
10
11
  }
11
12
  export declare class MySQLExecutor {
12
13
  static getConnectionOptionsFromEnv(): MySQLConfiguration;
@@ -97,12 +97,20 @@ class MySQLConnection extends connection_1.BaseConnection {
97
97
  'SET SESSION group_concat_max_len = 10000000;' +
98
98
  // Need this to make NULL LAST in order by (ISNULL(exp) can't appear in an ORDER BY without it)
99
99
  "SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));");
100
+ if (this.config.setupSQL) {
101
+ for (const stmt of this.config.setupSQL.split(';\n')) {
102
+ const trimmed = stmt.trim();
103
+ if (trimmed) {
104
+ await this.connection.query(trimmed);
105
+ }
106
+ }
107
+ }
100
108
  }
101
109
  return this.connection;
102
110
  }
103
111
  async manifestTemporaryTable(sqlCommand) {
104
112
  const hash = (0, malloy_1.makeDigest)(sqlCommand);
105
- const tableName = `tt${hash}`;
113
+ const tableName = `tt${hash.slice(0, this.dialect.maxIdentifierLength - 2)}`;
106
114
  const cmd = `CREATE TEMPORARY TABLE IF NOT EXISTS ${tableName} AS (${sqlCommand});`;
107
115
  // console.log(cmd);
108
116
  await this.runRawSQL(cmd);
@@ -119,9 +127,9 @@ class MySQLConnection extends connection_1.BaseConnection {
119
127
  return false;
120
128
  }
121
129
  getDigest() {
122
- const { host, port, database } = this.config;
123
- const data = `mysql:${host !== null && host !== void 0 ? host : ''}:${port !== null && port !== void 0 ? port : 3306}:${database !== null && database !== void 0 ? database : ''}`;
124
- return (0, malloy_1.makeDigest)(data);
130
+ var _a;
131
+ const { host, port, user, database } = this.config;
132
+ return (0, malloy_1.makeDigest)('mysql', host !== null && host !== void 0 ? host : '', String(port !== null && port !== void 0 ? port : 3306), user !== null && user !== void 0 ? user : '', database !== null && database !== void 0 ? database : '', (_a = this.config.setupSQL) !== null && _a !== void 0 ? _a : '');
125
133
  }
126
134
  canPersist() {
127
135
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/db-mysql",
3
- "version": "0.0.337",
3
+ "version": "0.0.338",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "prepublishOnly": "npm run build"
23
23
  },
24
24
  "dependencies": {
25
- "@malloydata/malloy": "0.0.337",
25
+ "@malloydata/malloy": "0.0.338",
26
26
  "@types/node": "^22.7.4",
27
27
  "fastestsmallesttextencoderdecoder": "^1.0.22",
28
28
  "luxon": "^3.5.0",