Documentation ¶
Overview ¶
Package gocqlx is an idiomatic extension to gocql that provides usability features. With gocqlx you can bind the query parameters from maps and structs, use named query parameters (:identifier) and scan the query results into structs and slices. It comes with a fluent and flexible CQL query builder and a database migrations module.
Index ¶
- Variables
- func CompileNamedQuery(qs []byte) (stmt string, names []string, err error)
- func Get(dest interface{}, q inter.Query) error
- func Select(dest interface{}, q inter.Query) error
- type Iterx
- type Queryx
- func (q *Queryx) Bind(v ...interface{}) *Queryx
- func (q *Queryx) BindMap(arg map[string]interface{}) *Queryx
- func (q *Queryx) BindStruct(arg interface{}) *Queryx
- func (q *Queryx) BindStructMap(arg0 interface{}, arg1 map[string]interface{}) *Queryx
- func (q *Queryx) Consistency(c gocql.Consistency) *Queryx
- func (q *Queryx) CustomPayload(customPayload map[string][]byte) *Queryx
- func (q *Queryx) DefaultTimestamp(enable bool) *Queryx
- func (q *Queryx) Err() error
- func (q *Queryx) Exec() error
- func (q *Queryx) ExecRelease() error
- func (q *Queryx) Get(dest interface{}) error
- func (q *Queryx) GetRelease(dest interface{}) error
- func (q *Queryx) Idempotent(value bool) *Queryx
- func (q *Queryx) Iter() *Iterx
- func (q *Queryx) NoSkipMetadata() *Queryx
- func (q *Queryx) Observer(observer gocql.QueryObserver) *Queryx
- func (q *Queryx) PageSize(n int) *Queryx
- func (q *Queryx) PageState(state []byte) *Queryx
- func (q *Queryx) Prefetch(p float64) *Queryx
- func (q *Queryx) RetryPolicy(r gocql.RetryPolicy) *Queryx
- func (q *Queryx) RoutingKey(routingKey []byte) *Queryx
- func (q *Queryx) Select(dest interface{}) error
- func (q *Queryx) SelectRelease(dest interface{}) error
- func (q *Queryx) SerialConsistency(cons gocql.SerialConsistency) *Queryx
- func (q *Queryx) SetSpeculativeExecutionPolicy(sp gocql.SpeculativeExecutionPolicy) *Queryx
- func (q *Queryx) Trace(trace gocql.Tracer) *Queryx
- func (q *Queryx) WithContext(ctx context.Context) *Queryx
- func (q *Queryx) WithTimestamp(timestamp int64) *Queryx
Constants ¶
This section is empty.
Variables ¶
var DefaultMapper = reflectx.NewMapperFunc("db", reflectx.CamelToSnakeASCII)
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.
var DefaultUnsafe bool
DefaultUnsafe enables the behavior of forcing the iterator to ignore missing fields for all queries. See Unsafe below for more information.
Functions ¶
func CompileNamedQuery ¶
CompileNamedQuery translates query with named parameters in a form ':<identifier>' to query with '?' placeholders and a list of parameter names. If you need to use ':' in a query, i.e. with maps or UDTs use '::' instead.
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 pointer, 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 pointer to 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.
If no rows were selected, ErrNotFound is NOT returned.
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 { inter.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) Bind ¶
Bind sets query arguments of query. This can also be used to rebind new query arguments to an existing query instance.
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) Consistency ¶
func (q *Queryx) Consistency(c gocql.Consistency) *Queryx
Consistency sets the consistency level for this query. If no consistency level have been set, the default consistency level of the cluster is used.
func (*Queryx) CustomPayload ¶
CustomPayload sets the custom payload level for this query.
func (*Queryx) DefaultTimestamp ¶
DefaultTimestamp will enable the with default timestamp flag on the query. If enable, this will replace the server side assigned timestamp as default timestamp. Note that a timestamp in the query itself will still override this timestamp. This is entirely optional.
Only available on protocol >= 3
func (*Queryx) ExecRelease ¶
ExecRelease calls Exec and releases the query, a released query cannot be reused.
func (*Queryx) Get ¶
Get scans first row into a destination. If the destination type is a struct pointer, then Iter.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 (*Queryx) GetRelease ¶
GetRelease calls Get and releases the query, a released query cannot be reused.
func (*Queryx) Idempotent ¶
Idempotent marks the query as being idempotent or not depending on the value.
func (*Queryx) Iter ¶
Iter returns Iterx instance for the query. It should be used when data is too big to be loaded with Select in order to do row by row iteration. See Iterx StructScan function.
func (*Queryx) NoSkipMetadata ¶
NoSkipMetadata will override the internal result metadata cache so that the driver does not send skip_metadata for queries, this means that the result will always contain the metadata to parse the rows and will not reuse the metadata from the prepared staement. This should only be used to work around cassandra bugs, such as when using CAS operations which do not end in Cas.
See https://issues.apache.org/jira/browse/CASSANDRA-11099 https://github.com/gocql/gocql/issues/612
func (*Queryx) Observer ¶
func (q *Queryx) Observer(observer gocql.QueryObserver) *Queryx
Observer enables query-level observer on this query. The provided observer will be called every time this query is executed.
func (*Queryx) PageSize ¶
PageSize will tell the iterator to fetch the result in pages of size n. This is useful for iterating over large result sets, but setting the page size too low might decrease the performance. This feature is only available in Cassandra 2 and onwards.
func (*Queryx) PageState ¶
PageState sets the paging state for the query to resume paging from a specific point in time. Setting this will disable to query paging for this query, and must be used for all subsequent pages.
func (*Queryx) Prefetch ¶
Prefetch sets the default threshold for pre-fetching new pages. If there are only p*pageSize rows remaining, the next page will be requested automatically.
func (*Queryx) RetryPolicy ¶
func (q *Queryx) RetryPolicy(r gocql.RetryPolicy) *Queryx
RetryPolicy sets the policy to use when retrying the query.
func (*Queryx) RoutingKey ¶
RoutingKey sets the routing key to use when a token aware connection pool is used to optimize the routing of this query.
func (*Queryx) Select ¶
Select scans all rows into a destination, which must be a pointer to slice of any type. If the destination slice type is a struct, then Iter.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.
If no rows were selected, ErrNotFound is NOT returned.
func (*Queryx) SelectRelease ¶
SelectRelease calls Select and releases the query, a released query cannot be reused.
func (*Queryx) SerialConsistency ¶
func (q *Queryx) SerialConsistency(cons gocql.SerialConsistency) *Queryx
SerialConsistency sets the consistency level for the serial phase of conditional updates. That consistency can only be either SERIAL or LOCAL_SERIAL and if not present, it defaults to SERIAL. This option will be ignored for anything else that a conditional update/insert.
func (*Queryx) SetSpeculativeExecutionPolicy ¶
func (q *Queryx) SetSpeculativeExecutionPolicy(sp gocql.SpeculativeExecutionPolicy) *Queryx
SetSpeculativeExecutionPolicy sets the execution policy.
func (*Queryx) Trace ¶
Trace enables tracing of this query. Look at the documentation of the Tracer interface to learn more about tracing.
func (*Queryx) WithContext ¶
WithContext returns a shallow copy of q with its context set to ctx.
The provided context controls the entire lifetime of executing a query, queries will be canceled and return once the context is canceled.
func (*Queryx) WithTimestamp ¶
WithTimestamp will enable the with default timestamp flag on the query like DefaultTimestamp does. But also allows to define value for timestamp. It works the same way as USING TIMESTAMP in the query itself, but should not break prepared query optimization
Only available on protocol >= 3
Directories ¶
Path | Synopsis |
---|---|
Package migrate provides simple and flexible CLQ migrations.
|
Package migrate provides simple and flexible CLQ migrations. |
Package qb provides CQL query builders.
|
Package qb provides CQL query builders. |
Package table adds support for super simple CRUD operations based on table model.
|
Package table adds support for super simple CRUD operations based on table model. |