rethink

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2014 License: GPL-2.0 Imports: 2 Imported by: 0

README

RethinkHelper

A helper to make it a little easier to use gorethink.

I am sure there are a lot of problems with this package. Also the API will change a lot until I am happy with how everything works.

wercker status

Usage

package main

import rh "github.com/Lanciv/rethinkHelper"

func main() {

    db, _ := rh.Connect("localhost:28015", "test")

    // Get a collection with a table name.
    Users := db.NewCollection("users")

    // Insert a record
    userOne := map[string]string{
        "UserName": "test",
        "Password": "testPass",
    }

    ids, err := Users.Insert(userOne)

    if err != nil {
        panic(err)
    }

    userOne["ID"] = ids[0]

}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRecordNotFound for record not being found
	ErrRecordNotFound = errors.New("record not found")
)

Functions

This section is empty.

Types

type Collection

type Collection struct {
	r.Term
	// contains filtered or unexported fields
}

Collection represents a table in rethinkdb. Term should be set to r.Table("CollectionName") db will be set to the db that Collection was initialized with.

func (*Collection) Insert

func (c *Collection) Insert(arg ...interface{}) ([]string, error)

Insert will insert from one to many records and will return their IDs.

func (*Collection) One

func (c *Collection) One(i interface{}, id string) error

One return single record from the DB.

func (*Collection) Update

func (c *Collection) Update(arg interface{}, id string) error

Update will update a single record.

type DB

type DB struct {
	Session *r.Session
	// contains filtered or unexported fields
}

DB represents a connection to the DB and allows you to run queriedb.

func Connect

func Connect(connectOpts r.ConnectOpts) (DB, error)

Connect establishes connection with rethinkDB

func NewDBFromSession

func NewDBFromSession(session *r.Session) DB

NewDBFromSession returns a new DB from an existing gorethink session.

func (*DB) All

func (db *DB) All(i interface{}, term r.Term) error

All will run a query and return the results scanned into an interface.

func (*DB) CreateTables

func (db *DB) CreateTables() error

CreateTables will create all tables in rethinkdb

func (*DB) NewCollection

func (db *DB) NewCollection(name string) *Collection

NewCollection returns a new collection with the db set.

func (*DB) Run

func (db *DB) Run(term r.Term) (*r.Cursor, error)

Run will run a query and return the cursor.

func (*DB) RunWrite

func (db *DB) RunWrite(term r.Term) (r.WriteResponse, error)

RunWrite will run a query for the current session.

Jump to

Keyboard shortcuts

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