diff options
| author | unwox <me@unwox.com> | 2024-09-27 16:48:39 +0600 |
|---|---|---|
| committer | unwox <me@unwox.com> | 2024-09-27 16:48:39 +0600 |
| commit | 2b8f8c31932f95f3460a4e8794a47bedfb6514c7 (patch) | |
| tree | f38127d6b6642a27fc8b70d99d6a0d2d29ff9d52 | |
| parent | 0ea9ddc67a4e771c57189b9bec721dd30df5f315 (diff) | |
do not try to store empty list of products
| -rw-r--r-- | bin/fetch.fnl | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/bin/fetch.fnl b/bin/fetch.fnl index fe1a1a5..5df2849 100644 --- a/bin/fetch.fnl +++ b/bin/fetch.fnl @@ -35,32 +35,33 @@ (os.date "%Y-%m-%d %H:%M:%S")) (fn store-products [products] - (local sql - (.. "INSERT OR REPLACE INTO products VALUES " - (table.concat - (map (fn [_ _] - "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") - products) - ","))) - (local vars - (reduce - (fn [_ product rest] - (array.concat rest - [product.id - product.site - product.category - product.title - (or product.description "") - (or product.year 0) - (or product.image "") - (or product.url "") - (or product.price 0) - (or product.weight 0) - (or product.price-per 0) - (or product.misc "") - (now)])) - products [])) - (luna.db.exec db sql vars)) + (when (< 0 (# products)) + (local sql + (.. "INSERT OR REPLACE INTO products VALUES " + (table.concat + (map (fn [_ _] + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") + products) + ","))) + (local vars + (reduce + (fn [_ product rest] + (array.concat rest + [(or product.id "") + (or product.site "") + (or product.category "") + (or product.title "") + (or product.description "") + (or product.year 0) + (or product.image "") + (or product.url "") + (or product.price 0) + (or product.weight 0) + (or product.price-per 0) + (or product.misc "") + (now)])) + products [])) + (luna.db.exec db sql vars))) (fn populate-search-table [] (local tx (luna.db.begin db)) |
