diff options
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/fetch.fnl | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/bin/fetch.fnl b/bin/fetch.fnl index c0f07c6..3ef57df 100644 --- a/bin/fetch.fnl +++ b/bin/fetch.fnl @@ -10,9 +10,11 @@ (local artoftea (require :parser.artoftea)) (local clubcha (require :parser.clubcha)) (local chaekshop (require :parser.chaekshop)) +(local {: must} (require :lib.utils)) -(local db (luna.db.open "file:var/db.sqlite?_journal=WAL&_sync=NORMAL")) -(luna.db.exec db " +(local db (must (luna.db.open "file:var/db.sqlite?_journal=WAL&_sync=NORMAL"))) +(must + (luna.db.exec db " PRAGMA foreign_keys=ON; PRAGMA journal_mode=WAL; PRAGMA synchronous=NORMAL; @@ -43,7 +45,7 @@ CREATE TABLE IF NOT EXISTS tags( title TEXT NOT NULL PRIMARY KEY, creation_time DATETIME NOT NULL - );" []) + );" [])) (fn now [] (os.date "%Y-%m-%d %H:%M:%S")) @@ -59,7 +61,7 @@ (reduce (fn [_ tag rest] (array.concat rest [tag (now)])) tags [])) - (luna.db.exec-tx tx sql vars))) + (must (luna.db.exec-tx tx sql vars)))) (fn store-product-tags [tx products] (when (< 0 (# products)) @@ -85,7 +87,7 @@ (fn [_ tags rest] (array.concat rest tags)) tags [])) - (luna.db.exec-tx tx sql vars))) + (must (luna.db.exec-tx tx sql vars)))) (fn store-products [tx products] (when (< 0 (# products)) @@ -111,7 +113,7 @@ false (now)])) products [])) - (luna.db.exec-tx tx sql vars) + (must (luna.db.exec-tx tx sql vars)) ;; store tags (store-tags tx (array.unique @@ -120,22 +122,22 @@ (store-product-tags tx products))) (fn populate-search-table [] - (local tx (luna.db.begin db)) - (luna.db.exec-tx tx "DELETE FROM search" []) - (luna.db.exec-tx tx "INSERT INTO search - SELECT title, url, 'products' - FROM products;" []) - (luna.db.commit tx)) + (local tx (must (luna.db.begin db))) + (must (luna.db.exec-tx tx "DELETE FROM search" [])) + (must (luna.db.exec-tx tx "INSERT INTO search + SELECT title, url, 'products' + FROM products;" [])) + (must (luna.db.commit tx))) ;; replace with with-tx -(local tx (luna.db.begin db)) -(luna.db.exec-tx tx "DELETE FROM product_tags;" []) +(local tx (must (luna.db.begin db))) +(must (luna.db.exec-tx tx "DELETE FROM product_tags;" [])) (each [_ products (pairs [chaekshop.products clubcha.products artoftea.products ipuer.products ozchai.products])] (store-products tx (products))) -(luna.db.commit tx) +(must (luna.db.commit tx)) (populate-search-table) |
