aboutsummaryrefslogtreecommitdiff
path: root/db.go
diff options
context:
space:
mode:
authorNathan Lasseter <Nathan Lasseter nathan@bytemark.co.uk>2015-09-23 22:46:47 +0100
committerNathan Lasseter <Nathan Lasseter nathan@bytemark.co.uk>2015-09-23 22:46:47 +0100
commitd167a89638b4eecad852c66385737ef89354ec99 (patch)
tree7813a4e3c171d32daafd119955fd00c9bc5c932a /db.go
parent3c1b0368c70ed9fd080bd79632645866fe9f5faf (diff)
post /caches now returns created object
Diffstat (limited to 'db.go')
-rw-r--r--db.go18
1 files changed, 13 insertions, 5 deletions
diff --git a/db.go b/db.go
index a2c1d1e..b71cb54 100644
--- a/db.go
+++ b/db.go
@@ -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
}