Skip to content

Commit

Permalink
Merge pull request #4 from clodman84/main
Browse files Browse the repository at this point in the history
bringing docs branch up to date with the main branch
  • Loading branch information
clodman84 authored Jul 22, 2024
2 parents ad85b88 + 1ae75a1 commit 50e679d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Application/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def read_mess_list(path: Path):
connection = connect()
vals = [row for row in reader]
connection.executemany(
"INSERT OR IGNORE INTO students VALUES(?, ?, ?, ?, ?, ?, ?)", vals[1:]
"INSERT OR IGNORE INTO students VALUES(?, ?, ?, ?, ?, ?, ?, NULL)", vals[1:]
)
connection.commit()

Expand Down
6 changes: 4 additions & 2 deletions Application/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def set_or(x, y):
class SearchMachine:
def __init__(self) -> None:
self.parser = parser()
self.fts_text = f"SELECT name, idno, hoscode, roomno FROM students WHERE rowid IN (SELECT rowid FROM students_fts WHERE name MATCH ? ORDER BY rank)"
self.fts_text = """SELECT name, idno, hoscode, roomno FROM students WHERE rowid IN (SELECT * from (SELECT rowid FROM students_fts WHERE name MATCH ? ORDER BY rank) UNION SELECT * from (SELECT rowid FROM students_fts WHERE nick MATCH ? ORDER BY rank))"""
self.id_text = (
f"SELECT name, idno, hoscode, roomno from students WHERE idno LIKE ?"
)
Expand All @@ -72,7 +72,9 @@ def __init__(self) -> None:

def get_name(self, argument):
with ConnectionPool() as db:
cursor = db.execute(self.fts_text, (argument,))
cursor = db.execute(
self.fts_text, (argument, argument)
) # argument, argument since the querry uses the search term twice :(
return {tuple(item) for item in cursor}

def get_id(self, argument):
Expand Down
13 changes: 7 additions & 6 deletions Data/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,28 @@ CREATE TABLE IF NOT EXISTS students(
GENDER text,
HOSCODE text,
ROOMNO text,
PROG_ID int
PROG_ID int,
NICK text UNIQUE
);

-- full text search capabilities for students
DROP table IF EXISTS students_fts;
CREATE VIRTUAL TABLE students_fts USING fts5(NAME, IDNO UNINDEXED, content='students', tokenize='trigram');
CREATE VIRTUAL TABLE students_fts USING fts5(NAME, NICK, IDNO UNINDEXED, content='students', tokenize='trigram');

DROP TRIGGER IF EXISTS students_ai;
DROP TRIGGER IF EXISTS students_ad;
DROP TRIGGER IF EXISTS students_au;

-- Triggers to keep the FTS index up to date.
CREATE TRIGGER students_ai AFTER INSERT ON students BEGIN
INSERT INTO students_fts(rowid, NAME, IDNO) VALUES (new.rowid, new.NAME , new.IDNO);
INSERT INTO students_fts(rowid, NAME, NICK, IDNO) VALUES (new.rowid, new.NAME , new.NICK, new.IDNO);
END;
CREATE TRIGGER students_ad AFTER DELETE ON students BEGIN
INSERT INTO students_fts(students_fts, rowid, NAME, IDNO) VALUES('delete', old.rowid, old.NAME, old.IDNO);
INSERT INTO students_fts(students_fts, rowid, NAME, NICK, IDNO) VALUES('delete', old.rowid, old.NAME, old.NICK, old.IDNO);
END;
CREATE TRIGGER students_au AFTER UPDATE ON students BEGIN
INSERT INTO students_fts(students_fts, rowid, NAME, IDNO) VALUES('delete', old.rowid, old.NAME, old.IDNO);
INSERT INTO students_fts(rowid, NAME, IDNO) VALUES (new.rowid, new.NAME, new.IDNO);
INSERT INTO students_fts(students_fts, rowid, NAME, NICK, IDNO) VALUES('delete', old.rowid, old.NAME, old.NICK, old.IDNO);
INSERT INTO students_fts(rowid, NAME, NICK, IDNO) VALUES (new.rowid, new.NAME, new.NICK, new.IDNO);
END;

INSERT INTO students_fts(students_fts) VALUES('rebuild');
9 changes: 9 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path

import dearpygui.dearpygui as dpg
from dearpygui import demo

import Application
import GUI
Expand Down Expand Up @@ -86,6 +87,14 @@ def main():
dpg.add_menu_item(
label="Show Performance Metrics", callback=dpg.show_metrics
)
with dpg.menu(label="Dev"):
dpg.add_menu_item(
label="Spawn Billing Window",
callback=lambda: GUI.BillingWindow(
roll="Dev", path=Path("Data/Dev")
),
)
dpg.add_menu_item(label="Show GUI Demo", callback=demo.show_demo)

dpg.add_button(
label="Music",
Expand Down

0 comments on commit 50e679d

Please sign in to comment.