diff options
| author | Max | 2018-02-05 17:47:03 +0100 |
|---|---|---|
| committer | Max | 2018-02-05 17:47:03 +0100 |
| commit | 7ca22dc3e6a5fb1815de2c42b868458e1efb9ef9 (patch) | |
| tree | 218bd25f29136169163cc46160b6fe75b999e2e1 /db.go | |
| parent | 5064a5f7562c6edfb446b176ca029f90bf6316d0 (diff) | |
| download | alkobote-7ca22dc3e6a5fb1815de2c42b868458e1efb9ef9.tar.gz | |
Adds detection of expired offers.
Diffstat (limited to 'db.go')
| -rw-r--r-- | db.go | 64 |
1 files changed, 0 insertions, 64 deletions
@@ -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 -} |
