-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.js
More file actions
53 lines (46 loc) · 1.14 KB
/
database.js
File metadata and controls
53 lines (46 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const { app } = require("electron");
const Database = require("better-sqlite3");
const path = require("path");
let appPath = app.getAppPath();
// In production, go two levels up to reach the app root
if (app.isPackaged) {
appPath = path.join(appPath, "..", "..");
}
let dbPath = appPath + "/sharpnote.db"
// Open (or create) the database file
const db = new Database(dbPath);
// Create a notes table if it doesn't exist
db.exec(`
CREATE TABLE IF NOT EXISTS notes (
noteID TEXT PRIMARY KEY,
sharpnoteVersion TEXT,
sharpnoteType TEXT,
noteTitle TEXT,
noteContent TEXT,
noteColor TEXT,
noteAttachments TEXT,
noteOriginalAuthor TEXT,
noteLastAuthor TEXT,
noteFolder TEXT,
created TEXT,
lastSaved TEXT,
lastOpened TEXT,
lastExported TEXT,
noteVersion INTEGER,
noteTags TEXT,
isReadonly BOOL
)
`);
// Create a notes table if it doesn't exist
db.exec(`
CREATE TABLE IF NOT EXISTS folders (
folderID TEXT PRIMARY KEY,
sharpnoteType TEXT,
folderTitle TEXT,
folderNotes TEXT,
folderColor TEXT,
folderOriginalAuthor TEXT,
created TEXT
)
`);
module.exports = db;