cqlquery

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2019 License: MIT Imports: 3 Imported by: 0

README

go-cql-query-builder

📇 a super tiny query builder for cassandra, made in go

To do

  • Add UPDATE support
  • Add DELETE support

Usage

package main

import (
	"log"

	cqlquery "github.com/flikmsg/go-cql-query-builder"
)

func main() {
	if _, err := cqlquery.Connect([]string{"127.0.0.1"}, "test_keyspace"); err != nil {
		log.Fatal(err)
	}

	query := cqlquery.Select("users_by_username", []string{"user_id", "username"}, map[string]interface{}{
		"username": "tyler",
	})

	results := query.Iter()
	defer results.Close()

	m := map[string]interface{}{}
	if results.MapScan(m) {
		log.Printf("User ID: %s, Username: %s", m["user_id"], m["username"])
	} else {
		log.Println("No user found.")
	}
}

Documentation

Index

Constants

This section is empty.

Variables

Conn is the global database connection.

Functions

func Connect

func Connect(hosts []string, keyspace string) (*gocql.Session, error)

Connect is a function that attempts to connect to a Cassandra cluster.

func Delete

func Delete(table string, query map[string]interface{}) *gocql.Query

Delete creates an insert statement.

func Insert

func Insert(table string, query map[string]interface{}) *gocql.Query

Insert creates an insert statement.

func Select

func Select(table string, fields []string, query map[string]interface{}) *gocql.Query

Select creates a select statement.

func Update added in v1.0.1

func Update(table string, query map[string]interface{}, changes map[string]interface{}) *gocql.Query

Update creates an update statement.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL