I expected to see the default of values set for the table, but I get undefined
This is the code:
import Database from 'better-sqlite3-multiple-ciphers'
// https://gist.github.com/anhdiepmmk/b8dcd1c7be8c09580f607ef186529192
// https://www.sqlite.org/quirks.html#no_separate_boolean_datatype
// https://www.sqlite.org/stricttables.html#strict_tables
const commandToCreateJitsiSettingsTable = `
CREATE TABLE IF NOT EXISTS jitsiTable (
id INTEGER PRIMARY KEY AUTOINCREMENT,
alwaysOnTopWindowEnable INTEGER NOT NULL DEFAULT 1,
disableAGC INTEGER NOT NULL DEFAULT 0,
serverURL TEXT,
serverTimeout REAL DEFAULT undefined,
created_at timestamp NOT NULL DEFAULT current_timestamp,
updated_at timestamp NOT NULL DEFAULT current_timestamp
)
`
if (!fs.existsSync(path.join(settingsUserDataFolder, "Settings.db")) {
const SettingsDB = new Database(path.join(settingsUserDataFolder,"Settings.db"), {})
SettingsDB.pragma('journal_mode = WAL')
SettingsDB.pragma("rekey='secret-key'");
SettingsDB.exec(commandToCreateJitsiSettingsTable)
SettingsDB.close();
} else {
console.log("Settings.db already exists")
const SettingsDB = require('better-sqlite3-multiple-ciphers')(path.join(settingsUserDataFolder,"Settings.db"), {})
SettingsDB.pragma("key='secret-key'");
const row = SettingsDB.prepare("SELECT * FROM jitsiTable");
console.log(row.alwaysOnTopWindowEnable, row.disableAGC, row.serverURL, row.serverTimeout, row.created_at, row.updated_at)
SettingsDB.close();
}
Output:
Settings.db already exists
undefined undefined undefined undefined undefined undefined
How to correctly set and then get the default values in the table?
You have prepared the statement but have not retrieved any data. You set the
row
variable to a prepared statement, not data. You need to use one of these methods, such as .get() or .all() depending on your needs on the prepared statement to retrieve the data. In your case, probably .get(). See the API docs for details.For example, you could replace these lines
with