Skip to content

Commit

Permalink
readme: updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatczuk committed May 25, 2018
1 parent fa402f3 commit d5caed5
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 20 deletions.
40 changes: 27 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
}
Expand Down Expand Up @@ -78,15 +74,33 @@ 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).

## 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
Expand All @@ -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.

Expand Down
3 changes: 1 addition & 2 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func TestExample(t *testing.T) {
// [{Patricia []} {Igy []}]
}

// Named query compilation.
// Use named query parameters.
{
p := &Person{
"Jane",
Expand Down
37 changes: 37 additions & 0 deletions migrate/README.md
Original file line number Diff line number Diff line change
@@ -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)
}
}
```
4 changes: 2 additions & 2 deletions migrate/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions qb/README.md
Original file line number Diff line number Diff line change
@@ -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`.
3 changes: 1 addition & 2 deletions qb/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d5caed5

Please sign in to comment.