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