Documentation ¶
Overview ¶
Package gocqlx is a productivity toolkit for ScyllaDB and Apache Cassandra®. It's an extension of `gocql`, similar to what `sqlx` is to `database/sql`.
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.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultMapper = reflectx.NewMapperFunc("db", snakeCase)
DefaultMapper uses `db` tag and automatically converts struct field names to snake case. It can be set to whatever you want, but it is encouraged to be set before gocqlx is used as name-to-field mappings are cached after first use on a type.
Functions ¶
func CompileNamedQuery ¶
CompileNamedQuery compiles a named query into an unbound query using the '?' bindvar and a list of names.
Types ¶
type Iterx ¶
Iterx is a wrapper around gocql.Iter which adds struct scanning capabilities.
func (*Iterx) Close ¶
Close closes the iterator and returns any errors that happened during the query or the iteration.
func (*Iterx) Get ¶
Get scans first row into a destination and closes the iterator. If the destination type is a Struct, then StructScan will be used. If the destination is some other type, then the row must only have one column which can scan into that type. If no rows were selected, ErrNotFound is returned.
func (*Iterx) Select ¶
Select scans all rows into a destination, which must be a slice of any type and closes the iterator. If the destination slice type is a Struct, then StructScan will be used on each row. If the destination is some other type, then each row must only have one column which can scan into that type.
func (*Iterx) StructScan ¶
StructScan is like gocql.Iter.Scan, but scans a single row into a single Struct. Use this and iterate manually when the memory load of Select() might be prohibitive. StructScan caches the reflect work of matching up column positions to fields to avoid that overhead per scan, which means it is not safe to run StructScan on the same Iterx instance with different struct types.
type Queryx ¶
type Queryx struct { *gocql.Query Names []string Mapper *reflectx.Mapper // contains filtered or unexported fields }
Queryx is a wrapper around gocql.Query which adds struct binding capabilities.
func (*Queryx) BindStruct ¶
BindStruct binds query named parameters to values from arg using mapper. If value cannot be found error is reported.
func (*Queryx) BindStructMap ¶
BindStructMap binds query named parameters to values from arg0 and arg1 using a mapper. If value cannot be found in arg0 it's looked up in arg1 before reporting an error.
func (*Queryx) ExecRelease ¶
ExecRelease performs exec and releases the query, a released query cannot be reused.