This is the proc I am currently using:

proc opendb(readonly: bool = false): DbConn =
    20 │ 21 │ var 22 │ appdir: string = getAppDir() 23 │ dbpath: string 24 │ 25 
│ proc isOnPath(): bool = 26 │ 27 │ let path = split(getEnv("PATH"),":") 28 │ 
29 │ appdir in path 30 │ 31 │ if release and isOnPath():# and isOnPath(): 32 │ 
33 │ dbpath = getDataDir() / "medical.db" 34 │ 35 │ else: 36 │ 37 │ dbpath = 
parentDir(appdir) / ".local/share/medical.db" 38 │ 39 │ let db = open(dbpath, 
"", "", "") 40 │ 41 │ if readonly: 42 │ 43 │ db.exec(sql"PRAGMA query_only = 
true") 44 │ 45 │ else: 46 │ 47 │ db.exec(sql"pragma foreign_keys = on") 48 │ 49 
│ result = db

By the time I run the db.exec(pragma) it is already too late.

I know because I have a systemd.path unit that triggers a service that rsyncs 
the db to a backup machine when the db chaneges.

Reply via email to