Spaces:
Runtime error
Runtime error
File size: 718 Bytes
9d9d2a1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import os
import sqlite3
from typing import Tuple, Optional
def resolve_db_path() -> Tuple[str, bool]:
if os.path.isdir("/data"):
return "/data/venus_hotel.db", True
os.makedirs("./data", exist_ok=True)
return "./data/venus_hotel.db", False
def get_conn(db_path: Optional[str] = None) -> sqlite3.Connection:
if db_path is None:
db_path, _ = resolve_db_path()
conn = sqlite3.connect(db_path, check_same_thread=False, isolation_level=None)
conn.row_factory = sqlite3.Row
conn.execute("PRAGMA foreign_keys = ON;")
conn.execute("PRAGMA journal_mode = WAL;")
conn.execute("PRAGMA synchronous = NORMAL;")
conn.execute("PRAGMA busy_timeout = 5000;")
return conn
|