readme: updated docs

This commit is contained in:
Michał Matczuk
2018-05-25 08:02:16 +02:00
parent fa402f3f0c
commit d5caed56c3
7 changed files with 75 additions and 20 deletions

View File

@@ -1,6 +1,6 @@
# GoCQLX [![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](http://godoc.org/github.com/scylladb/gocqlx) [![Go Report Card](https://goreportcard.com/badge/github.com/scylladb/gocqlx)](https://goreportcard.com/report/github.com/scylladb/gocqlx) [![Build Status](https://travis-ci.org/scylladb/gocqlx.svg?branch=master)](https://travis-ci.org/scylladb/gocqlx)
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 that supports full CQL spec, including BATCH statements and custom functions.
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.
## Installation
@@ -10,21 +10,17 @@ Package `gocqlx` is an idiomatic extension to `gocql` that provides usability fe
* Binding query parameters form struct or map
* Scanning results directly into struct or slice
* CQL query builder ([see more](https://github.com/scylladb/gocqlx/blob/master/qb))
* Database migrations ([see more](https://github.com/scylladb/gocqlx/blob/master/migrate))
* Fast!
In addition to that:
Package `qb` provides query builders for `SELECT`, `INSERT`, `UPDATE` `DELETE`
and `BATCH` statements supporting full spec including literals, functions,
collections and counters.
Package `migrate` provides a simple database migration system.
## Example
```go
// Field names are converted to camel case by default, no need to add
// `db:"first_name"`, if you want to disable a filed add `db:"-"` tag.
type Person struct {
FirstName string // no need to add `db:"first_name"` etc.
FirstName string
LastName string
Email []string
}
@@ -78,6 +74,25 @@ type Person struct {
t.Fatal(err)
}
}
// Use named query parameters.
{
p := &Person{
"Jane",
"Citizen",
[]string{"jane.citzen@gocqlx_test.com"},
}
stmt, names, err := gocqlx.CompileNamedQuery([]byte("INSERT INTO gocqlx_test.person (first_name, last_name, email) VALUES (:first_name, :last_name, :email)"))
if err != nil {
t.Fatal(err)
}
err = gocqlx.Query(session.Query(stmt), names).BindStruct(p).ExecRelease()
if err != nil {
t.Fatal(err)
}
}
```
See more examples in [example_test.go](https://github.com/scylladb/gocqlx/blob/master/example_test.go).
@@ -85,8 +100,7 @@ See more examples in [example_test.go](https://github.com/scylladb/gocqlx/blob/m
## Performance
Gocqlx is fast, this is a benchmark result comparing `gocqlx` to raw `gocql`
on a local machine. For query binding (insert) `gocqlx` is faster then `gocql`
thanks to smart caching, otherwise the performance is comparable.
on a local machine, Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz.
```
BenchmarkE2EGocqlInsert-4 500000 258434 ns/op 2627 B/op 59 allocs/op
@@ -109,7 +123,7 @@ It contains software from:
* [gocql project](https://github.com/gocql/gocql), licensed under the BSD license
* [sqlx project](https://github.com/jmoiron/sqlx), licensed under the MIT license
Apache®, Apache Cassandra®, are either registered trademarks or trademarks of
Apache®, Apache Cassandra® are either registered trademarks or trademarks of
the Apache Software Foundation in the United States and/or other countries.
No endorsement by The Apache Software Foundation is implied by the use of these marks.

3
doc.go
View File

@@ -6,6 +6,5 @@
// 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 that supports full CQL spec, including BATCH statements and custom
// functions.
// builder and a database migrations module.
package gocqlx

View File

@@ -195,7 +195,7 @@ func TestExample(t *testing.T) {
// [{Patricia []} {Igy []}]
}
// Named query compilation.
// Use named query parameters.
{
p := &Person{
"Jane",

37
migrate/README.md Normal file
View File

@@ -0,0 +1,37 @@
# GoCQLX Migrations
Package `migrate` provides simple and flexible CQL migrations.
Migrations can be read from a flat directory containing cql files.
There is no imposed naming schema, migration name is file name and the
migrations are processed in lexicographical order. Caller provides a
`gocql.Session`, the session must use a desired keyspace as migrate would try
to create migrations table.
## Features
* Each CQL statement will run once
* Go code migrations using callbacks
## Example
```go
package main
import (
"context"
"github.com/scylladb/gocqlx/migrate"
)
const dir = "./cql"
func main() {
session := CreateSession()
defer session.Close()
ctx := context.Background()
if err := migrate.Migrate(ctx, session, dir); err != nil {
panic(err)
}
}
```

View File

@@ -2,8 +2,8 @@
// Use of this source code is governed by a ALv2-style
// license that can be found in the LICENSE file.
// Package migrate provides simple and flexible ScyllaDB and Apache Cassandra®
// migrations. Migrations can be read from a flat directory containing cql files.
// Package migrate provides simple and flexible CLQ migrations.
// Migrations can be read from a flat directory containing cql files.
// There is no imposed naming schema, migration name is file name and the
// migrations are processed in lexicographical order. Caller provides a
// gocql.Session, the session must use a desired keyspace as migrate would try

6
qb/README.md Normal file
View File

@@ -0,0 +1,6 @@
# GoCQLX Query Builder
Package `qb` provides CQL query builders. The builders create CQL statement
and a list of named parameters that can later be bound using `gocqlx`.
The following CQL commands are supported: `SELECT`, `INSERT`, `UPDATE`, `DELETE` and `BATCH`.

View File

@@ -3,6 +3,5 @@
// license that can be found in the LICENSE file.
// Package qb provides CQL query builders. The builders create CQL statement
// and a list of named parameters that can later be bound using
// github.com/scylladb/gocqlx.
// and a list of named parameters that can later be bound using gocqlx.
package qb