diff --git a/.gitignore b/.gitignore index 13c8366..0aa895e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ bin* *.log +*.sqlite diff --git a/storage/sql/sql.go b/storage/sql/sql.go index a2e3175..ab3d3c9 100644 --- a/storage/sql/sql.go +++ b/storage/sql/sql.go @@ -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 } diff --git a/tests/storage_test.go b/tests/storage_test.go index 5391b07..929ef43 100644 --- a/tests/storage_test.go +++ b/tests/storage_test.go @@ -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