From 7ca22dc3e6a5fb1815de2c42b868458e1efb9ef9 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 5 Feb 2018 17:47:03 +0100 Subject: Adds detection of expired offers. --- db.go | 64 ---------------------------------------------------------------- 1 file changed, 64 deletions(-) delete mode 100644 db.go (limited to 'db.go') diff --git a/db.go b/db.go deleted file mode 100644 index 8ea7165..0000000 --- a/db.go +++ /dev/null @@ -1,64 +0,0 @@ -package main - -import ( - // "github.com/jmoiron/sqlx" - "database/sql" -) - -func (app *App) createTables() error { - query1 := `CREATE TABLE IF NOT EXISTS angebot ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - shop text, - name text, - url text, - original_price int, - discounted_price int, - valid_until text, - image_url text, - spirit_type text, - created_at text - )` - _, err := app.DB.Exec(query1) - if err != nil { - return err - } - - query2 := `CREATE TABLE IF NOT EXISTS shop( - id INTEGER PRIMARY KEY AUTOINCREMENT, - name text, - url text, - logo_url text, - shipping_costs text, - free_shipping text - )` - _, err = app.DB.Exec(query2) - return err -} - -func (app *App) save_offer(W []Angebot) error { - - query := `INSERT INTO angebot (shop, name, url, original_price, discounted_price, valid_until, image_url, spirit_type) VALUES (?, ?, ?, ?, ?, ?, ?, ?)` - - stmt, err := app.DB.Prepare(query) - if err != nil { - return err - } - - for _, o := range W { - - var found int - - err := app.DB.QueryRow("SELECT 1 FROM angebot WHERE shop = ? AND name = ? AND url = ? AND original_price = ? AND discounted_price = ? AND image_url = ? AND spirit_type = ?", o.Shop, o.Name, o.Url, o.Original_price, o.Discounted_price, o.Image_url, o.Spirit_type).Scan(&found) - - if err == sql.ErrNoRows { - - _, err = stmt.Exec(o.Shop, o.Name, o.Url, o.Original_price, o.Discounted_price, o.Valid_until, o.Image_url, o.Spirit_type) - if err != nil { - return err - } - - } - } - - return nil -} -- cgit v1.2.3