-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor database initialization and message handling; add table crea…
…tion for users, messages, and calendars
- Loading branch information
Showing
6 changed files
with
102 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,6 @@ | ||
const sqlite = require('node:sqlite'); | ||
const { DatabaseSync } = require('node:sqlite'); | ||
const { DATABASE } = require('../environments/index.cjs'); | ||
|
||
const userDB = new sqlite.DatabaseSync(DATABASE.USERS); | ||
const messageDB = new sqlite.DatabaseSync(':memory:'); | ||
const calendarsDB = new sqlite.DatabaseSync(DATABASE.CALENDARS); | ||
|
||
module.exports.userDB = userDB; | ||
module.exports.calendarsDB = calendarsDB; | ||
module.exports.messageDB = messageDB; | ||
|
||
function createMessagesTable() { | ||
messageDB.exec(` | ||
CREATE TABLE if not exists messages( | ||
message_id INTEGER PRIMARY KEY, | ||
chat_id INTEGER, | ||
text TEXT, | ||
role TEXT, | ||
created_at TEXT DEFAULT CURRENT_TIMESTAMP | ||
) STRICT | ||
`); | ||
} | ||
|
||
function createUsersTable() { | ||
userDB.exec(` | ||
CREATE TABLE if not exists users( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
location TEXT NULL, | ||
timezone TEXT DEFAULT 'UTC', | ||
jwt TEXT, | ||
created_at TEXT DEFAULT CURRENT_TIMESTAMP | ||
) STRICT | ||
`); | ||
} | ||
|
||
function createCalendarsTable() { | ||
calendarsDB.exec(` | ||
CREATE TABLE if not exists calendars( | ||
id INTEGER PRIMARY KEY, | ||
message_id INTEGER, | ||
title TEXT, | ||
details TEXT NULL, | ||
location TEXT NULL, | ||
start INTEGER, | ||
end INTEGER, | ||
geo TEXT NULL | ||
) STRICT | ||
`); | ||
} | ||
|
||
try { | ||
createMessagesTable(); | ||
} catch (error) { | ||
console.warn(error); | ||
} | ||
try { | ||
createUsersTable(); | ||
} catch (error) { | ||
console.warn(error); | ||
} | ||
try { | ||
createCalendarsTable(); | ||
} catch (error) { | ||
console.warn(error); | ||
} | ||
module.exports.userDB = new DatabaseSync(DATABASE.USERS); | ||
module.exports.calendarsDB = new DatabaseSync(DATABASE.CALENDARS); | ||
module.exports.messageDB = new DatabaseSync(':memory:'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters