storage: sql.Exec() OK
This commit is contained in:
parent
f1ce07fd7e
commit
d7096500ce
3 changed files with 25 additions and 5 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
bin*
|
||||
*.log
|
||||
*.sqlite
|
||||
|
|
|
@ -23,5 +23,14 @@ func Open(cfg *Cfg) *Storage {
|
|||
return &Storage{db}
|
||||
}
|
||||
|
||||
func Exec(db *Storage, s string) {
|
||||
func (db *Storage) Exec(q string, args ...interface{}) (int64, error) {
|
||||
info := "sql.Exec"
|
||||
//log.Debug().Str("query", q).Msg(info)
|
||||
res, err := db.DB.Exec(q, args...)
|
||||
if err != nil {
|
||||
log.Error(err).Str("query", q).Msg(info)
|
||||
return 0, err
|
||||
}
|
||||
nrows, _ := res.RowsAffected()
|
||||
return nrows, nil
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package scopes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
tbase "testing"
|
||||
|
||||
"git.sr.ht/~cco/go-scopes/common/testing"
|
||||
|
@ -15,7 +14,7 @@ func TestSqlite(tb *tbase.T) {
|
|||
t := testing.SetUp(tb)
|
||||
cfg := etc.ConfigSqlite()
|
||||
db := sql.Open(cfg)
|
||||
// resetSqlite(db)
|
||||
resetSqlite(db)
|
||||
DoTests(t, cfg, db)
|
||||
}
|
||||
|
||||
|
@ -23,7 +22,7 @@ func TestPgsql(tb *tbase.T) {
|
|||
t := testing.SetUp(tb)
|
||||
cfg := etc.ConfigPgsql()
|
||||
db := sql.Open(cfg)
|
||||
// resetPgsql(db)
|
||||
resetPgsql(db)
|
||||
DoTests(t, cfg, db)
|
||||
}
|
||||
|
||||
|
@ -32,7 +31,18 @@ func DoTests(t *testing.T, cfg *sql.Cfg, db *sql.Storage) {
|
|||
}
|
||||
|
||||
func BaseTest(t *testing.T, cfg *sql.Cfg, db *sql.Storage) {
|
||||
fmt.Println(cfg.Connstr)
|
||||
//fmt.Println(cfg.Connstr)
|
||||
db.Exec(insert)
|
||||
}
|
||||
|
||||
func resetSqlite(db *sql.Storage) {
|
||||
db.Exec(drop_table)
|
||||
db.Exec(sqlite_create_table)
|
||||
}
|
||||
|
||||
func resetPgsql(db *sql.Storage) {
|
||||
db.Exec(drop_table)
|
||||
db.Exec(pgsql_create_table)
|
||||
}
|
||||
|
||||
// SQL statements
|
||||
|
|
Loading…
Add table
Reference in a new issue