@atscript/db-sqlite 0.1.137 → 0.1.139
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 +28 -28
- package/dist/index.mjs +28 -28
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1075,37 +1075,37 @@ var SqliteAdapter = class SqliteAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
1075
1075
|
return this._withExclusiveConnection(async () => {
|
|
1076
1076
|
const tableName = this.resolveTableName();
|
|
1077
1077
|
const tempName = `${tableName}__tmp_${Date.now()}`;
|
|
1078
|
-
this._dropAllFtsTables(tableName);
|
|
1079
|
-
this._dropAllVecTables(tableName);
|
|
1080
1078
|
this.driver.exec("PRAGMA foreign_keys = OFF");
|
|
1081
1079
|
this.driver.exec("PRAGMA legacy_alter_table = ON");
|
|
1082
1080
|
try {
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
const
|
|
1092
|
-
const
|
|
1093
|
-
|
|
1094
|
-
const
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1081
|
+
await this.withTransaction(async () => {
|
|
1082
|
+
this._dropAllFtsTables(tableName);
|
|
1083
|
+
this._dropAllVecTables(tableName);
|
|
1084
|
+
const createSql = buildCreateTable(tempName, this._table.fieldDescriptors, this._table.foreignKeys, { typeMapper: (field) => this.typeMapper(field) });
|
|
1085
|
+
this._log(createSql);
|
|
1086
|
+
this.driver.exec(createSql);
|
|
1087
|
+
const oldCols = (await this.getExistingColumns()).map((c) => c.name);
|
|
1088
|
+
const newCols = this._table.fieldDescriptors.filter((f) => !f.ignored).map((f) => f.physicalName);
|
|
1089
|
+
const oldColSet = new Set(oldCols);
|
|
1090
|
+
const commonCols = newCols.filter((c) => oldColSet.has(c));
|
|
1091
|
+
if (commonCols.length > 0) {
|
|
1092
|
+
const fieldsByName = new Map(this._table.fieldDescriptors.map((f) => [f.physicalName, f]));
|
|
1093
|
+
const colNames = commonCols.map((c) => `"${esc(c)}"`).join(", ");
|
|
1094
|
+
const selectExprs = commonCols.map((c) => {
|
|
1095
|
+
const field = fieldsByName.get(c);
|
|
1096
|
+
if (field && !field.optional && !field.isPrimaryKey) {
|
|
1097
|
+
const fallback = field.defaultValue?.kind === "value" ? (0, _atscript_db_sql_tools.defaultValueToSqlLiteral)(field.designType, field.defaultValue.value) : (0, _atscript_db_sql_tools.defaultValueForType)(field.designType);
|
|
1098
|
+
return `COALESCE("${esc(c)}", ${fallback}) AS "${esc(c)}"`;
|
|
1099
|
+
}
|
|
1100
|
+
return `"${esc(c)}"`;
|
|
1101
|
+
}).join(", ");
|
|
1102
|
+
const copySql = `INSERT INTO "${esc(tempName)}" (${colNames}) SELECT ${selectExprs} FROM "${esc(tableName)}"`;
|
|
1103
|
+
this._log(copySql);
|
|
1104
|
+
this.driver.exec(copySql);
|
|
1105
|
+
}
|
|
1106
|
+
this.driver.exec(`DROP TABLE IF EXISTS "${esc(tableName)}"`);
|
|
1107
|
+
this.driver.exec(`ALTER TABLE "${esc(tempName)}" RENAME TO "${esc(tableName)}"`);
|
|
1108
|
+
});
|
|
1109
1109
|
} finally {
|
|
1110
1110
|
this.driver.exec("PRAGMA legacy_alter_table = OFF");
|
|
1111
1111
|
this.driver.exec("PRAGMA foreign_keys = ON");
|
package/dist/index.mjs
CHANGED
|
@@ -1074,37 +1074,37 @@ var SqliteAdapter = class SqliteAdapter extends BaseDbAdapter {
|
|
|
1074
1074
|
return this._withExclusiveConnection(async () => {
|
|
1075
1075
|
const tableName = this.resolveTableName();
|
|
1076
1076
|
const tempName = `${tableName}__tmp_${Date.now()}`;
|
|
1077
|
-
this._dropAllFtsTables(tableName);
|
|
1078
|
-
this._dropAllVecTables(tableName);
|
|
1079
1077
|
this.driver.exec("PRAGMA foreign_keys = OFF");
|
|
1080
1078
|
this.driver.exec("PRAGMA legacy_alter_table = ON");
|
|
1081
1079
|
try {
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
const
|
|
1091
|
-
const
|
|
1092
|
-
|
|
1093
|
-
const
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1080
|
+
await this.withTransaction(async () => {
|
|
1081
|
+
this._dropAllFtsTables(tableName);
|
|
1082
|
+
this._dropAllVecTables(tableName);
|
|
1083
|
+
const createSql = buildCreateTable(tempName, this._table.fieldDescriptors, this._table.foreignKeys, { typeMapper: (field) => this.typeMapper(field) });
|
|
1084
|
+
this._log(createSql);
|
|
1085
|
+
this.driver.exec(createSql);
|
|
1086
|
+
const oldCols = (await this.getExistingColumns()).map((c) => c.name);
|
|
1087
|
+
const newCols = this._table.fieldDescriptors.filter((f) => !f.ignored).map((f) => f.physicalName);
|
|
1088
|
+
const oldColSet = new Set(oldCols);
|
|
1089
|
+
const commonCols = newCols.filter((c) => oldColSet.has(c));
|
|
1090
|
+
if (commonCols.length > 0) {
|
|
1091
|
+
const fieldsByName = new Map(this._table.fieldDescriptors.map((f) => [f.physicalName, f]));
|
|
1092
|
+
const colNames = commonCols.map((c) => `"${esc(c)}"`).join(", ");
|
|
1093
|
+
const selectExprs = commonCols.map((c) => {
|
|
1094
|
+
const field = fieldsByName.get(c);
|
|
1095
|
+
if (field && !field.optional && !field.isPrimaryKey) {
|
|
1096
|
+
const fallback = field.defaultValue?.kind === "value" ? defaultValueToSqlLiteral(field.designType, field.defaultValue.value) : defaultValueForType(field.designType);
|
|
1097
|
+
return `COALESCE("${esc(c)}", ${fallback}) AS "${esc(c)}"`;
|
|
1098
|
+
}
|
|
1099
|
+
return `"${esc(c)}"`;
|
|
1100
|
+
}).join(", ");
|
|
1101
|
+
const copySql = `INSERT INTO "${esc(tempName)}" (${colNames}) SELECT ${selectExprs} FROM "${esc(tableName)}"`;
|
|
1102
|
+
this._log(copySql);
|
|
1103
|
+
this.driver.exec(copySql);
|
|
1104
|
+
}
|
|
1105
|
+
this.driver.exec(`DROP TABLE IF EXISTS "${esc(tableName)}"`);
|
|
1106
|
+
this.driver.exec(`ALTER TABLE "${esc(tempName)}" RENAME TO "${esc(tableName)}"`);
|
|
1107
|
+
});
|
|
1108
1108
|
} finally {
|
|
1109
1109
|
this.driver.exec("PRAGMA legacy_alter_table = OFF");
|
|
1110
1110
|
this.driver.exec("PRAGMA foreign_keys = ON");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/db-sqlite",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.139",
|
|
4
4
|
"description": "SQLite adapter for @atscript/db with swappable driver support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"atscript",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"@atscript/typescript": "^0.1.92",
|
|
50
50
|
"@uniqu/core": "^0.1.11",
|
|
51
51
|
"better-sqlite3": ">=11.0.0",
|
|
52
|
-
"@atscript/db": "^0.1.
|
|
53
|
-
"@atscript/db-sql-tools": "^0.1.
|
|
52
|
+
"@atscript/db": "^0.1.139",
|
|
53
|
+
"@atscript/db-sql-tools": "^0.1.139"
|
|
54
54
|
},
|
|
55
55
|
"peerDependenciesMeta": {
|
|
56
56
|
"better-sqlite3": {
|