diff options
| -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)) |
