Initialize the sqlite connection with WAL and foreign keys.
This somewhat improves performance, which is nice.
This commit is contained in:
parent
f4344fa28a
commit
4fd5880a0b
1 changed files with 11 additions and 0 deletions
|
@ -67,9 +67,20 @@
|
||||||
[(<-SQLite (:attr row)) (<-SQLite (:value row))]) rows))]))
|
[(<-SQLite (:attr row)) (<-SQLite (:value row))]) rows))]))
|
||||||
(into {})))))
|
(into {})))))
|
||||||
|
|
||||||
|
(defn <initialize-connection [sqlite-connection]
|
||||||
|
(go-pair
|
||||||
|
;; Some of these return values when set, and some don't, hence the craziness here.
|
||||||
|
(<? (s/execute! sqlite-connection ["PRAGMA page_size=32768"]))
|
||||||
|
(<? (s/all-rows sqlite-connection ["PRAGMA journal_mode=wal"]))
|
||||||
|
(<? (s/all-rows sqlite-connection ["PRAGMA wal_autocheckpoint=32"]))
|
||||||
|
(<? (s/all-rows sqlite-connection ["PRAGMA journal_size_limit=3145728"]))
|
||||||
|
(s/execute! sqlite-connection ["PRAGMA foreign_keys=ON"])))
|
||||||
|
|
||||||
(defn <db-with-sqlite-connection
|
(defn <db-with-sqlite-connection
|
||||||
[sqlite-connection]
|
[sqlite-connection]
|
||||||
(go-pair
|
(go-pair
|
||||||
|
(<? (<initialize-connection sqlite-connection))
|
||||||
|
|
||||||
(when-not (= sqlite-schema/current-version (<? (sqlite-schema/<ensure-current-version sqlite-connection)))
|
(when-not (= sqlite-schema/current-version (<? (sqlite-schema/<ensure-current-version sqlite-connection)))
|
||||||
(raise "Could not ensure current SQLite schema version."))
|
(raise "Could not ensure current SQLite schema version."))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue