schema-seed-adapter-mysql 0.1.0
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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/index.cjs +181 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +26 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +147 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 schema-seed contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
MySqlAdapter: () => MySqlAdapter,
|
|
34
|
+
createMySqlAdapter: () => createMySqlAdapter
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
var import_promise = __toESM(require("mysql2/promise"), 1);
|
|
38
|
+
var import_schema_seed_core = require("schema-seed-core");
|
|
39
|
+
var MySqlAdapter = class {
|
|
40
|
+
connection = null;
|
|
41
|
+
connectionString;
|
|
42
|
+
constructor(connectionString) {
|
|
43
|
+
this.connectionString = connectionString;
|
|
44
|
+
}
|
|
45
|
+
async connect() {
|
|
46
|
+
this.connection = await import_promise.default.createConnection(this.connectionString);
|
|
47
|
+
}
|
|
48
|
+
async disconnect() {
|
|
49
|
+
if (this.connection) {
|
|
50
|
+
await this.connection.end();
|
|
51
|
+
this.connection = null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async begin() {
|
|
55
|
+
await this.connection?.query("START TRANSACTION");
|
|
56
|
+
}
|
|
57
|
+
async commit() {
|
|
58
|
+
await this.connection?.query("COMMIT");
|
|
59
|
+
}
|
|
60
|
+
async rollback() {
|
|
61
|
+
await this.connection?.query("ROLLBACK");
|
|
62
|
+
}
|
|
63
|
+
async introspectSchema() {
|
|
64
|
+
if (!this.connection) throw new Error("Not connected");
|
|
65
|
+
const schema = { tables: {} };
|
|
66
|
+
const dbName = this.connection.config.database;
|
|
67
|
+
const [tables] = await this.connection.query(`
|
|
68
|
+
SELECT TABLE_NAME, TABLE_SCHEMA
|
|
69
|
+
FROM information_schema.TABLES
|
|
70
|
+
WHERE TABLE_SCHEMA = ? AND TABLE_TYPE = 'BASE TABLE'
|
|
71
|
+
`, [dbName]);
|
|
72
|
+
for (const row of tables) {
|
|
73
|
+
const tableName = row.TABLE_NAME;
|
|
74
|
+
schema.tables[tableName] = {
|
|
75
|
+
name: tableName,
|
|
76
|
+
schema: row.TABLE_SCHEMA,
|
|
77
|
+
columns: {},
|
|
78
|
+
foreignKeys: [],
|
|
79
|
+
uniqueConstraints: []
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const [columns] = await this.connection.query(`
|
|
83
|
+
SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT, EXTRA, COLUMN_TYPE
|
|
84
|
+
FROM information_schema.COLUMNS
|
|
85
|
+
WHERE TABLE_SCHEMA = ?
|
|
86
|
+
`, [dbName]);
|
|
87
|
+
for (const row of columns) {
|
|
88
|
+
if (!schema.tables[row.TABLE_NAME]) continue;
|
|
89
|
+
const col = {
|
|
90
|
+
name: row.COLUMN_NAME,
|
|
91
|
+
type: this.mapMySqlType(row.DATA_TYPE, row.COLUMN_TYPE),
|
|
92
|
+
rawType: row.DATA_TYPE,
|
|
93
|
+
nullable: row.IS_NULLABLE === "YES",
|
|
94
|
+
defaultValue: row.COLUMN_DEFAULT,
|
|
95
|
+
isAutoIncrement: row.EXTRA.includes("auto_increment"),
|
|
96
|
+
enumValues: this.parseEnumValues(row.COLUMN_TYPE)
|
|
97
|
+
};
|
|
98
|
+
schema.tables[row.TABLE_NAME].columns[row.COLUMN_NAME] = col;
|
|
99
|
+
}
|
|
100
|
+
const [fks] = await this.connection.query(`
|
|
101
|
+
SELECT
|
|
102
|
+
TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME,
|
|
103
|
+
REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME
|
|
104
|
+
FROM information_schema.KEY_COLUMN_USAGE
|
|
105
|
+
WHERE TABLE_SCHEMA = ? AND REFERENCED_TABLE_NAME IS NOT NULL
|
|
106
|
+
`, [dbName]);
|
|
107
|
+
for (const row of fks) {
|
|
108
|
+
if (!schema.tables[row.TABLE_NAME]) continue;
|
|
109
|
+
schema.tables[row.TABLE_NAME].foreignKeys.push({
|
|
110
|
+
name: row.CONSTRAINT_NAME,
|
|
111
|
+
columns: [row.COLUMN_NAME],
|
|
112
|
+
referencedTable: row.REFERENCED_TABLE_NAME,
|
|
113
|
+
referencedColumns: [row.REFERENCED_COLUMN_NAME]
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const [pks] = await this.connection.query(`
|
|
117
|
+
SELECT TABLE_NAME, COLUMN_NAME
|
|
118
|
+
FROM information_schema.KEY_COLUMN_USAGE
|
|
119
|
+
WHERE TABLE_SCHEMA = ? AND CONSTRAINT_NAME = 'PRIMARY'
|
|
120
|
+
`, [dbName]);
|
|
121
|
+
for (const row of pks) {
|
|
122
|
+
if (!schema.tables[row.TABLE_NAME]) continue;
|
|
123
|
+
if (!schema.tables[row.TABLE_NAME].primaryKey) {
|
|
124
|
+
schema.tables[row.TABLE_NAME].primaryKey = { columns: [] };
|
|
125
|
+
}
|
|
126
|
+
schema.tables[row.TABLE_NAME].primaryKey.columns.push(row.COLUMN_NAME);
|
|
127
|
+
}
|
|
128
|
+
return schema;
|
|
129
|
+
}
|
|
130
|
+
async insertBatch(batch) {
|
|
131
|
+
if (!this.connection) throw new Error("Not connected");
|
|
132
|
+
const { tableName, rows } = batch;
|
|
133
|
+
if (rows.length === 0) return;
|
|
134
|
+
const columns = Object.keys(rows[0]);
|
|
135
|
+
const values = rows.map((row) => columns.map((col) => row[col]));
|
|
136
|
+
const query = `INSERT INTO \`${tableName}\` (${columns.map((c) => `\`${c}\``).join(", ")}) VALUES ?`;
|
|
137
|
+
await this.connection.query(query, [values]);
|
|
138
|
+
}
|
|
139
|
+
async truncateTables(tableNames) {
|
|
140
|
+
if (!this.connection) throw new Error("Not connected");
|
|
141
|
+
await this.connection.query("SET FOREIGN_KEY_CHECKS = 0");
|
|
142
|
+
for (const table of tableNames) {
|
|
143
|
+
await this.connection.query(`TRUNCATE TABLE \`${table}\``);
|
|
144
|
+
}
|
|
145
|
+
await this.connection.query("SET FOREIGN_KEY_CHECKS = 1");
|
|
146
|
+
}
|
|
147
|
+
capabilities = {
|
|
148
|
+
enums: true,
|
|
149
|
+
deferrableConstraints: false,
|
|
150
|
+
returning: false,
|
|
151
|
+
identityInsert: false
|
|
152
|
+
};
|
|
153
|
+
mapMySqlType(mysqlType, columnType) {
|
|
154
|
+
const type = mysqlType.toLowerCase();
|
|
155
|
+
if (type.includes("int")) return import_schema_seed_core.NormalizedSqlType.INT;
|
|
156
|
+
if (type.includes("bigint")) return import_schema_seed_core.NormalizedSqlType.BIGINT;
|
|
157
|
+
if (type.includes("char") || type.includes("varchar") || type === "text" || type.includes("text")) return import_schema_seed_core.NormalizedSqlType.STRING;
|
|
158
|
+
if (type === "tinyint" && columnType.includes("(1)")) return import_schema_seed_core.NormalizedSqlType.BOOLEAN;
|
|
159
|
+
if (type === "date") return import_schema_seed_core.NormalizedSqlType.DATE;
|
|
160
|
+
if (type.includes("time") || type === "datetime") return import_schema_seed_core.NormalizedSqlType.DATETIME;
|
|
161
|
+
if (type === "json") return import_schema_seed_core.NormalizedSqlType.JSON;
|
|
162
|
+
if (type === "decimal") return import_schema_seed_core.NormalizedSqlType.DECIMAL;
|
|
163
|
+
if (type === "float" || type === "double") return import_schema_seed_core.NormalizedSqlType.FLOAT;
|
|
164
|
+
if (type === "enum") return import_schema_seed_core.NormalizedSqlType.ENUM;
|
|
165
|
+
if (type === "blob" || type.includes("binary")) return import_schema_seed_core.NormalizedSqlType.BINARY;
|
|
166
|
+
return import_schema_seed_core.NormalizedSqlType.STRING;
|
|
167
|
+
}
|
|
168
|
+
parseEnumValues(columnType) {
|
|
169
|
+
if (!columnType.startsWith("enum(")) return void 0;
|
|
170
|
+
return columnType.slice(5, -1).split(",").map((v) => v.trim().replace(/^'|'$/g, ""));
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
function createMySqlAdapter(connectionString) {
|
|
174
|
+
return new MySqlAdapter(connectionString);
|
|
175
|
+
}
|
|
176
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
177
|
+
0 && (module.exports = {
|
|
178
|
+
MySqlAdapter,
|
|
179
|
+
createMySqlAdapter
|
|
180
|
+
});
|
|
181
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import mysql from 'mysql2/promise'\nimport {\n SqlAdapter,\n SchemaGraph,\n SeedBatch,\n NormalizedSqlType,\n TableSchema,\n ColumnSchema\n} from 'schema-seed-core'\n\nexport class MySqlAdapter implements SqlAdapter {\n private connection: mysql.Connection | null = null\n private connectionString: string\n\n constructor(connectionString: string) {\n this.connectionString = connectionString\n }\n\n async connect(): Promise<void> {\n this.connection = await mysql.createConnection(this.connectionString)\n }\n\n async disconnect(): Promise<void> {\n if (this.connection) {\n await this.connection.end()\n this.connection = null\n }\n }\n\n async begin(): Promise<void> {\n await this.connection?.query('START TRANSACTION')\n }\n\n async commit(): Promise<void> {\n await this.connection?.query('COMMIT')\n }\n\n async rollback(): Promise<void> {\n await this.connection?.query('ROLLBACK')\n }\n\n async introspectSchema(): Promise<SchemaGraph> {\n if (!this.connection) throw new Error('Not connected')\n\n const schema: SchemaGraph = { tables: {} }\n const dbName = this.connection.config.database\n\n // Get tables\n const [tables] = await this.connection.query<any[]>(`\n SELECT TABLE_NAME, TABLE_SCHEMA\n FROM information_schema.TABLES\n WHERE TABLE_SCHEMA = ? AND TABLE_TYPE = 'BASE TABLE'\n `, [dbName])\n\n for (const row of tables) {\n const tableName = row.TABLE_NAME\n schema.tables[tableName] = {\n name: tableName,\n schema: row.TABLE_SCHEMA,\n columns: {},\n foreignKeys: [],\n uniqueConstraints: []\n }\n }\n\n // Get columns\n const [columns] = await this.connection.query<any[]>(`\n SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT, EXTRA, COLUMN_TYPE\n FROM information_schema.COLUMNS\n WHERE TABLE_SCHEMA = ?\n `, [dbName])\n\n for (const row of columns) {\n if (!schema.tables[row.TABLE_NAME]) continue\n\n const col: ColumnSchema = {\n name: row.COLUMN_NAME,\n type: this.mapMySqlType(row.DATA_TYPE, row.COLUMN_TYPE),\n rawType: row.DATA_TYPE,\n nullable: row.IS_NULLABLE === 'YES',\n defaultValue: row.COLUMN_DEFAULT,\n isAutoIncrement: row.EXTRA.includes('auto_increment'),\n enumValues: this.parseEnumValues(row.COLUMN_TYPE)\n }\n schema.tables[row.TABLE_NAME].columns[row.COLUMN_NAME] = col\n }\n\n // Get Foreign Keys\n const [fks] = await this.connection.query<any[]>(`\n SELECT \n TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME, \n REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME\n FROM information_schema.KEY_COLUMN_USAGE\n WHERE TABLE_SCHEMA = ? AND REFERENCED_TABLE_NAME IS NOT NULL\n `, [dbName])\n\n for (const row of fks) {\n if (!schema.tables[row.TABLE_NAME]) continue\n schema.tables[row.TABLE_NAME].foreignKeys.push({\n name: row.CONSTRAINT_NAME,\n columns: [row.COLUMN_NAME],\n referencedTable: row.REFERENCED_TABLE_NAME,\n referencedColumns: [row.REFERENCED_COLUMN_NAME]\n })\n }\n\n // Get Primary Keys\n const [pks] = await this.connection.query<any[]>(`\n SELECT TABLE_NAME, COLUMN_NAME\n FROM information_schema.KEY_COLUMN_USAGE\n WHERE TABLE_SCHEMA = ? AND CONSTRAINT_NAME = 'PRIMARY'\n `, [dbName])\n\n for (const row of pks) {\n if (!schema.tables[row.TABLE_NAME]) continue\n if (!schema.tables[row.TABLE_NAME].primaryKey) {\n schema.tables[row.TABLE_NAME].primaryKey = { columns: [] }\n }\n schema.tables[row.TABLE_NAME].primaryKey!.columns.push(row.COLUMN_NAME)\n }\n\n return schema\n }\n\n async insertBatch(batch: SeedBatch): Promise<void> {\n if (!this.connection) throw new Error('Not connected')\n const { tableName, rows } = batch\n if (rows.length === 0) return\n\n const columns = Object.keys(rows[0])\n const values = rows.map(row => columns.map(col => row[col]))\n\n const query = `INSERT INTO \\`${tableName}\\` (${columns.map(c => `\\`${c}\\``).join(', ')}) VALUES ?`\n await this.connection.query(query, [values])\n }\n\n async truncateTables(tableNames: string[]): Promise<void> {\n if (!this.connection) throw new Error('Not connected')\n await this.connection.query('SET FOREIGN_KEY_CHECKS = 0')\n for (const table of tableNames) {\n await this.connection.query(`TRUNCATE TABLE \\`${table}\\``)\n }\n await this.connection.query('SET FOREIGN_KEY_CHECKS = 1')\n }\n\n readonly capabilities = {\n enums: true,\n deferrableConstraints: false,\n returning: false,\n identityInsert: false\n }\n\n private mapMySqlType(mysqlType: string, columnType: string): NormalizedSqlType {\n const type = mysqlType.toLowerCase()\n if (type.includes('int')) return NormalizedSqlType.INT\n if (type.includes('bigint')) return NormalizedSqlType.BIGINT\n if (type.includes('char') || type.includes('varchar') || type === 'text' || type.includes('text')) return NormalizedSqlType.STRING\n if (type === 'tinyint' && columnType.includes('(1)')) return NormalizedSqlType.BOOLEAN\n if (type === 'date') return NormalizedSqlType.DATE\n if (type.includes('time') || type === 'datetime') return NormalizedSqlType.DATETIME\n if (type === 'json') return NormalizedSqlType.JSON\n if (type === 'decimal') return NormalizedSqlType.DECIMAL\n if (type === 'float' || type === 'double') return NormalizedSqlType.FLOAT\n if (type === 'enum') return NormalizedSqlType.ENUM\n if (type === 'blob' || type.includes('binary')) return NormalizedSqlType.BINARY\n\n return NormalizedSqlType.STRING\n }\n\n private parseEnumValues(columnType: string): string[] | undefined {\n if (!columnType.startsWith('enum(')) return undefined\n return columnType\n .slice(5, -1)\n .split(',')\n .map(v => v.trim().replace(/^'|'$/g, ''))\n }\n}\n\nexport function createMySqlAdapter(connectionString: string): MySqlAdapter {\n return new MySqlAdapter(connectionString)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAkB;AAClB,8BAOO;AAEA,IAAM,eAAN,MAAyC;AAAA,EACtC,aAAsC;AAAA,EACtC;AAAA,EAER,YAAY,kBAA0B;AACpC,SAAK,mBAAmB;AAAA,EAC1B;AAAA,EAEA,MAAM,UAAyB;AAC7B,SAAK,aAAa,MAAM,eAAAA,QAAM,iBAAiB,KAAK,gBAAgB;AAAA,EACtE;AAAA,EAEA,MAAM,aAA4B;AAChC,QAAI,KAAK,YAAY;AACnB,YAAM,KAAK,WAAW,IAAI;AAC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AAC5C,WAAO,WACJ,MAAM,GAAG,EAAE,EACX,MAAM,GAAG,EACT,IAAI,OAAK,EAAE,KAAK,EAAE,QAAQ,UAAU,EAAE,CAAC;AAAA,EAC5C;AACF;AAEO,SAAS,mBAAmB,kBAAwC;AACzE,SAAO,IAAI,aAAa,gBAAgB;AAC1C;","names":["mysql"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SqlAdapter, SchemaGraph, SeedBatch } from 'schema-seed-core';
|
|
2
|
+
|
|
3
|
+
declare class MySqlAdapter implements SqlAdapter {
|
|
4
|
+
private connection;
|
|
5
|
+
private connectionString;
|
|
6
|
+
constructor(connectionString: string);
|
|
7
|
+
connect(): Promise<void>;
|
|
8
|
+
disconnect(): Promise<void>;
|
|
9
|
+
begin(): Promise<void>;
|
|
10
|
+
commit(): Promise<void>;
|
|
11
|
+
rollback(): Promise<void>;
|
|
12
|
+
introspectSchema(): Promise<SchemaGraph>;
|
|
13
|
+
insertBatch(batch: SeedBatch): Promise<void>;
|
|
14
|
+
truncateTables(tableNames: string[]): Promise<void>;
|
|
15
|
+
readonly capabilities: {
|
|
16
|
+
enums: boolean;
|
|
17
|
+
deferrableConstraints: boolean;
|
|
18
|
+
returning: boolean;
|
|
19
|
+
identityInsert: boolean;
|
|
20
|
+
};
|
|
21
|
+
private mapMySqlType;
|
|
22
|
+
private parseEnumValues;
|
|
23
|
+
}
|
|
24
|
+
declare function createMySqlAdapter(connectionString: string): MySqlAdapter;
|
|
25
|
+
|
|
26
|
+
export { MySqlAdapter, createMySqlAdapter };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SqlAdapter, SchemaGraph, SeedBatch } from 'schema-seed-core';
|
|
2
|
+
|
|
3
|
+
declare class MySqlAdapter implements SqlAdapter {
|
|
4
|
+
private connection;
|
|
5
|
+
private connectionString;
|
|
6
|
+
constructor(connectionString: string);
|
|
7
|
+
connect(): Promise<void>;
|
|
8
|
+
disconnect(): Promise<void>;
|
|
9
|
+
begin(): Promise<void>;
|
|
10
|
+
commit(): Promise<void>;
|
|
11
|
+
rollback(): Promise<void>;
|
|
12
|
+
introspectSchema(): Promise<SchemaGraph>;
|
|
13
|
+
insertBatch(batch: SeedBatch): Promise<void>;
|
|
14
|
+
truncateTables(tableNames: string[]): Promise<void>;
|
|
15
|
+
readonly capabilities: {
|
|
16
|
+
enums: boolean;
|
|
17
|
+
deferrableConstraints: boolean;
|
|
18
|
+
returning: boolean;
|
|
19
|
+
identityInsert: boolean;
|
|
20
|
+
};
|
|
21
|
+
private mapMySqlType;
|
|
22
|
+
private parseEnumValues;
|
|
23
|
+
}
|
|
24
|
+
declare function createMySqlAdapter(connectionString: string): MySqlAdapter;
|
|
25
|
+
|
|
26
|
+
export { MySqlAdapter, createMySqlAdapter };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import mysql from "mysql2/promise";
|
|
3
|
+
import {
|
|
4
|
+
NormalizedSqlType
|
|
5
|
+
} from "schema-seed-core";
|
|
6
|
+
var MySqlAdapter = class {
|
|
7
|
+
connection = null;
|
|
8
|
+
connectionString;
|
|
9
|
+
constructor(connectionString) {
|
|
10
|
+
this.connectionString = connectionString;
|
|
11
|
+
}
|
|
12
|
+
async connect() {
|
|
13
|
+
this.connection = await mysql.createConnection(this.connectionString);
|
|
14
|
+
}
|
|
15
|
+
async disconnect() {
|
|
16
|
+
if (this.connection) {
|
|
17
|
+
await this.connection.end();
|
|
18
|
+
this.connection = null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async begin() {
|
|
22
|
+
await this.connection?.query("START TRANSACTION");
|
|
23
|
+
}
|
|
24
|
+
async commit() {
|
|
25
|
+
await this.connection?.query("COMMIT");
|
|
26
|
+
}
|
|
27
|
+
async rollback() {
|
|
28
|
+
await this.connection?.query("ROLLBACK");
|
|
29
|
+
}
|
|
30
|
+
async introspectSchema() {
|
|
31
|
+
if (!this.connection) throw new Error("Not connected");
|
|
32
|
+
const schema = { tables: {} };
|
|
33
|
+
const dbName = this.connection.config.database;
|
|
34
|
+
const [tables] = await this.connection.query(`
|
|
35
|
+
SELECT TABLE_NAME, TABLE_SCHEMA
|
|
36
|
+
FROM information_schema.TABLES
|
|
37
|
+
WHERE TABLE_SCHEMA = ? AND TABLE_TYPE = 'BASE TABLE'
|
|
38
|
+
`, [dbName]);
|
|
39
|
+
for (const row of tables) {
|
|
40
|
+
const tableName = row.TABLE_NAME;
|
|
41
|
+
schema.tables[tableName] = {
|
|
42
|
+
name: tableName,
|
|
43
|
+
schema: row.TABLE_SCHEMA,
|
|
44
|
+
columns: {},
|
|
45
|
+
foreignKeys: [],
|
|
46
|
+
uniqueConstraints: []
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const [columns] = await this.connection.query(`
|
|
50
|
+
SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT, EXTRA, COLUMN_TYPE
|
|
51
|
+
FROM information_schema.COLUMNS
|
|
52
|
+
WHERE TABLE_SCHEMA = ?
|
|
53
|
+
`, [dbName]);
|
|
54
|
+
for (const row of columns) {
|
|
55
|
+
if (!schema.tables[row.TABLE_NAME]) continue;
|
|
56
|
+
const col = {
|
|
57
|
+
name: row.COLUMN_NAME,
|
|
58
|
+
type: this.mapMySqlType(row.DATA_TYPE, row.COLUMN_TYPE),
|
|
59
|
+
rawType: row.DATA_TYPE,
|
|
60
|
+
nullable: row.IS_NULLABLE === "YES",
|
|
61
|
+
defaultValue: row.COLUMN_DEFAULT,
|
|
62
|
+
isAutoIncrement: row.EXTRA.includes("auto_increment"),
|
|
63
|
+
enumValues: this.parseEnumValues(row.COLUMN_TYPE)
|
|
64
|
+
};
|
|
65
|
+
schema.tables[row.TABLE_NAME].columns[row.COLUMN_NAME] = col;
|
|
66
|
+
}
|
|
67
|
+
const [fks] = await this.connection.query(`
|
|
68
|
+
SELECT
|
|
69
|
+
TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME,
|
|
70
|
+
REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME
|
|
71
|
+
FROM information_schema.KEY_COLUMN_USAGE
|
|
72
|
+
WHERE TABLE_SCHEMA = ? AND REFERENCED_TABLE_NAME IS NOT NULL
|
|
73
|
+
`, [dbName]);
|
|
74
|
+
for (const row of fks) {
|
|
75
|
+
if (!schema.tables[row.TABLE_NAME]) continue;
|
|
76
|
+
schema.tables[row.TABLE_NAME].foreignKeys.push({
|
|
77
|
+
name: row.CONSTRAINT_NAME,
|
|
78
|
+
columns: [row.COLUMN_NAME],
|
|
79
|
+
referencedTable: row.REFERENCED_TABLE_NAME,
|
|
80
|
+
referencedColumns: [row.REFERENCED_COLUMN_NAME]
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
const [pks] = await this.connection.query(`
|
|
84
|
+
SELECT TABLE_NAME, COLUMN_NAME
|
|
85
|
+
FROM information_schema.KEY_COLUMN_USAGE
|
|
86
|
+
WHERE TABLE_SCHEMA = ? AND CONSTRAINT_NAME = 'PRIMARY'
|
|
87
|
+
`, [dbName]);
|
|
88
|
+
for (const row of pks) {
|
|
89
|
+
if (!schema.tables[row.TABLE_NAME]) continue;
|
|
90
|
+
if (!schema.tables[row.TABLE_NAME].primaryKey) {
|
|
91
|
+
schema.tables[row.TABLE_NAME].primaryKey = { columns: [] };
|
|
92
|
+
}
|
|
93
|
+
schema.tables[row.TABLE_NAME].primaryKey.columns.push(row.COLUMN_NAME);
|
|
94
|
+
}
|
|
95
|
+
return schema;
|
|
96
|
+
}
|
|
97
|
+
async insertBatch(batch) {
|
|
98
|
+
if (!this.connection) throw new Error("Not connected");
|
|
99
|
+
const { tableName, rows } = batch;
|
|
100
|
+
if (rows.length === 0) return;
|
|
101
|
+
const columns = Object.keys(rows[0]);
|
|
102
|
+
const values = rows.map((row) => columns.map((col) => row[col]));
|
|
103
|
+
const query = `INSERT INTO \`${tableName}\` (${columns.map((c) => `\`${c}\``).join(", ")}) VALUES ?`;
|
|
104
|
+
await this.connection.query(query, [values]);
|
|
105
|
+
}
|
|
106
|
+
async truncateTables(tableNames) {
|
|
107
|
+
if (!this.connection) throw new Error("Not connected");
|
|
108
|
+
await this.connection.query("SET FOREIGN_KEY_CHECKS = 0");
|
|
109
|
+
for (const table of tableNames) {
|
|
110
|
+
await this.connection.query(`TRUNCATE TABLE \`${table}\``);
|
|
111
|
+
}
|
|
112
|
+
await this.connection.query("SET FOREIGN_KEY_CHECKS = 1");
|
|
113
|
+
}
|
|
114
|
+
capabilities = {
|
|
115
|
+
enums: true,
|
|
116
|
+
deferrableConstraints: false,
|
|
117
|
+
returning: false,
|
|
118
|
+
identityInsert: false
|
|
119
|
+
};
|
|
120
|
+
mapMySqlType(mysqlType, columnType) {
|
|
121
|
+
const type = mysqlType.toLowerCase();
|
|
122
|
+
if (type.includes("int")) return NormalizedSqlType.INT;
|
|
123
|
+
if (type.includes("bigint")) return NormalizedSqlType.BIGINT;
|
|
124
|
+
if (type.includes("char") || type.includes("varchar") || type === "text" || type.includes("text")) return NormalizedSqlType.STRING;
|
|
125
|
+
if (type === "tinyint" && columnType.includes("(1)")) return NormalizedSqlType.BOOLEAN;
|
|
126
|
+
if (type === "date") return NormalizedSqlType.DATE;
|
|
127
|
+
if (type.includes("time") || type === "datetime") return NormalizedSqlType.DATETIME;
|
|
128
|
+
if (type === "json") return NormalizedSqlType.JSON;
|
|
129
|
+
if (type === "decimal") return NormalizedSqlType.DECIMAL;
|
|
130
|
+
if (type === "float" || type === "double") return NormalizedSqlType.FLOAT;
|
|
131
|
+
if (type === "enum") return NormalizedSqlType.ENUM;
|
|
132
|
+
if (type === "blob" || type.includes("binary")) return NormalizedSqlType.BINARY;
|
|
133
|
+
return NormalizedSqlType.STRING;
|
|
134
|
+
}
|
|
135
|
+
parseEnumValues(columnType) {
|
|
136
|
+
if (!columnType.startsWith("enum(")) return void 0;
|
|
137
|
+
return columnType.slice(5, -1).split(",").map((v) => v.trim().replace(/^'|'$/g, ""));
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
function createMySqlAdapter(connectionString) {
|
|
141
|
+
return new MySqlAdapter(connectionString);
|
|
142
|
+
}
|
|
143
|
+
export {
|
|
144
|
+
MySqlAdapter,
|
|
145
|
+
createMySqlAdapter
|
|
146
|
+
};
|
|
147
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import mysql from 'mysql2/promise'\nimport {\n SqlAdapter,\n SchemaGraph,\n SeedBatch,\n NormalizedSqlType,\n TableSchema,\n ColumnSchema\n} from 'schema-seed-core'\n\nexport class MySqlAdapter implements SqlAdapter {\n private connection: mysql.Connection | null = null\n private connectionString: string\n\n constructor(connectionString: string) {\n this.connectionString = connectionString\n }\n\n async connect(): Promise<void> {\n this.connection = await mysql.createConnection(this.connectionString)\n }\n\n async disconnect(): Promise<void> {\n if (this.connection) {\n await this.connection.end()\n this.connection = null\n }\n }\n\n async begin(): Promise<void> {\n await this.connection?.query('START TRANSACTION')\n }\n\n async commit(): Promise<void> {\n await this.connection?.query('COMMIT')\n }\n\n async rollback(): Promise<void> {\n await this.connection?.query('ROLLBACK')\n }\n\n async introspectSchema(): Promise<SchemaGraph> {\n if (!this.connection) throw new Error('Not connected')\n\n const schema: SchemaGraph = { tables: {} }\n const dbName = this.connection.config.database\n\n // Get tables\n const [tables] = await this.connection.query<any[]>(`\n SELECT TABLE_NAME, TABLE_SCHEMA\n FROM information_schema.TABLES\n WHERE TABLE_SCHEMA = ? AND TABLE_TYPE = 'BASE TABLE'\n `, [dbName])\n\n for (const row of tables) {\n const tableName = row.TABLE_NAME\n schema.tables[tableName] = {\n name: tableName,\n schema: row.TABLE_SCHEMA,\n columns: {},\n foreignKeys: [],\n uniqueConstraints: []\n }\n }\n\n // Get columns\n const [columns] = await this.connection.query<any[]>(`\n SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT, EXTRA, COLUMN_TYPE\n FROM information_schema.COLUMNS\n WHERE TABLE_SCHEMA = ?\n `, [dbName])\n\n for (const row of columns) {\n if (!schema.tables[row.TABLE_NAME]) continue\n\n const col: ColumnSchema = {\n name: row.COLUMN_NAME,\n type: this.mapMySqlType(row.DATA_TYPE, row.COLUMN_TYPE),\n rawType: row.DATA_TYPE,\n nullable: row.IS_NULLABLE === 'YES',\n defaultValue: row.COLUMN_DEFAULT,\n isAutoIncrement: row.EXTRA.includes('auto_increment'),\n enumValues: this.parseEnumValues(row.COLUMN_TYPE)\n }\n schema.tables[row.TABLE_NAME].columns[row.COLUMN_NAME] = col\n }\n\n // Get Foreign Keys\n const [fks] = await this.connection.query<any[]>(`\n SELECT \n TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME, \n REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME\n FROM information_schema.KEY_COLUMN_USAGE\n WHERE TABLE_SCHEMA = ? AND REFERENCED_TABLE_NAME IS NOT NULL\n `, [dbName])\n\n for (const row of fks) {\n if (!schema.tables[row.TABLE_NAME]) continue\n schema.tables[row.TABLE_NAME].foreignKeys.push({\n name: row.CONSTRAINT_NAME,\n columns: [row.COLUMN_NAME],\n referencedTable: row.REFERENCED_TABLE_NAME,\n referencedColumns: [row.REFERENCED_COLUMN_NAME]\n })\n }\n\n // Get Primary Keys\n const [pks] = await this.connection.query<any[]>(`\n SELECT TABLE_NAME, COLUMN_NAME\n FROM information_schema.KEY_COLUMN_USAGE\n WHERE TABLE_SCHEMA = ? AND CONSTRAINT_NAME = 'PRIMARY'\n `, [dbName])\n\n for (const row of pks) {\n if (!schema.tables[row.TABLE_NAME]) continue\n if (!schema.tables[row.TABLE_NAME].primaryKey) {\n schema.tables[row.TABLE_NAME].primaryKey = { columns: [] }\n }\n schema.tables[row.TABLE_NAME].primaryKey!.columns.push(row.COLUMN_NAME)\n }\n\n return schema\n }\n\n async insertBatch(batch: SeedBatch): Promise<void> {\n if (!this.connection) throw new Error('Not connected')\n const { tableName, rows } = batch\n if (rows.length === 0) return\n\n const columns = Object.keys(rows[0])\n const values = rows.map(row => columns.map(col => row[col]))\n\n const query = `INSERT INTO \\`${tableName}\\` (${columns.map(c => `\\`${c}\\``).join(', ')}) VALUES ?`\n await this.connection.query(query, [values])\n }\n\n async truncateTables(tableNames: string[]): Promise<void> {\n if (!this.connection) throw new Error('Not connected')\n await this.connection.query('SET FOREIGN_KEY_CHECKS = 0')\n for (const table of tableNames) {\n await this.connection.query(`TRUNCATE TABLE \\`${table}\\``)\n }\n await this.connection.query('SET FOREIGN_KEY_CHECKS = 1')\n }\n\n readonly capabilities = {\n enums: true,\n deferrableConstraints: false,\n returning: false,\n identityInsert: false\n }\n\n private mapMySqlType(mysqlType: string, columnType: string): NormalizedSqlType {\n const type = mysqlType.toLowerCase()\n if (type.includes('int')) return NormalizedSqlType.INT\n if (type.includes('bigint')) return NormalizedSqlType.BIGINT\n if (type.includes('char') || type.includes('varchar') || type === 'text' || type.includes('text')) return NormalizedSqlType.STRING\n if (type === 'tinyint' && columnType.includes('(1)')) return NormalizedSqlType.BOOLEAN\n if (type === 'date') return NormalizedSqlType.DATE\n if (type.includes('time') || type === 'datetime') return NormalizedSqlType.DATETIME\n if (type === 'json') return NormalizedSqlType.JSON\n if (type === 'decimal') return NormalizedSqlType.DECIMAL\n if (type === 'float' || type === 'double') return NormalizedSqlType.FLOAT\n if (type === 'enum') return NormalizedSqlType.ENUM\n if (type === 'blob' || type.includes('binary')) return NormalizedSqlType.BINARY\n\n return NormalizedSqlType.STRING\n }\n\n private parseEnumValues(columnType: string): string[] | undefined {\n if (!columnType.startsWith('enum(')) return undefined\n return columnType\n .slice(5, -1)\n .split(',')\n .map(v => v.trim().replace(/^'|'$/g, ''))\n }\n}\n\nexport function createMySqlAdapter(connectionString: string): MySqlAdapter {\n return new MySqlAdapter(connectionString)\n}\n"],"mappings":";AAAA,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AS,OAAQ,QAAO,kBAAkB;AAC9C,QAAI,SAAS,UAAW,QAAO,kBAAkB;AACjD,QAAI,SAAS,WAAW,SAAS,SAAU,QAAO,kBAAkB;AACpE,QAAI,SAAS,OAAQ,QAAO,kBAAkB;AAC9C,QAAI,SAAS,UAAU,KAAK,SAAS,QAAQ,EAAG,QAAO,kBAAkB;AAEzE,WAAO,kBAAkB;AAAA,EAC3B;AAAA,EAEQ,gBAAgB,YAA0C;AAChE,QAAI,CAAC,WAAW,WAAW,OAAO,EAAG,QAAO;AAC5C,WAAO,WACJ,MAAM,GAAG,EAAE,EACX,MAAM,GAAG,EACT,IAAI,OAAK,EAAE,KAAK,EAAE,QAAQ,UAAU,EAAE,CAAC;AAAA,EAC5C;AACF;AAEO,SAAS,mBAAmB,kBAAwC;AACzE,SAAO,IAAI,aAAa,gBAAgB;AAC1C;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "schema-seed-adapter-mysql",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "MySQL adapter for schema-seed",
|
|
6
|
+
"author": "Ali Nazar",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"private": false,
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/alinazar-111/schema-seed.git"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/alinazar-111/schema-seed#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/alinazar-111/schema-seed/issues"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"database",
|
|
20
|
+
"seeding",
|
|
21
|
+
"test-data",
|
|
22
|
+
"adapter",
|
|
23
|
+
"schema-seed"
|
|
24
|
+
],
|
|
25
|
+
"main": "./dist/index.cjs",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js",
|
|
32
|
+
"require": "./dist/index.cjs"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"mysql2": "^3.11.3",
|
|
42
|
+
"schema-seed-core": "0.1.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"tsup": "^8.3.5",
|
|
46
|
+
"typescript": "^5.7.2",
|
|
47
|
+
"vitest": "^2.1.8"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsup",
|
|
51
|
+
"clean": "rm -rf dist",
|
|
52
|
+
"dev": "tsup --watch",
|
|
53
|
+
"lint": "eslint .",
|
|
54
|
+
"test": "vitest run --passWithNoTests",
|
|
55
|
+
"typecheck": "tsc --noEmit"
|
|
56
|
+
}
|
|
57
|
+
}
|