-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdatabase.py
More file actions
48 lines (39 loc) · 1.12 KB
/
Copy pathdatabase.py
File metadata and controls
48 lines (39 loc) · 1.12 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
"""
Database configuration and initialization
"""
from sqlite_worker import SqliteWorker
import os
DB_PATH = os.path.join(os.path.dirname(__file__), "app.db")
_worker = None
def get_worker() -> SqliteWorker:
"""Get database worker instance (singleton)"""
global _worker
if _worker is None:
_worker = SqliteWorker(
DB_PATH,
execute_init=[
"PRAGMA journal_mode=WAL;",
"PRAGMA synchronous=NORMAL;",
"PRAGMA temp_store=MEMORY;"
],
max_count=50
)
return _worker
def init_database():
"""Initialize database schema"""
worker = get_worker()
# Create your tables here
worker.execute("""
CREATE TABLE IF NOT EXISTS items (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
description TEXT,
value REAL DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
""")
# Create indexes
worker.execute("""
CREATE INDEX IF NOT EXISTS idx_items_created
ON items(created_at)
""")