@zaisma/cli 0.30.0 → 0.31.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/package.json +1 -1
- package/zaisma.mjs +11 -6
package/package.json
CHANGED
package/zaisma.mjs
CHANGED
|
@@ -1751,15 +1751,20 @@ function* sqliteDumpStatements(sqlite) {
|
|
|
1751
1751
|
)
|
|
1752
1752
|
.all();
|
|
1753
1753
|
yield "PRAGMA foreign_keys=OFF;\nBEGIN TRANSACTION;\n";
|
|
1754
|
-
|
|
1755
|
-
|
|
1754
|
+
const tables = entries.filter((entry) => entry.type === "table" && (entry.table_kind === "table" || entry.table_kind === "virtual") && !entry.name.startsWith("sqlite_"));
|
|
1755
|
+
// Every table is made before any row goes in, so a row can refer to a table made after it.
|
|
1756
|
+
for (const table of tables) yield `${table.sql};\n`;
|
|
1757
|
+
for (const table of tables) {
|
|
1756
1758
|
const columns = sqlite.prepare("SELECT name, hidden = 0 AS is_insertable, pk AS primary_key_number FROM pragma_table_xinfo(?) ORDER BY cid").all(table.name);
|
|
1757
1759
|
const insertedColumns = columns.filter((column) => column.is_insertable === 1);
|
|
1758
|
-
|
|
1759
|
-
const
|
|
1760
|
+
// A search table's rows are known by their rowids, so they go in with them.
|
|
1761
|
+
const isVirtual = table.table_kind === "virtual";
|
|
1762
|
+
const insertInto = `INSERT INTO ${quoteName(table.name)}${insertedColumns.length < columns.length || isVirtual ? `(${[...(isVirtual ? ["rowid"] : []), ...insertedColumns.map((column) => quoteName(column.name))].join(",")})` : ""} VALUES(`;
|
|
1763
|
+
const valuesSql = [...(isVirtual ? ["rowid AS paging_rowid"] : []), ...insertedColumns.map((column, i) => `quote(${quoteName(column.name)}) AS value_${i}`)].join(", ");
|
|
1760
1764
|
const primaryKey = columns.filter((column) => column.primary_key_number > 0).sort((first, second) => first.primary_key_number - second.primary_key_number);
|
|
1761
|
-
|
|
1762
|
-
|
|
1765
|
+
// The key's order, rowid last where there is one, as Zaisma's export reads it (packages/game-server/src/dump.ts).
|
|
1766
|
+
const order = primaryKey.length ? [...primaryKey.map((column) => `${quoteName(table.name)}.${quoteName(column.name)}`), ...(table.is_without_rowid ? [] : [`${quoteName(table.name)}.rowid`])].join(", ") : "rowid";
|
|
1767
|
+
for (const row of sqlite.prepare(`SELECT ${valuesSql} FROM ${quoteName(table.name)} ORDER BY ${order}`).iterate()) yield `${insertInto}${[...(isVirtual ? [row.paging_rowid] : []), ...insertedColumns.map((_, i) => row[`value_${i}`])].join(",")});\n`;
|
|
1763
1768
|
}
|
|
1764
1769
|
if (entries.some((entry) => entry.name === "sqlite_sequence")) {
|
|
1765
1770
|
yield "DELETE FROM sqlite_sequence;\n";
|