|
|
|
@ -42,6 +42,16 @@ export function startup() {
@@ -42,6 +42,16 @@ export function startup() {
|
|
|
|
|
ON UPDATE NO ACTION |
|
|
|
|
);`).run();
|
|
|
|
|
|
|
|
|
|
db.query(`CREATE TABLE IF NOT EXISTS images (
|
|
|
|
|
id INTEGER PRIMARY KEY, |
|
|
|
|
desk_id INTEGER, |
|
|
|
|
|
|
|
|
|
FOREIGN KEY (desk_id) |
|
|
|
|
REFERENCES desks (id) |
|
|
|
|
ON DELETE CASCADE |
|
|
|
|
ON UPDATE NO ACTION |
|
|
|
|
);`).run();
|
|
|
|
|
|
|
|
|
|
db.query(`CREATE TABLE IF NOT EXISTS strokes (
|
|
|
|
|
id INTEGER PRIMARY KEY, |
|
|
|
|
desk_id INTEGER, |
|
|
|
@ -59,13 +69,14 @@ export function startup() {
@@ -59,13 +69,14 @@ export function startup() {
|
|
|
|
|
desk_id INTEGER, |
|
|
|
|
user_id INTEGER, |
|
|
|
|
stroke_id INTEGER, |
|
|
|
|
image_id INTEGER, |
|
|
|
|
x INTEGER, |
|
|
|
|
y INTEGER, |
|
|
|
|
|
|
|
|
|
FOREIGN KEY (desk_id) |
|
|
|
|
REFERENCES desks (id) |
|
|
|
|
ON DELETE CASCADE |
|
|
|
|
ON UPDATE NO ACTION, |
|
|
|
|
ON UPDATE NO ACTION |
|
|
|
|
|
|
|
|
|
FOREIGN KEY (user_id) |
|
|
|
|
REFERENCES users (id) |
|
|
|
@ -76,6 +87,11 @@ export function startup() {
@@ -76,6 +87,11 @@ export function startup() {
|
|
|
|
|
REFERENCES strokes (id) |
|
|
|
|
ON DELETE CASCADE |
|
|
|
|
ON UPDATE NO ACTION |
|
|
|
|
|
|
|
|
|
FOREIGN KEY (image_id) |
|
|
|
|
REFERENCES images (id) |
|
|
|
|
ON DELETE CASCADE |
|
|
|
|
ON UPDATE NO ACTION |
|
|
|
|
);`).run();
|
|
|
|
|
|
|
|
|
|
db.query(`CREATE INDEX IF NOT EXISTS idx_events_desk_id
|
|
|
|
@ -91,9 +107,11 @@ export function startup() {
@@ -91,9 +107,11 @@ export function startup() {
|
|
|
|
|
const res3 = db.query('SELECT COUNT(id) as count FROM strokes').get(); |
|
|
|
|
const res4 = db.query('SELECT COUNT(id) as count FROM users').get(); |
|
|
|
|
const res5 = db.query('SELECT COUNT(id) as count FROM sessions').get(); |
|
|
|
|
const res6 = db.query('SELECT COUNT(id) as count FROM images').get(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
queries.desks = db.query('SELECT id, sn FROM desks'); |
|
|
|
|
queries.events = db.query('SELECT id, desk_id, user_id, stroke_id, type, x, y FROM events'); |
|
|
|
|
queries.events = db.query('SELECT * FROM events'); |
|
|
|
|
queries.sessions = db.query('SELECT id, lsn, user_id, desk_id FROM sessions'); |
|
|
|
|
queries.strokes = db.query('SELECT id, points FROM strokes'); |
|
|
|
|
queries.empty_desk = db.query('INSERT INTO desks (id, title, sn) VALUES (?1, ?2, 0)'); |
|
|
|
@ -104,7 +122,8 @@ export function startup() {
@@ -104,7 +122,8 @@ export function startup() {
|
|
|
|
|
queries.save_session_lsn = db.query('UPDATE sessions SET lsn = ?1 WHERE id = ?2'); |
|
|
|
|
queries.create_session = db.query('INSERT INTO sessions (id, lsn, user_id, desk_id) VALUES (?1, 0, ?2, ?3)'); |
|
|
|
|
queries.create_user = db.query('INSERT INTO users (id, login) VALUES (?1, ?2)'); |
|
|
|
|
queries.put_event = db.query('INSERT INTO events (type, desk_id, user_id, stroke_id, x, y) VALUES (?1, ?2, ?3, ?4, ?5, ?6)'); |
|
|
|
|
queries.put_event = db.query('INSERT INTO events (type, desk_id, user_id, stroke_id, image_id, x, y) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)'); |
|
|
|
|
queries.put_image = db.query('INSERT INTO images (id, desk_id) VALUES (?1, ?2)'); |
|
|
|
|
|
|
|
|
|
console.log(`Storing data in ${path}`); |
|
|
|
|
console.log(`Entity count at startup:
|
|
|
|
@ -112,7 +131,8 @@ export function startup() {
@@ -112,7 +131,8 @@ export function startup() {
|
|
|
|
|
${res2.count} events |
|
|
|
|
${res3.count} strokes |
|
|
|
|
${res4.count} users |
|
|
|
|
${res5.count} sessions` |
|
|
|
|
${res5.count} sessions |
|
|
|
|
${res6.count} images` |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const stored_desks = get_desks(); |
|
|
|
@ -169,7 +189,7 @@ export function get_desk_strokes(desk_id) {
@@ -169,7 +189,7 @@ export function get_desk_strokes(desk_id) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function put_event(event) { |
|
|
|
|
return queries.put_event.get(event.type, event.desk_id || 0, event.user_id || 0, event.stroke_id || 0, event.x || 0, event.y || 0); |
|
|
|
|
return queries.put_event.get(event.type, event.desk_id || 0, event.user_id || 0, event.stroke_id || 0, event.image_id || 0, event.x || 0, event.y || 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function put_stroke(stroke_id, desk_id, points) { |
|
|
|
@ -198,4 +218,8 @@ export function create_user(user) {
@@ -198,4 +218,8 @@ export function create_user(user) {
|
|
|
|
|
|
|
|
|
|
export function save_session_lsn(session_id, lsn) { |
|
|
|
|
return queries.save_session_lsn.get(lsn, session_id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function put_image(image_id, desk_id) { |
|
|
|
|
return queries.put_image.get(image_id, desk_id); |
|
|
|
|
} |