@atscript/db-mysql 0.1.203 → 0.1.205
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.cjs +25 -18
- package/dist/index.d.cts +8 -4
- package/dist/index.d.mts +8 -4
- package/dist/index.mjs +25 -18
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -256,7 +256,8 @@ const mysqlDialect = {
|
|
|
256
256
|
castDouble: (expr) => `CAST(${expr} AS DOUBLE)`,
|
|
257
257
|
conditionalAggregate: "case",
|
|
258
258
|
countDistinctColumns: (columns, when) => `COUNT(DISTINCT ${columns.map((c) => when ? `CASE WHEN ${when} THEN ${c} END` : c).join(", ")})`,
|
|
259
|
-
createViewPrefix: "CREATE OR REPLACE VIEW"
|
|
259
|
+
createViewPrefix: "CREATE OR REPLACE VIEW",
|
|
260
|
+
schemaQualified: true
|
|
260
261
|
};
|
|
261
262
|
/** `JSON_TYPE()` names of JSON numbers (MariaDB reports only INTEGER / DOUBLE). */
|
|
262
263
|
const MYSQL_JSON_NUMBER_TYPES = "'INTEGER', 'UNSIGNED INTEGER', 'DOUBLE', 'DECIMAL'";
|
|
@@ -959,6 +960,10 @@ var MysqlAdapter = class MysqlAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
959
960
|
get _schema() {
|
|
960
961
|
return this._table?.schema ?? null;
|
|
961
962
|
}
|
|
963
|
+
/** `name`, quoted and qualified with `schema` (default: the bound table's `@db.schema`, its database). */
|
|
964
|
+
_qualify(name, schema = this._schema) {
|
|
965
|
+
return quoteTableName(schema ? `${schema}.${name}` : name);
|
|
966
|
+
}
|
|
962
967
|
constructor(driver, options) {
|
|
963
968
|
super();
|
|
964
969
|
this.driver = driver;
|
|
@@ -1997,7 +2002,7 @@ var MysqlAdapter = class MysqlAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
1997
2002
|
}
|
|
1998
2003
|
/** The quoted table `tableName` of the adapter's schema, or the adapter's own. */
|
|
1999
2004
|
_quotedTable(tableName) {
|
|
2000
|
-
return
|
|
2005
|
+
return tableName ? this._qualify(tableName) : quoteTableName(this.resolveTableName());
|
|
2001
2006
|
}
|
|
2002
2007
|
async hasRows(tableName) {
|
|
2003
2008
|
const sql = `SELECT EXISTS(SELECT 1 FROM ${this._quotedTable(tableName)}) AS present`;
|
|
@@ -2012,11 +2017,11 @@ var MysqlAdapter = class MysqlAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
2012
2017
|
return Number(row?.violations ?? 0);
|
|
2013
2018
|
}
|
|
2014
2019
|
/** Live foreign keys referencing `tableName` (any table of the schema). */
|
|
2015
|
-
async getReferencingForeignKeys(tableName) {
|
|
2020
|
+
async getReferencingForeignKeys(tableName, schema) {
|
|
2016
2021
|
const rows = await this._exec().all(`SELECT TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_COLUMN_NAME
|
|
2017
2022
|
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
|
|
2018
2023
|
WHERE REFERENCED_TABLE_NAME = ? AND REFERENCED_TABLE_SCHEMA = COALESCE(?, DATABASE())
|
|
2019
|
-
ORDER BY TABLE_NAME, CONSTRAINT_NAME, ORDINAL_POSITION`, [tableName, this._schema]);
|
|
2024
|
+
ORDER BY TABLE_NAME, CONSTRAINT_NAME, ORDINAL_POSITION`, [tableName, schema ?? this._schema]);
|
|
2020
2025
|
const byConstraint = /* @__PURE__ */ new Map();
|
|
2021
2026
|
for (const r of rows) {
|
|
2022
2027
|
const key = `${r.TABLE_NAME}\0${r.CONSTRAINT_NAME}`;
|
|
@@ -2034,9 +2039,9 @@ var MysqlAdapter = class MysqlAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
2034
2039
|
}
|
|
2035
2040
|
return [...byConstraint.values()];
|
|
2036
2041
|
}
|
|
2037
|
-
async getObjectKind(name) {
|
|
2042
|
+
async getObjectKind(name, schema) {
|
|
2038
2043
|
const row = await this._exec().get(`SELECT TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES
|
|
2039
|
-
WHERE TABLE_NAME = ? AND TABLE_SCHEMA = COALESCE(?, DATABASE())`, [name, this._schema]);
|
|
2044
|
+
WHERE TABLE_NAME = ? AND TABLE_SCHEMA = COALESCE(?, DATABASE())`, [name, schema ?? this._schema]);
|
|
2040
2045
|
if (!row) return;
|
|
2041
2046
|
return row.TABLE_TYPE.toUpperCase() === "VIEW" ? "view" : "table";
|
|
2042
2047
|
}
|
|
@@ -2503,13 +2508,13 @@ var MysqlAdapter = class MysqlAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
2503
2508
|
}
|
|
2504
2509
|
async recreateTable() {
|
|
2505
2510
|
const tableName = this.resolveTableName();
|
|
2506
|
-
const
|
|
2511
|
+
const tempTable = `${tableName}__tmp_${Date.now()}`;
|
|
2507
2512
|
return this._withStrictSession(async (conn) => {
|
|
2508
2513
|
await conn.exec("SET FOREIGN_KEY_CHECKS = 0");
|
|
2509
2514
|
await withSessionRestore(conn, "SET FOREIGN_KEY_CHECKS = 1", async () => {
|
|
2510
2515
|
let originalDropped = false;
|
|
2511
2516
|
try {
|
|
2512
|
-
const createSql = buildCreateTable(
|
|
2517
|
+
const createSql = buildCreateTable(tempTable, this._table.fieldDescriptors, this._table.foreignKeys, this._tableOptions());
|
|
2513
2518
|
this._log(createSql);
|
|
2514
2519
|
await conn.exec(createSql);
|
|
2515
2520
|
const oldCols = (await this._readColumns(conn, this._table.tableName)).map((c) => c.name);
|
|
@@ -2527,23 +2532,23 @@ var MysqlAdapter = class MysqlAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
2527
2532
|
}
|
|
2528
2533
|
return qi(c);
|
|
2529
2534
|
}).join(", ");
|
|
2530
|
-
const copySql = `INSERT INTO ${
|
|
2535
|
+
const copySql = `INSERT INTO ${quoteTableName(tempTable)} (${colNames}) SELECT ${selectExprs} FROM ${quoteTableName(tableName)}`;
|
|
2531
2536
|
this._log(copySql);
|
|
2532
2537
|
await conn.exec(copySql);
|
|
2533
2538
|
}
|
|
2534
2539
|
await conn.exec(`DROP TABLE IF EXISTS ${quoteTableName(tableName)}`);
|
|
2535
2540
|
originalDropped = true;
|
|
2536
|
-
await conn.exec(`RENAME TABLE ${
|
|
2541
|
+
await conn.exec(`RENAME TABLE ${quoteTableName(tempTable)} TO ${quoteTableName(tableName)}`);
|
|
2537
2542
|
} catch (error) {
|
|
2538
|
-
if (originalDropped) throw new Error(`Recreate of "${tableName}" failed after the original table was dropped; its rows are in "${
|
|
2539
|
-
await conn.exec(`DROP TABLE IF EXISTS ${
|
|
2543
|
+
if (originalDropped) throw new Error(`Recreate of "${tableName}" failed after the original table was dropped; its rows are in "${tempTable}"`, { cause: error });
|
|
2544
|
+
await conn.exec(`DROP TABLE IF EXISTS ${quoteTableName(tempTable)}`).catch(() => void 0);
|
|
2540
2545
|
throw error;
|
|
2541
2546
|
}
|
|
2542
2547
|
});
|
|
2543
2548
|
});
|
|
2544
2549
|
}
|
|
2545
2550
|
async dropTable() {
|
|
2546
|
-
return this.dropTableByName(this.
|
|
2551
|
+
return this.dropTableByName(this._table.tableName);
|
|
2547
2552
|
}
|
|
2548
2553
|
async copyFromJsonColumn(source, targets) {
|
|
2549
2554
|
const temporal = targets.find((t) => mysqlTemporalFsp(t.field) !== void 0);
|
|
@@ -2577,8 +2582,9 @@ var MysqlAdapter = class MysqlAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
2577
2582
|
]);
|
|
2578
2583
|
for (const row of rows) await this._dropIndex(row.name);
|
|
2579
2584
|
}
|
|
2580
|
-
|
|
2581
|
-
|
|
2585
|
+
/** In `schema` — its database (since 0.1.205) — else the bound table's, else `DATABASE()`. */
|
|
2586
|
+
async dropTableByName(tableName, schema) {
|
|
2587
|
+
const ddl = `DROP TABLE IF EXISTS ${this._qualify(tableName, schema)}`;
|
|
2582
2588
|
this._log(ddl);
|
|
2583
2589
|
try {
|
|
2584
2590
|
await this._onDedicatedConnection((conn) => withSessionRestore(conn, "SET FOREIGN_KEY_CHECKS = 1", async () => {
|
|
@@ -2589,15 +2595,16 @@ var MysqlAdapter = class MysqlAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
2589
2595
|
throw mapContention(error);
|
|
2590
2596
|
}
|
|
2591
2597
|
}
|
|
2592
|
-
|
|
2593
|
-
|
|
2598
|
+
/** In `schema` — its database (since 0.1.205) — else the bound table's, else `DATABASE()`. */
|
|
2599
|
+
async dropViewByName(viewName, schema) {
|
|
2600
|
+
const ddl = `DROP VIEW IF EXISTS ${this._qualify(viewName, schema)}`;
|
|
2594
2601
|
this._log(ddl);
|
|
2595
2602
|
await this._exec().exec(ddl);
|
|
2596
2603
|
}
|
|
2597
2604
|
async renameTable(oldName) {
|
|
2598
2605
|
const newName = this.resolveTableName();
|
|
2599
2606
|
if (!await this.getObjectKind(oldName) && await this.getObjectKind(this._table.tableName)) return;
|
|
2600
|
-
const ddl = `RENAME TABLE ${
|
|
2607
|
+
const ddl = `RENAME TABLE ${this._qualify(oldName)} TO ${quoteTableName(newName)}`;
|
|
2601
2608
|
this._log(ddl);
|
|
2602
2609
|
await this._exec().exec(ddl);
|
|
2603
2610
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -157,6 +157,8 @@ declare class MysqlAdapter extends BaseDbAdapter {
|
|
|
157
157
|
* (the name-taking schema-sync primitives run on such an adapter).
|
|
158
158
|
*/
|
|
159
159
|
private get _schema();
|
|
160
|
+
/** `name`, quoted and qualified with `schema` (default: the bound table's `@db.schema`, its database). */
|
|
161
|
+
private _qualify;
|
|
160
162
|
constructor(driver: TMysqlDriver, options?: TMysqlAdapterOptions);
|
|
161
163
|
/**
|
|
162
164
|
* The FROM source of a read of this adapter's table or view: a managed
|
|
@@ -469,8 +471,8 @@ declare class MysqlAdapter extends BaseDbAdapter {
|
|
|
469
471
|
hasRows(tableName?: string): Promise<boolean>;
|
|
470
472
|
countKeyViolations(columns: readonly string[], tableName?: string): Promise<number>;
|
|
471
473
|
/** Live foreign keys referencing `tableName` (any table of the schema). */
|
|
472
|
-
getReferencingForeignKeys(tableName: string): Promise<TReferencingForeignKey[]>;
|
|
473
|
-
getObjectKind(name: string): Promise<TDbObjectKind | undefined>;
|
|
474
|
+
getReferencingForeignKeys(tableName: string, schema?: string): Promise<TReferencingForeignKey[]>;
|
|
475
|
+
getObjectKind(name: string, schema?: string): Promise<TDbObjectKind | undefined>;
|
|
474
476
|
/**
|
|
475
477
|
* One `ALTER TABLE … [MODIFY …,] DROP PRIMARY KEY, ADD PRIMARY KEY (…)`
|
|
476
478
|
* statement (atomic). The sole owner of the columns entering the key:
|
|
@@ -556,8 +558,10 @@ declare class MysqlAdapter extends BaseDbAdapter {
|
|
|
556
558
|
jsonifyTextColumn(column: string): Promise<void>;
|
|
557
559
|
dropColumns(columns: string[]): Promise<void>;
|
|
558
560
|
dropIndexesForColumns(columns: string[]): Promise<void>;
|
|
559
|
-
|
|
560
|
-
|
|
561
|
+
/** In `schema` — its database (since 0.1.205) — else the bound table's, else `DATABASE()`. */
|
|
562
|
+
dropTableByName(tableName: string, schema?: string): Promise<void>;
|
|
563
|
+
/** In `schema` — its database (since 0.1.205) — else the bound table's, else `DATABASE()`. */
|
|
564
|
+
dropViewByName(viewName: string, schema?: string): Promise<void>;
|
|
561
565
|
renameTable(oldName: string): Promise<void>;
|
|
562
566
|
/** Keeps the space: {@link typeMapper} asks it which fields a foreign key references. */
|
|
563
567
|
registerSpace(space: DbSpace): void;
|
package/dist/index.d.mts
CHANGED
|
@@ -157,6 +157,8 @@ declare class MysqlAdapter extends BaseDbAdapter {
|
|
|
157
157
|
* (the name-taking schema-sync primitives run on such an adapter).
|
|
158
158
|
*/
|
|
159
159
|
private get _schema();
|
|
160
|
+
/** `name`, quoted and qualified with `schema` (default: the bound table's `@db.schema`, its database). */
|
|
161
|
+
private _qualify;
|
|
160
162
|
constructor(driver: TMysqlDriver, options?: TMysqlAdapterOptions);
|
|
161
163
|
/**
|
|
162
164
|
* The FROM source of a read of this adapter's table or view: a managed
|
|
@@ -469,8 +471,8 @@ declare class MysqlAdapter extends BaseDbAdapter {
|
|
|
469
471
|
hasRows(tableName?: string): Promise<boolean>;
|
|
470
472
|
countKeyViolations(columns: readonly string[], tableName?: string): Promise<number>;
|
|
471
473
|
/** Live foreign keys referencing `tableName` (any table of the schema). */
|
|
472
|
-
getReferencingForeignKeys(tableName: string): Promise<TReferencingForeignKey[]>;
|
|
473
|
-
getObjectKind(name: string): Promise<TDbObjectKind | undefined>;
|
|
474
|
+
getReferencingForeignKeys(tableName: string, schema?: string): Promise<TReferencingForeignKey[]>;
|
|
475
|
+
getObjectKind(name: string, schema?: string): Promise<TDbObjectKind | undefined>;
|
|
474
476
|
/**
|
|
475
477
|
* One `ALTER TABLE … [MODIFY …,] DROP PRIMARY KEY, ADD PRIMARY KEY (…)`
|
|
476
478
|
* statement (atomic). The sole owner of the columns entering the key:
|
|
@@ -556,8 +558,10 @@ declare class MysqlAdapter extends BaseDbAdapter {
|
|
|
556
558
|
jsonifyTextColumn(column: string): Promise<void>;
|
|
557
559
|
dropColumns(columns: string[]): Promise<void>;
|
|
558
560
|
dropIndexesForColumns(columns: string[]): Promise<void>;
|
|
559
|
-
|
|
560
|
-
|
|
561
|
+
/** In `schema` — its database (since 0.1.205) — else the bound table's, else `DATABASE()`. */
|
|
562
|
+
dropTableByName(tableName: string, schema?: string): Promise<void>;
|
|
563
|
+
/** In `schema` — its database (since 0.1.205) — else the bound table's, else `DATABASE()`. */
|
|
564
|
+
dropViewByName(viewName: string, schema?: string): Promise<void>;
|
|
561
565
|
renameTable(oldName: string): Promise<void>;
|
|
562
566
|
/** Keeps the space: {@link typeMapper} asks it which fields a foreign key references. */
|
|
563
567
|
registerSpace(space: DbSpace): void;
|
package/dist/index.mjs
CHANGED
|
@@ -255,7 +255,8 @@ const mysqlDialect = {
|
|
|
255
255
|
castDouble: (expr) => `CAST(${expr} AS DOUBLE)`,
|
|
256
256
|
conditionalAggregate: "case",
|
|
257
257
|
countDistinctColumns: (columns, when) => `COUNT(DISTINCT ${columns.map((c) => when ? `CASE WHEN ${when} THEN ${c} END` : c).join(", ")})`,
|
|
258
|
-
createViewPrefix: "CREATE OR REPLACE VIEW"
|
|
258
|
+
createViewPrefix: "CREATE OR REPLACE VIEW",
|
|
259
|
+
schemaQualified: true
|
|
259
260
|
};
|
|
260
261
|
/** `JSON_TYPE()` names of JSON numbers (MariaDB reports only INTEGER / DOUBLE). */
|
|
261
262
|
const MYSQL_JSON_NUMBER_TYPES = "'INTEGER', 'UNSIGNED INTEGER', 'DOUBLE', 'DECIMAL'";
|
|
@@ -958,6 +959,10 @@ var MysqlAdapter = class MysqlAdapter extends BaseDbAdapter {
|
|
|
958
959
|
get _schema() {
|
|
959
960
|
return this._table?.schema ?? null;
|
|
960
961
|
}
|
|
962
|
+
/** `name`, quoted and qualified with `schema` (default: the bound table's `@db.schema`, its database). */
|
|
963
|
+
_qualify(name, schema = this._schema) {
|
|
964
|
+
return quoteTableName(schema ? `${schema}.${name}` : name);
|
|
965
|
+
}
|
|
961
966
|
constructor(driver, options) {
|
|
962
967
|
super();
|
|
963
968
|
this.driver = driver;
|
|
@@ -1996,7 +2001,7 @@ var MysqlAdapter = class MysqlAdapter extends BaseDbAdapter {
|
|
|
1996
2001
|
}
|
|
1997
2002
|
/** The quoted table `tableName` of the adapter's schema, or the adapter's own. */
|
|
1998
2003
|
_quotedTable(tableName) {
|
|
1999
|
-
return
|
|
2004
|
+
return tableName ? this._qualify(tableName) : quoteTableName(this.resolveTableName());
|
|
2000
2005
|
}
|
|
2001
2006
|
async hasRows(tableName) {
|
|
2002
2007
|
const sql = `SELECT EXISTS(SELECT 1 FROM ${this._quotedTable(tableName)}) AS present`;
|
|
@@ -2011,11 +2016,11 @@ var MysqlAdapter = class MysqlAdapter extends BaseDbAdapter {
|
|
|
2011
2016
|
return Number(row?.violations ?? 0);
|
|
2012
2017
|
}
|
|
2013
2018
|
/** Live foreign keys referencing `tableName` (any table of the schema). */
|
|
2014
|
-
async getReferencingForeignKeys(tableName) {
|
|
2019
|
+
async getReferencingForeignKeys(tableName, schema) {
|
|
2015
2020
|
const rows = await this._exec().all(`SELECT TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_COLUMN_NAME
|
|
2016
2021
|
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
|
|
2017
2022
|
WHERE REFERENCED_TABLE_NAME = ? AND REFERENCED_TABLE_SCHEMA = COALESCE(?, DATABASE())
|
|
2018
|
-
ORDER BY TABLE_NAME, CONSTRAINT_NAME, ORDINAL_POSITION`, [tableName, this._schema]);
|
|
2023
|
+
ORDER BY TABLE_NAME, CONSTRAINT_NAME, ORDINAL_POSITION`, [tableName, schema ?? this._schema]);
|
|
2019
2024
|
const byConstraint = /* @__PURE__ */ new Map();
|
|
2020
2025
|
for (const r of rows) {
|
|
2021
2026
|
const key = `${r.TABLE_NAME}\0${r.CONSTRAINT_NAME}`;
|
|
@@ -2033,9 +2038,9 @@ var MysqlAdapter = class MysqlAdapter extends BaseDbAdapter {
|
|
|
2033
2038
|
}
|
|
2034
2039
|
return [...byConstraint.values()];
|
|
2035
2040
|
}
|
|
2036
|
-
async getObjectKind(name) {
|
|
2041
|
+
async getObjectKind(name, schema) {
|
|
2037
2042
|
const row = await this._exec().get(`SELECT TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES
|
|
2038
|
-
WHERE TABLE_NAME = ? AND TABLE_SCHEMA = COALESCE(?, DATABASE())`, [name, this._schema]);
|
|
2043
|
+
WHERE TABLE_NAME = ? AND TABLE_SCHEMA = COALESCE(?, DATABASE())`, [name, schema ?? this._schema]);
|
|
2039
2044
|
if (!row) return;
|
|
2040
2045
|
return row.TABLE_TYPE.toUpperCase() === "VIEW" ? "view" : "table";
|
|
2041
2046
|
}
|
|
@@ -2502,13 +2507,13 @@ var MysqlAdapter = class MysqlAdapter extends BaseDbAdapter {
|
|
|
2502
2507
|
}
|
|
2503
2508
|
async recreateTable() {
|
|
2504
2509
|
const tableName = this.resolveTableName();
|
|
2505
|
-
const
|
|
2510
|
+
const tempTable = `${tableName}__tmp_${Date.now()}`;
|
|
2506
2511
|
return this._withStrictSession(async (conn) => {
|
|
2507
2512
|
await conn.exec("SET FOREIGN_KEY_CHECKS = 0");
|
|
2508
2513
|
await withSessionRestore(conn, "SET FOREIGN_KEY_CHECKS = 1", async () => {
|
|
2509
2514
|
let originalDropped = false;
|
|
2510
2515
|
try {
|
|
2511
|
-
const createSql = buildCreateTable(
|
|
2516
|
+
const createSql = buildCreateTable(tempTable, this._table.fieldDescriptors, this._table.foreignKeys, this._tableOptions());
|
|
2512
2517
|
this._log(createSql);
|
|
2513
2518
|
await conn.exec(createSql);
|
|
2514
2519
|
const oldCols = (await this._readColumns(conn, this._table.tableName)).map((c) => c.name);
|
|
@@ -2526,23 +2531,23 @@ var MysqlAdapter = class MysqlAdapter extends BaseDbAdapter {
|
|
|
2526
2531
|
}
|
|
2527
2532
|
return qi(c);
|
|
2528
2533
|
}).join(", ");
|
|
2529
|
-
const copySql = `INSERT INTO ${
|
|
2534
|
+
const copySql = `INSERT INTO ${quoteTableName(tempTable)} (${colNames}) SELECT ${selectExprs} FROM ${quoteTableName(tableName)}`;
|
|
2530
2535
|
this._log(copySql);
|
|
2531
2536
|
await conn.exec(copySql);
|
|
2532
2537
|
}
|
|
2533
2538
|
await conn.exec(`DROP TABLE IF EXISTS ${quoteTableName(tableName)}`);
|
|
2534
2539
|
originalDropped = true;
|
|
2535
|
-
await conn.exec(`RENAME TABLE ${
|
|
2540
|
+
await conn.exec(`RENAME TABLE ${quoteTableName(tempTable)} TO ${quoteTableName(tableName)}`);
|
|
2536
2541
|
} catch (error) {
|
|
2537
|
-
if (originalDropped) throw new Error(`Recreate of "${tableName}" failed after the original table was dropped; its rows are in "${
|
|
2538
|
-
await conn.exec(`DROP TABLE IF EXISTS ${
|
|
2542
|
+
if (originalDropped) throw new Error(`Recreate of "${tableName}" failed after the original table was dropped; its rows are in "${tempTable}"`, { cause: error });
|
|
2543
|
+
await conn.exec(`DROP TABLE IF EXISTS ${quoteTableName(tempTable)}`).catch(() => void 0);
|
|
2539
2544
|
throw error;
|
|
2540
2545
|
}
|
|
2541
2546
|
});
|
|
2542
2547
|
});
|
|
2543
2548
|
}
|
|
2544
2549
|
async dropTable() {
|
|
2545
|
-
return this.dropTableByName(this.
|
|
2550
|
+
return this.dropTableByName(this._table.tableName);
|
|
2546
2551
|
}
|
|
2547
2552
|
async copyFromJsonColumn(source, targets) {
|
|
2548
2553
|
const temporal = targets.find((t) => mysqlTemporalFsp(t.field) !== void 0);
|
|
@@ -2576,8 +2581,9 @@ var MysqlAdapter = class MysqlAdapter extends BaseDbAdapter {
|
|
|
2576
2581
|
]);
|
|
2577
2582
|
for (const row of rows) await this._dropIndex(row.name);
|
|
2578
2583
|
}
|
|
2579
|
-
|
|
2580
|
-
|
|
2584
|
+
/** In `schema` — its database (since 0.1.205) — else the bound table's, else `DATABASE()`. */
|
|
2585
|
+
async dropTableByName(tableName, schema) {
|
|
2586
|
+
const ddl = `DROP TABLE IF EXISTS ${this._qualify(tableName, schema)}`;
|
|
2581
2587
|
this._log(ddl);
|
|
2582
2588
|
try {
|
|
2583
2589
|
await this._onDedicatedConnection((conn) => withSessionRestore(conn, "SET FOREIGN_KEY_CHECKS = 1", async () => {
|
|
@@ -2588,15 +2594,16 @@ var MysqlAdapter = class MysqlAdapter extends BaseDbAdapter {
|
|
|
2588
2594
|
throw mapContention(error);
|
|
2589
2595
|
}
|
|
2590
2596
|
}
|
|
2591
|
-
|
|
2592
|
-
|
|
2597
|
+
/** In `schema` — its database (since 0.1.205) — else the bound table's, else `DATABASE()`. */
|
|
2598
|
+
async dropViewByName(viewName, schema) {
|
|
2599
|
+
const ddl = `DROP VIEW IF EXISTS ${this._qualify(viewName, schema)}`;
|
|
2593
2600
|
this._log(ddl);
|
|
2594
2601
|
await this._exec().exec(ddl);
|
|
2595
2602
|
}
|
|
2596
2603
|
async renameTable(oldName) {
|
|
2597
2604
|
const newName = this.resolveTableName();
|
|
2598
2605
|
if (!await this.getObjectKind(oldName) && await this.getObjectKind(this._table.tableName)) return;
|
|
2599
|
-
const ddl = `RENAME TABLE ${
|
|
2606
|
+
const ddl = `RENAME TABLE ${this._qualify(oldName)} TO ${quoteTableName(newName)}`;
|
|
2600
2607
|
this._log(ddl);
|
|
2601
2608
|
await this._exec().exec(ddl);
|
|
2602
2609
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/db-mysql",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.205",
|
|
4
4
|
"description": "MySQL adapter for @atscript/db with mysql2 driver support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"atscript",
|
|
@@ -41,21 +41,21 @@
|
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@atscript/db-sql-tools": "^0.1.
|
|
44
|
+
"@atscript/db-sql-tools": "^0.1.205"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@atscript/core": "^0.2.
|
|
48
|
-
"@atscript/typescript": "^0.2.
|
|
47
|
+
"@atscript/core": "^0.2.29",
|
|
48
|
+
"@atscript/typescript": "^0.2.29",
|
|
49
49
|
"@uniqu/core": "^0.2.2",
|
|
50
50
|
"mysql2": "^3.11.0",
|
|
51
|
-
"unplugin-atscript": "^0.2.
|
|
51
|
+
"unplugin-atscript": "^0.2.29"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@atscript/core": "^0.2.
|
|
55
|
-
"@atscript/typescript": "^0.2.
|
|
54
|
+
"@atscript/core": "^0.2.29",
|
|
55
|
+
"@atscript/typescript": "^0.2.29",
|
|
56
56
|
"@uniqu/core": "^0.2.2",
|
|
57
57
|
"mysql2": ">=3.0.0",
|
|
58
|
-
"@atscript/db": "^0.1.
|
|
58
|
+
"@atscript/db": "^0.1.205"
|
|
59
59
|
},
|
|
60
60
|
"peerDependenciesMeta": {
|
|
61
61
|
"mysql2": {
|