Compare commits
2 Commits
08b3600836
...
4f988959ce
Author | SHA1 | Date | |
---|---|---|---|
4f988959ce | |||
b40060f770 |
@ -73,12 +73,23 @@
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.compose-wrapper textarea { resize: vertical; min-height: 60px; }
|
||||
input,textarea {
|
||||
padding: .5rem;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
width: 100%;
|
||||
}
|
||||
button {
|
||||
padding: .5rem 1rem;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
<aside id="sidebar">
|
||||
<h2>Tags</h2>
|
||||
<!-- New search box -->
|
||||
<input
|
||||
type="text"
|
||||
@ -86,6 +97,7 @@
|
||||
placeholder="Search notes…"
|
||||
style="width: calc(100% - 2rem); margin: .5rem 1rem; padding: .5rem;"
|
||||
/>
|
||||
<h2>Tags</h2>
|
||||
<ul id="tag-list"></ul>
|
||||
</aside>
|
||||
<main>
|
||||
|
39
main.py
39
main.py
@ -77,10 +77,43 @@ app.mount("/static", StaticFiles(directory=UPLOAD_DIR), name="static")
|
||||
if pathlib.Path(FRONTEND_DIR).exists():
|
||||
app.mount("/assets", StaticFiles(directory=FRONTEND_DIR), name="assets")
|
||||
|
||||
async def ensure_tables_exist():
|
||||
async with db_session() as db:
|
||||
# Check if 'notes' table exists
|
||||
if 'notes' not in db.tables:
|
||||
db.query("""
|
||||
CREATE TABLE notes (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title TEXT,
|
||||
body TEXT,
|
||||
created_at TEXT,
|
||||
updated_at TEXT
|
||||
)
|
||||
""")
|
||||
# Check if 'tags' table exists
|
||||
if 'tags' not in db.tables:
|
||||
db.query("""
|
||||
CREATE TABLE tags (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT UNIQUE
|
||||
)
|
||||
""")
|
||||
# Check if 'note_tags' table exists
|
||||
if 'note_tags' not in db.tables:
|
||||
db.query("""
|
||||
CREATE TABLE note_tags (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
note_id INTEGER,
|
||||
tag TEXT,
|
||||
FOREIGN KEY(note_id) REFERENCES notes(id)
|
||||
)
|
||||
""")
|
||||
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def init_search_index():
|
||||
await ensure_tables_exist()
|
||||
db = dataset.connect(DB_URL)
|
||||
# Create the FTS5 virtual table over notes.title and notes.body
|
||||
db.query("""
|
||||
@ -243,12 +276,6 @@ async def _upsert_note(note_id: Optional[int], payload: Dict[str, Any]):
|
||||
db.query("DELETE FROM notes_fts WHERE note_id = :nid", nid=note_id)
|
||||
|
||||
# (Re‑)insert into FTS table
|
||||
db.query(
|
||||
"INSERT INTO notes_fts (title, body, note_id) VALUES (:title, :body, :nid)",
|
||||
title=title,
|
||||
body=body,
|
||||
nid=note_id,
|
||||
)
|
||||
for t in tags:
|
||||
t = t.strip()
|
||||
if not t:
|
||||
|
Loading…
Reference in New Issue
Block a user