summaryrefslogtreecommitdiff
path: root/bin/fetch.fnl
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2024-10-15 14:49:46 +0600
committerunwox <me@unwox.com>2024-10-15 14:59:04 +0600
commit92d95b978bfb10fd29024d0adda7b28f125e08b8 (patch)
tree189fd3c9cf9bc08712d795e8119c8df61fd7ce6b /bin/fetch.fnl
parent1204496efa2fcd495bd74ba8ca249b7f082f3ba5 (diff)
adapt to the new convention for calling luna module methods
Diffstat (limited to 'bin/fetch.fnl')
-rw-r--r--bin/fetch.fnl32
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)