Files
gocqlx/doc.go

39 lines
1.3 KiB
Go
Raw Normal View History

2017-07-24 15:22:18 +02:00
// Package gocqlx is a gocql extension, similar to what sqlx is to database/sql.
//
2017-07-25 14:30:13 +02:00
// It contains wrappers over gocql types that provide convenience methods which
// are useful in the development of database driven applications. Under the
// hood it uses sqlx/reflectx package so sqlx models will also work with gocqlx.
2017-07-24 15:22:18 +02:00
//
2017-07-25 14:30:13 +02:00
// Example, read all rows into a slice
2017-07-24 15:22:18 +02:00
//
// var v []*Item
2017-07-24 16:22:30 +02:00
// if err := gocqlx.Select(&v, session.Query(`SELECT * FROM items WHERE id = ?`, id)); err != nil {
2017-07-24 15:22:18 +02:00
// log.Fatal("select failed", err)
// }
2017-07-24 16:22:30 +02:00
//
2017-07-25 14:30:13 +02:00
// Example, read a single row into a struct
2017-07-24 16:22:30 +02:00
//
// var v Item
// if err := gocqlx.Get(&v, session.Query(`SELECT * FROM items WHERE id = ?`, id)); err != nil {
// log.Fatal("get failed", err)
// }
2017-07-25 14:30:13 +02:00
//
// Example, bind named query parameters from a struct or map
//
// stmt, names, err := gocqlx.CompileNamedQuery([]byte("INSERT INTO items (id, name) VALUES (:id, :name)"))
// if err != nil {
// t.Fatal("compile:", err)
// }
// q := gocqlx.Queryx{
// Query: session.Query(stmt),
// Names: names,
// }
// if err := q.BindStruct(&Item{"id", "name"}); err != nil {
// t.Fatal("bind:", err)
// }
// if err := q.Query.Exec(); err != nil {
// log.Fatal("get failed", err)
// }
//
2017-07-24 15:22:18 +02:00
package gocqlx