我正在編寫一個小型實用程序,用於將數據從一個sqlite數據庫文件複製到另一個。兩個文件都有相同的表結構 - 這完全是關於將行從一個數據庫移動到另一個數據庫。使用node-sqlite將數據從一個數據庫複製到另一個數據庫 - 格式化'insert'語句
我現在代碼:
let tables: Array<string> = [
"OneTable", "AnotherTable", "DataStoredHere", "Video"
]
tables.forEach((table) => {
console.log(`Copying ${table} table`);
sourceDB.each(`select * from ${table}`, (error, row) => {
console.log(row);
destDB.run(`insert into ${table} values (?)`, ...row) // this is the problem
})
})
row
這裏是一個js對象,從每個表中的所有鍵數據。我確信有一個簡單的方法可以做到這一點,不涉及轉義字符串數據。