This commit is contained in:
Michał Matczuk
2017-07-25 12:25:59 +02:00
parent 37524a4485
commit f3b13bf31b
4 changed files with 271 additions and 63 deletions

View File

@@ -69,9 +69,6 @@ func TestExample(t *testing.T) {
q.Release()
}
// TODO
// tx.NamedExec("INSERT INTO person (first_name, last_name, email) VALUES (:first_name, :last_name, :email)", &Person{"Jane", "Citizen", "jane.citzen@gocqlx_test.com"})
// Query the database, storing results in a []Person (wrapped in []interface{})
{
people := []Person{}
@@ -109,4 +106,35 @@ func TestExample(t *testing.T) {
// gocqlx_test.Place{Country:"United States", City:"New York", TelCode:1}
// gocqlx_test.Place{Country:"Singapore", City:"", TelCode:65}
}
// Named queries, using `:name` as the bindvar
{
stmt, names, err := gocqlx.CompileNamedQuery([]byte("INSERT INTO person (first_name, last_name, email) VALUES (:first_name, :last_name, :email)"))
if err != nil {
t.Fatal("compile:", err)
}
q := gocqlx.Queryx{
Query: session.Query(stmt),
Names: names,
}
if err := q.BindStruct(&Person{
"Jane",
"Citizen",
[]string{"jane.citzen@gocqlx_test.com"},
}); err != nil {
t.Fatal("bind:", err)
}
mustExec(q.Query)
if err := q.BindMap(map[string]interface{}{
"first_name": "Bin",
"last_name": "Smuth",
"email": []string{"bensmith@allblacks.nz"},
}); err != nil {
t.Fatal("bind:", err)
}
mustExec(q.Query)
}
}