diff options
author | Nathan Lasseter <Nathan Lasseter nathan@bytemark.co.uk> | 2015-09-23 22:46:47 +0100 |
---|---|---|
committer | Nathan Lasseter <Nathan Lasseter nathan@bytemark.co.uk> | 2015-09-23 22:46:47 +0100 |
commit | d167a89638b4eecad852c66385737ef89354ec99 (patch) | |
tree | 7813a4e3c171d32daafd119955fd00c9bc5c932a /db.go | |
parent | 3c1b0368c70ed9fd080bd79632645866fe9f5faf (diff) |
post /caches now returns created object
Diffstat (limited to 'db.go')
-rw-r--r-- | db.go | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -39,17 +39,25 @@ func getCache(id uint64) (DBCache, error) { return cache, err } -func postCache(dbcache DBCache) error { +func postCache(incache DBCache) (DBCache, error) { + var outcache DBCache + db, err := sqlx.Connect("postgres", "user=audiocache password=audiocache dbname=audiocache sslmode=disable") if err != nil { - return err + return outcache, err + } + + rows, err := db.NamedQuery("INSERT INTO caches (latitude, longitude, created, path) VALUES (:latitude, :longitude, :created, :path) RETURNING *", incache) + if err != nil { + return outcache, err } - _, err = db.NamedExec("INSERT INTO caches (latitude, longitude, created, path) VALUES (:latitude, :longitude, :created, :path)", dbcache) + rows.Next() + err = rows.StructScan(&outcache) if err != nil { - return err + return outcache, err } err = db.Close() - return err + return outcache, err } |