All Projects → scylladb → Gocqlx

scylladb / Gocqlx

Licence: apache-2.0
All-In-One: CQL query builder, ORM and migration tool

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Gocqlx

Php Es Mapper
An elasticsearch simple mapping ORM for php
Stars: ✭ 25 (-95.12%)
Mutual labels:  orm, query-builder
Codeigniter Model
CodeIgniter 3 Active Record (ORM) Standard Model with Laravel Eloquent & Yii2 AR like
Stars: ✭ 124 (-75.78%)
Mutual labels:  orm, query-builder
Evolutility Server Node
Model-driven REST or GraphQL backend for CRUD and more, written in Javascript, using Node.js, Express, and PostgreSQL.
Stars: ✭ 84 (-83.59%)
Mutual labels:  orm, query-builder
Migrate
Database migrations. CLI and Golang library.
Stars: ✭ 2,315 (+352.15%)
Mutual labels:  migration, cassandra
Evolve
Database migration tool for .NET and .NET Core projects. Inspired by Flyway.
Stars: ✭ 477 (-6.84%)
Mutual labels:  migration, cassandra
Orm
PHP DataMapper, ORM
Stars: ✭ 827 (+61.52%)
Mutual labels:  orm, query-builder
Ship Hold
data access framework for Postgresql on nodejs
Stars: ✭ 110 (-78.52%)
Mutual labels:  orm, query-builder
Diesel
A safe, extensible ORM and Query Builder for Rust
Stars: ✭ 7,702 (+1404.3%)
Mutual labels:  orm, query-builder
Piccolo
A fast, user friendly ORM and query builder which supports asyncio.
Stars: ✭ 219 (-57.23%)
Mutual labels:  orm, query-builder
Rekord
A javascript REST ORM that is offline and real-time capable
Stars: ✭ 171 (-66.6%)
Mutual labels:  orm, migration
Migrate
Database migrations. CLI and Golang library.
Stars: ✭ 7,712 (+1406.25%)
Mutual labels:  migration, cassandra
Elasticsearch
The missing elasticsearch ORM for Laravel, Lumen and Native php applications
Stars: ✭ 375 (-26.76%)
Mutual labels:  orm, query-builder
Sql
A delightful SQL ORM ☺️
Stars: ✭ 89 (-82.62%)
Mutual labels:  orm, query-builder
Express Cassandra
Cassandra ORM/ODM/OGM for Node.js with optional support for Elassandra & JanusGraph
Stars: ✭ 163 (-68.16%)
Mutual labels:  orm, cassandra
diesel
No description or website provided.
Stars: ✭ 30 (-94.14%)
Mutual labels:  cassandra, query-builder
Android Orma
An ORM for Android with type-safety and painless smart migrations
Stars: ✭ 442 (-13.67%)
Mutual labels:  orm, query-builder
Bee
Bee is an AI, easy and high efficiency ORM framework.
Stars: ✭ 469 (-8.4%)
Mutual labels:  orm
Rbatis
Rust ORM Framework High Performance Rust SQL-ORM(JSON based)
Stars: ✭ 482 (-5.86%)
Mutual labels:  orm
Flask Restplus Boilerplate
A boilerplate for flask restful web service
Stars: ✭ 466 (-8.98%)
Mutual labels:  migration
Jooq
jOOQ is the best way to write SQL in Java
Stars: ✭ 4,695 (+816.99%)
Mutual labels:  orm

🚀 GocqlX GoDoc Go Report Card Build Status

GocqlX makes working with Scylla easy and less error-prone. It’s inspired by Sqlx, a tool for working with SQL databases, but it goes beyond what Sqlx provides.

Features

  • Binding query parameters from struct fields, map, or both
  • Scanning query results into structs based on field names
  • Convenient functions for common tasks such as loading a single row into a struct or all rows into a slice (list) of structs
  • Making any struct a UDT without implementing marshalling functions
  • GocqlX is fast. Its performance is comparable to raw driver. You can find some benchmarks here.

Subpackages provide additional functionality:

Installation

    go get -u github.com/scylladb/gocqlx/v2

Getting started

Wrap gocql Session:

// Create gocql cluster.
cluster := gocql.NewCluster(hosts...)
// Wrap session on creation, gocqlx session embeds gocql.Session pointer. 
session, err := gocqlx.WrapSession(cluster.CreateSession())
if err != nil {
	t.Fatal(err)
}

Specify table model:

// metadata specifies table name and columns it must be in sync with schema.
var personMetadata = table.Metadata{
	Name:    "person",
	Columns: []string{"first_name", "last_name", "email"},
	PartKey: []string{"first_name"},
	SortKey: []string{"last_name"},
}

// personTable allows for simple CRUD operations based on personMetadata.
var personTable = table.New(personMetadata)

// Person represents a row in person table.
// Field names are converted to camel case by default, no need to add special tags.
// If you want to disable a field add `db:"-"` tag, it will not be persisted.
type Person struct {
	FirstName string
	LastName  string
	Email     []string
}

Bind data from a struct and insert a row:

p := Person{
	"Michał",
	"Matczuk",
	[]string{"[email protected]"},
}
q := session.Query(personTable.Insert()).BindStruct(p)
if err := q.ExecRelease(); err != nil {
	t.Fatal(err)
}

Load a single row to a struct:

p := Person{
	"Michał",
	"Matczuk",
	nil, // no email
}
q := session.Query(personTable.Get()).BindStruct(p)
if err := q.GetRelease(&p); err != nil {
	t.Fatal(err)
}
t.Log(p)
// stdout: {Michał Matczuk [[email protected]]}

Load all rows in to a slice:

var people []Person
q := session.Query(personTable.Select()).BindMap(qb.M{"first_name": "Michał"})
if err := q.SelectRelease(&people); err != nil {
	t.Fatal(err)
}
t.Log(people)
// stdout: [{Michał Matczuk [[email protected]]}]

Examples

You can find lots of examples in example_test.go.

Go and run them locally:

make run-scylla
make run-examples

Performance

GocqlX performance is comparable to the raw gocql driver. Below benchmark results running on my laptop.

BenchmarkBaseGocqlInsert            2392            427491 ns/op            7804 B/op         39 allocs/op
BenchmarkGocqlxInsert               2479            435995 ns/op            7803 B/op         39 allocs/op
BenchmarkBaseGocqlGet               2853            452384 ns/op            7309 B/op         35 allocs/op
BenchmarkGocqlxGet                  2706            442645 ns/op            7646 B/op         38 allocs/op
BenchmarkBaseGocqlSelect             747           1664365 ns/op           49415 B/op        927 allocs/op
BenchmarkGocqlxSelect                667           1877859 ns/op           42521 B/op        932 allocs/op

See the benchmark in benchmark_test.go.

License

Copyright (C) 2017 ScyllaDB

This project is distributed under the Apache 2.0 license. See the LICENSE file for details. It contains software from:

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.

GitHub star is always appreciated!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].