mirror of
https://github.com/screentinker/screentinker.git
synced 2026-08-16 23:33:10 -06:00
ee
This commit is contained in:
parent
5987db1ae4
commit
bf7fa80a25
21
fix-schema.js
Normal file
21
fix-schema.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
const fs = require('fs');
|
||||
let code = fs.readFileSync('server/db/database.js', 'utf8');
|
||||
|
||||
// Replace db.exec(schema) with splitting by ';' and running prepare().run()
|
||||
const replacement = `
|
||||
const schema = fs.readFileSync(path.join(__dirname, 'schema.sql'), 'utf8');
|
||||
const statements = schema.split(';');
|
||||
for (let stmt of statements) {
|
||||
if (stmt.trim()) {
|
||||
try {
|
||||
db.prepare(stmt).run();
|
||||
} catch (e) {
|
||||
console.error('Schema exec error:', e.message, '\\nStatement:', stmt.substring(0, 50));
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
code = code.replace("const schema = fs.readFileSync(path.join(__dirname, 'schema.sql'), 'utf8');\\ndb.exec(schema);", replacement);
|
||||
fs.writeFileSync('server/db/database.js', code);
|
||||
console.log('Fixed database.js');
|
||||
Binary file not shown.
4
server/test-exec.js
Normal file
4
server/test-exec.js
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
const Database = require('libsql');
|
||||
const db = new Database(':memory:');
|
||||
db.exec('CREATE TABLE foo (id INT); CREATE TABLE bar (id INT);');
|
||||
console.log(db.prepare("SELECT name FROM sqlite_master WHERE type='table'").all());
|
||||
Loading…
Reference in a new issue