Documentation ¶
Overview ¶
Package gorethink implements a Go driver for RethinkDB
Current version: v0.7.2 (RethinkDB v2.0) For more in depth information on how to use RethinkDB check out the API docs at http://rethinkdb.com/api
Example ¶
package main import ( "fmt" "log" "os" r "github.com/dancannon/gorethink" ) var session *r.Session var url, authKey string func init() { // Needed for wercker. By default url is "localhost:28015" url = os.Getenv("RETHINKDB_URL") if url == "" { url = "localhost:28015" } // Needed for running tests for RethinkDB with a non-empty authkey authKey = os.Getenv("RETHINKDB_AUTHKEY") } func main() { session, err := r.Connect(r.ConnectOpts{ Address: url, AuthKey: authKey, }) if err != nil { log.Fatalf("Error connecting to DB: %s", err) } res, err := r.Expr("Hello World").Run(session) if err != nil { log.Fatalln(err.Error()) } var response string err = res.One(&response) if err != nil { log.Fatalln(err.Error()) } fmt.Println(response) }
Output:
Index ¶
- Variables
- func SetVerbose(verbose bool)
- type BetweenOpts
- type ChangesOpts
- type CircleOpts
- type CloseOpts
- type Cluster
- func (c *Cluster) AddSeeds(hosts []Host)
- func (c *Cluster) Close(optArgs ...CloseOpts) error
- func (c *Cluster) Exec(q Query) (err error)
- func (c *Cluster) GetHealthyNodes() []*Node
- func (c *Cluster) GetNodes() []*Node
- func (c *Cluster) GetRandomNode() (*Node, error)
- func (c *Cluster) IsConnected() bool
- func (c *Cluster) Query(q Query) (cursor *Cursor, err error)
- func (c *Cluster) SetMaxIdleConns(n int)
- func (c *Cluster) SetMaxOpenConns(n int)
- type ConnectOpts
- type Connection
- type Cursor
- func (c *Cursor) All(result interface{}) error
- func (c *Cursor) Close() error
- func (c *Cursor) Err() error
- func (c *Cursor) IsNil() bool
- func (c *Cursor) Listen(channel interface{})
- func (c *Cursor) Next(dest interface{}) bool
- func (c *Cursor) One(result interface{}) error
- func (c *Cursor) Profile() interface{}
- func (c *Cursor) Type() string
- type DeleteOpts
- type DistanceOpts
- type DistinctOpts
- type DuringOpts
- type EqJoinOpts
- type ExecOpts
- type FilterOpts
- type GetIntersectingOpts
- type GetNearestOpts
- type Host
- type HttpOpts
- type ISO8601Opts
- type IndexCreateOpts
- type IndexRenameOpts
- type InsertOpts
- type Node
- func (n *Node) Close(optArgs ...CloseOpts) error
- func (n *Node) Closed() bool
- func (n *Node) DecrementHealth()
- func (n *Node) Exec(q Query) (err error)
- func (n *Node) IsHealthy() bool
- func (n *Node) NoReplyWait() error
- func (n *Node) Query(q Query) (cursor *Cursor, err error)
- func (n *Node) Refresh()
- func (n *Node) ResetHealth()
- func (n *Node) SetMaxIdleConns(idleConns int)
- func (n *Node) SetMaxOpenConns(openConns int)
- type OptArgs
- type OrderByOpts
- type Pool
- type Query
- type RandomOpts
- type ReconfigureOpts
- type ReplaceOpts
- type Response
- type RqlClientError
- type RqlCompileError
- type RqlConnectionError
- type RqlDriverError
- type RqlRuntimeError
- type RunOpts
- type Session
- func (s *Session) Close(optArgs ...CloseOpts) error
- func (s *Session) Exec(q Query) error
- func (s *Session) NoReplyWait() error
- func (s *Session) Query(q Query) (*Cursor, error)
- func (s *Session) Reconnect(optArgs ...CloseOpts) error
- func (s *Session) SetHosts(hosts []Host)
- func (s *Session) SetMaxIdleConns(n int)
- func (s *Session) SetMaxOpenConns(n int)
- func (s *Session) Use(database string)
- type SliceOpts
- type TableCreateOpts
- type TableOpts
- type Term
- func Add(args ...interface{}) Term
- func And(args ...interface{}) Term
- func Args(args ...interface{}) Term
- func Asc(args ...interface{}) Term
- func Binary(data interface{}) Term
- func Branch(args ...interface{}) Term
- func Circle(point, radius interface{}, optArgs ...CircleOpts) Term
- func Db(args ...interface{}) Term
- func DbCreate(args ...interface{}) Term
- func DbDrop(args ...interface{}) Term
- func DbList(args ...interface{}) Term
- func Desc(args ...interface{}) Term
- func Distance(point1, point2 interface{}, optArgs ...DistanceOpts) Term
- func Div(args ...interface{}) Term
- func Do(args ...interface{}) Term
- func EpochTime(args ...interface{}) Term
- func Eq(args ...interface{}) Term
- func Error(args ...interface{}) Term
- func Expr(val interface{}) Term
- func Ge(args ...interface{}) Term
- func Geojson(args ...interface{}) Term
- func Gt(args ...interface{}) Term
- func Http(url interface{}, optArgs ...HttpOpts) Term
- func ISO8601(date interface{}, optArgs ...ISO8601Opts) Term
- func Js(jssrc interface{}) Term
- func Json(args ...interface{}) Term
- func Le(args ...interface{}) Term
- func Line(args ...interface{}) Term
- func Literal(args ...interface{}) Term
- func Lt(args ...interface{}) Term
- func Map(args ...interface{}) Term
- func Mod(args ...interface{}) Term
- func Mul(args ...interface{}) Term
- func Ne(args ...interface{}) Term
- func Not(args ...interface{}) Term
- func Now(args ...interface{}) Term
- func Object(args ...interface{}) Term
- func Or(args ...interface{}) Term
- func Point(lon, lat interface{}) Term
- func Polygon(args ...interface{}) Term
- func Range(args ...interface{}) Term
- func Sub(args ...interface{}) Term
- func Table(name interface{}, optArgs ...TableOpts) Term
- func Time(args ...interface{}) Term
- func UUID(args ...interface{}) Term
- func Wait(optArgs ...WaitOpts) Term
- func (t Term) Add(args ...interface{}) Term
- func (t Term) And(args ...interface{}) Term
- func (t Term) Append(args ...interface{}) Term
- func (t Term) AtIndex(args ...interface{}) Term
- func (t Term) Avg(args ...interface{}) Term
- func (t Term) Between(lowerKey, upperKey interface{}, optArgs ...BetweenOpts) Term
- func (t Term) ChangeAt(args ...interface{}) Term
- func (t Term) Changes(optArgs ...ChangesOpts) Term
- func (t Term) CoerceTo(args ...interface{}) Term
- func (t Term) ConcatMap(args ...interface{}) Term
- func (t Term) Config() Term
- func (t Term) Contains(args ...interface{}) Term
- func (t Term) Count(args ...interface{}) Term
- func (t Term) Date(args ...interface{}) Term
- func (t Term) Day(args ...interface{}) Term
- func (t Term) DayOfWeek(args ...interface{}) Term
- func (t Term) DayOfYear(args ...interface{}) Term
- func (t Term) Default(args ...interface{}) Term
- func (t Term) Delete(optArgs ...DeleteOpts) Term
- func (t Term) DeleteAt(args ...interface{}) Term
- func (t Term) Difference(args ...interface{}) Term
- func (t Term) Distance(point interface{}, optArgs ...DistanceOpts) Term
- func (t Term) Distinct(optArgs ...DistinctOpts) Term
- func (t Term) Div(args ...interface{}) Term
- func (t Term) Do(args ...interface{}) Term
- func (t Term) Downcase(args ...interface{}) Term
- func (t Term) During(startTime, endTime interface{}, optArgs ...DuringOpts) Term
- func (t Term) Eq(args ...interface{}) Term
- func (t Term) EqJoin(left, right interface{}, optArgs ...EqJoinOpts) Term
- func (t Term) Exec(s *Session, optArgs ...ExecOpts) error
- func (t Term) Field(args ...interface{}) Term
- func (t Term) Fill() Term
- func (t Term) Filter(f interface{}, optArgs ...FilterOpts) Term
- func (t Term) ForEach(args ...interface{}) Term
- func (t Term) Ge(args ...interface{}) Term
- func (t Term) Get(args ...interface{}) Term
- func (t Term) GetAll(keys ...interface{}) Term
- func (t Term) GetAllByIndex(index interface{}, keys ...interface{}) Term
- func (t Term) GetIntersecting(args interface{}, optArgs ...GetIntersectingOpts) Term
- func (t Term) GetNearest(point interface{}, optArgs ...GetNearestOpts) Term
- func (t Term) Group(fieldOrFunctions ...interface{}) Term
- func (t Term) GroupByIndex(index interface{}, fieldOrFunctions ...interface{}) Term
- func (t Term) Gt(args ...interface{}) Term
- func (t Term) HasFields(args ...interface{}) Term
- func (t Term) Hours(args ...interface{}) Term
- func (t Term) InTimezone(args ...interface{}) Term
- func (t Term) Includes(args ...interface{}) Term
- func (t Term) IndexCreate(name interface{}, optArgs ...IndexCreateOpts) Term
- func (t Term) IndexCreateFunc(name, f interface{}, optArgs ...IndexCreateOpts) Term
- func (t Term) IndexDrop(args ...interface{}) Term
- func (t Term) IndexList(args ...interface{}) Term
- func (t Term) IndexRename(oldName, newName interface{}, optArgs ...IndexRenameOpts) Term
- func (t Term) IndexStatus(args ...interface{}) Term
- func (t Term) IndexWait(args ...interface{}) Term
- func (t Term) Info(args ...interface{}) Term
- func (t Term) InnerJoin(args ...interface{}) Term
- func (t Term) Insert(arg interface{}, optArgs ...InsertOpts) Term
- func (t Term) InsertAt(args ...interface{}) Term
- func (t Term) Intersects(args ...interface{}) Term
- func (t Term) IsEmpty(args ...interface{}) Term
- func (t Term) Keys(args ...interface{}) Term
- func (t Term) Le(args ...interface{}) Term
- func (t Term) Limit(args ...interface{}) Term
- func (t Term) Lt(args ...interface{}) Term
- func (t Term) Map(args ...interface{}) Term
- func (t Term) Match(args ...interface{}) Term
- func (t Term) Max(args ...interface{}) Term
- func (t Term) MaxIndex(index interface{}, args ...interface{}) Term
- func (t Term) Merge(args ...interface{}) Term
- func (t Term) Min(args ...interface{}) Term
- func (t Term) MinIndex(index interface{}, args ...interface{}) Term
- func (t Term) Minutes(args ...interface{}) Term
- func (t Term) Mod(args ...interface{}) Term
- func (t Term) Month(args ...interface{}) Term
- func (t Term) Mul(args ...interface{}) Term
- func (t Term) Ne(args ...interface{}) Term
- func (t Term) Not(args ...interface{}) Term
- func (t Term) Nth(args ...interface{}) Term
- func (t Term) OffsetsOf(args ...interface{}) Term
- func (t Term) Or(args ...interface{}) Term
- func (t Term) OrderBy(args ...interface{}) Term
- func (t Term) OuterJoin(args ...interface{}) Term
- func (t Term) Pluck(args ...interface{}) Term
- func (t Term) PolygonSub(args ...interface{}) Term
- func (t Term) Prepend(args ...interface{}) Term
- func (t Term) Random(args ...interface{}) Term
- func (t Term) Rebalance() Term
- func (t Term) Reconfigure(opts ReconfigureOpts) Term
- func (t Term) Reduce(args ...interface{}) Term
- func (t Term) Replace(arg interface{}, optArgs ...ReplaceOpts) Term
- func (t Term) Run(s *Session, optArgs ...RunOpts) (*Cursor, error)
- func (t Term) RunWrite(s *Session, optArgs ...RunOpts) (WriteResponse, error)
- func (t Term) Sample(args ...interface{}) Term
- func (t Term) Seconds(args ...interface{}) Term
- func (t Term) SetDifference(args ...interface{}) Term
- func (t Term) SetInsert(args ...interface{}) Term
- func (t Term) SetIntersection(args ...interface{}) Term
- func (t Term) SetUnion(args ...interface{}) Term
- func (t Term) Skip(args ...interface{}) Term
- func (t Term) Slice(args ...interface{}) Term
- func (t Term) SpliceAt(args ...interface{}) Term
- func (t Term) Split(args ...interface{}) Term
- func (t Term) Status() Term
- func (t Term) String() string
- func (t Term) Sub(args ...interface{}) Term
- func (t Term) Sum(args ...interface{}) Term
- func (t Term) Sync(args ...interface{}) Term
- func (t Term) Table(name interface{}, optArgs ...TableOpts) Term
- func (t Term) TableCreate(name interface{}, optArgs ...TableCreateOpts) Term
- func (t Term) TableDrop(args ...interface{}) Term
- func (t Term) TableList(args ...interface{}) Term
- func (t Term) TimeOfDay(args ...interface{}) Term
- func (t Term) Timezone(args ...interface{}) Term
- func (t Term) ToEpochTime(args ...interface{}) Term
- func (t Term) ToGeojson(args ...interface{}) Term
- func (t Term) ToISO8601(args ...interface{}) Term
- func (t Term) ToJSON() Term
- func (t Term) TypeOf(args ...interface{}) Term
- func (t Term) Ungroup(args ...interface{}) Term
- func (t Term) Union(args ...interface{}) Term
- func (t Term) Upcase(args ...interface{}) Term
- func (t Term) Update(arg interface{}, optArgs ...UpdateOpts) Term
- func (t Term) Wait(optArgs ...WaitOpts) Term
- func (t Term) WithFields(args ...interface{}) Term
- func (t Term) Without(args ...interface{}) Term
- func (t Term) Year(args ...interface{}) Term
- func (t Term) Zip(args ...interface{}) Term
- type UpdateOpts
- type WaitOpts
- type WriteChanges
- type WriteResponse
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoHosts = errors.New("no hosts provided") ErrNoConnectionsStarted = errors.New("no connections were made when creating the session") ErrHostQueryFailed = errors.New("unable to populate hosts") ErrInvalidNode = errors.New("invalid node") ErrClusterClosed = errors.New("cluster closed") ErrNoConnections = errors.New("gorethink: no connections were available") ErrConnectionClosed = errors.New("gorethink: the connection is closed") ErrBusyBuffer = errors.New("Busy buffer") )
var ( // MinVal represents the smallest possible value RethinkDB can store MinVal = constructRootTerm("MinVal", p.Term_MINVAL, []interface{}{}, map[string]interface{}{}) // MaxVal represents the smallest possible value RethinkDB can store MaxVal = constructRootTerm("MaxVal", p.Term_MAXVAL, []interface{}{}, map[string]interface{}{}) )
var ( // Days Monday = constructRootTerm("Monday", p.Term_MONDAY, []interface{}{}, map[string]interface{}{}) Tuesday = constructRootTerm("Tuesday", p.Term_TUESDAY, []interface{}{}, map[string]interface{}{}) Wednesday = constructRootTerm("Wednesday", p.Term_WEDNESDAY, []interface{}{}, map[string]interface{}{}) Thursday = constructRootTerm("Thursday", p.Term_THURSDAY, []interface{}{}, map[string]interface{}{}) Friday = constructRootTerm("Friday", p.Term_FRIDAY, []interface{}{}, map[string]interface{}{}) Saturday = constructRootTerm("Saturday", p.Term_SATURDAY, []interface{}{}, map[string]interface{}{}) Sunday = constructRootTerm("Sunday", p.Term_SUNDAY, []interface{}{}, map[string]interface{}{}) // Months January = constructRootTerm("January", p.Term_JANUARY, []interface{}{}, map[string]interface{}{}) February = constructRootTerm("February", p.Term_FEBRUARY, []interface{}{}, map[string]interface{}{}) March = constructRootTerm("March", p.Term_MARCH, []interface{}{}, map[string]interface{}{}) April = constructRootTerm("April", p.Term_APRIL, []interface{}{}, map[string]interface{}{}) May = constructRootTerm("May", p.Term_MAY, []interface{}{}, map[string]interface{}{}) June = constructRootTerm("June", p.Term_JUNE, []interface{}{}, map[string]interface{}{}) July = constructRootTerm("July", p.Term_JULY, []interface{}{}, map[string]interface{}{}) August = constructRootTerm("August", p.Term_AUGUST, []interface{}{}, map[string]interface{}{}) September = constructRootTerm("September", p.Term_SEPTEMBER, []interface{}{}, map[string]interface{}{}) October = constructRootTerm("October", p.Term_OCTOBER, []interface{}{}, map[string]interface{}{}) November = constructRootTerm("November", p.Term_NOVEMBER, []interface{}{}, map[string]interface{}{}) December = constructRootTerm("December", p.Term_DECEMBER, []interface{}{}, map[string]interface{}{}) )
var ErrBadConn = errors.New("gorethink: bad connection")
ErrBadConn should be returned by a connection operation to signal to the pool that a driver.Conn is in a bad state (such as the server having earlier closed the connection) and the pool should retry on a new connection.
To prevent duplicate operations, ErrBadConn should NOT be returned if there's a possibility that the database server might have performed the operation. Even if the server sends back an error, you shouldn't return ErrBadConn.
var ErrEmptyResult = errors.New("The result does not contain any more rows")
Error constants
var Row = constructRootTerm("Doc", p.Term_IMPLICIT_VAR, []interface{}{}, map[string]interface{}{})
Returns the currently visited document.
Functions ¶
func SetVerbose ¶ added in v0.7.0
func SetVerbose(verbose bool)
SetVerbose allows the driver logging level to be set. If true is passed then the log level is set to Debug otherwise it defaults to Info.
Types ¶
type BetweenOpts ¶
type BetweenOpts struct { Index interface{} `gorethink:"index,omitempty"` LeftBound interface{} `gorethink:"left_bound,omitempty"` RightBound interface{} `gorethink:"right_bound,omitempty"` }
type ChangesOpts ¶ added in v0.6.0
type ChangesOpts struct { Squash interface{} `gorethink:"squash,omitempty"` IncludeStates interface{} `gorethink:"include_states,omitempty"` }
type CircleOpts ¶ added in v0.5.0
type CircleOpts struct { NumVertices interface{} `gorethink:"num_vertices,omitempty"` GeoSystem interface{} `gorethink:"geo_system,omitempty"` Unit interface{} `gorethink:"unit,omitempty"` Fill interface{} `gorethink:"fill,omitempty"` }
CircleOpts describes the optional arguments for a Circle operation
type CloseOpts ¶
type CloseOpts struct {
NoReplyWait bool `gorethink:"noreplyWait,omitempty"`
}
CloseOpts allows calls to the Close function to be configured.
type Cluster ¶ added in v0.7.0
type Cluster struct {
// contains filtered or unexported fields
}
A Cluster represents a connection to a RethinkDB cluster, a cluster is created by the Session and should rarely be created manually.
The cluster keeps track of all nodes in the cluster and if requested can listen for cluster changes and start tracking a new node if one appears. Currently nodes are removed from the pool if they become unhealthy (100 failed queries). This should hopefully soon be replaced by a backoff system.
func NewCluster ¶ added in v0.7.0
func NewCluster(hosts []Host, opts *ConnectOpts) (*Cluster, error)
NewCluster creates a new cluster by connecting to the given hosts.
func (*Cluster) Exec ¶ added in v0.7.0
Exec executes a ReQL query using the cluster to connect to the database
func (*Cluster) GetHealthyNodes ¶ added in v0.7.0
GetHealthyNodes returns a list of all healthy nodes in the cluster
func (*Cluster) GetRandomNode ¶ added in v0.7.0
GetRandomNode returns a random node on the cluster TODO(dancannon) replace with hostpool
func (*Cluster) IsConnected ¶ added in v0.7.0
IsConnected returns true if cluster has nodes and is not already closed.
func (*Cluster) Query ¶ added in v0.7.0
Query executes a ReQL query using the cluster to connect to the database
func (*Cluster) SetMaxIdleConns ¶ added in v0.7.0
SetMaxIdleConns sets the maximum number of connections in the idle connection pool.
func (*Cluster) SetMaxOpenConns ¶ added in v0.7.0
SetMaxOpenConns sets the maximum number of open connections to the database.
type ConnectOpts ¶
type ConnectOpts struct { Address string `gorethink:"address,omitempty"` Addresses []string `gorethink:"addresses,omitempty"` Database string `gorethink:"database,omitempty"` AuthKey string `gorethink:"authkey,omitempty"` Timeout time.Duration `gorethink:"timeout,omitempty"` TLSConfig *tls.Config `gorethink:"tlsconfig,omitempty"` MaxIdle int `gorethink:"max_idle,omitempty"` MaxOpen int `gorethink:"max_open,omitempty"` // DiscoverHosts is used to enable host discovery, when true the driver // will attempt to discover any new nodes added to the cluster and then // start sending queries to these new nodes. DiscoverHosts bool `gorethink:"discover_hosts,omitempty"` // NodeRefreshInterval is used to determine how often the driver should // refresh the status of a node. NodeRefreshInterval time.Duration `gorethink:"node_refresh_interval,omitempty"` }
ConnectOpts is used to specify optional arguments when connecting to a cluster.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection is a connection to a rethinkdb database. Connection is not thread safe and should only be accessed be a single goroutine
func NewConnection ¶ added in v0.6.0
func NewConnection(address string, opts *ConnectOpts) (*Connection, error)
NewConnection creates a new connection to the database server
type Cursor ¶
type Cursor struct {
// contains filtered or unexported fields
}
Cursor is the result of a query. Its cursor starts before the first row of the result set. A Cursor is not thread safe and should only be accessed by a single goroutine at any given time. Use Next to advance through the rows:
cursor, err := query.Run(session) ... defer cursor.Close() var response interface{} for cursor.Next(&response) { ... } err = cursor.Err() // get any error encountered during iteration ...
func (*Cursor) All ¶
All retrieves all documents from the result set into the provided slice and closes the cursor.
The result argument must necessarily be the address for a slice. The slice may be nil or previously allocated.
Also note that you are able to reuse the same variable multiple times as `All` zeroes the value before scanning in the result. It also attempts to reuse the existing slice without allocating any more space by either resizing or returning a selection of the slice if necessary.
func (*Cursor) Close ¶
Close closes the cursor, preventing further enumeration. If the end is encountered, the cursor is closed automatically. Close is idempotent.
func (*Cursor) Err ¶
Err returns nil if no errors happened during iteration, or the actual error otherwise.
func (*Cursor) Listen ¶ added in v0.7.0
func (c *Cursor) Listen(channel interface{})
Listen listens for rows from the database and sends the result onto the given channel. The type that the row is scanned into is determined by the element type of the channel.
Also note that this function returns immediately.
cursor, err := r.Expr([]int{1,2,3}).Run(session) if err != nil { panic(err) } ch := make(chan int) cursor.Listen(ch) <- ch // 1 <- ch // 2 <- ch // 3
func (*Cursor) Next ¶
Next retrieves the next document from the result set, blocking if necessary. This method will also automatically retrieve another batch of documents from the server when the current one is exhausted, or before that in background if possible.
Next returns true if a document was successfully unmarshalled onto result, and false at the end of the result set or if an error happened. When Next returns false, the Err method should be called to verify if there was an error during iteration.
Also note that you are able to reuse the same variable multiple times as `Next` zeroes the value before scanning in the result.
func (*Cursor) One ¶
One retrieves a single document from the result set into the provided slice and closes the cursor.
Also note that you are able to reuse the same variable multiple times as `One` zeroes the value before scanning in the result.
type DeleteOpts ¶
type DeleteOpts struct { Durability interface{} `gorethink:"durability,omitempty"` ReturnChanges interface{} `gorethink:"return_changes,omitempty"` }
type DistanceOpts ¶ added in v0.5.0
type DistanceOpts struct { GeoSystem interface{} `gorethink:"geo_system,omitempty"` Unit interface{} `gorethink:"unit,omitempty"` }
DistanceOpts describes the optional arguments for a Distance operation
type DistinctOpts ¶ added in v0.4.0
type DistinctOpts struct {
Index interface{} `gorethink:"index,omitempty"`
}
type DuringOpts ¶
type DuringOpts struct { LeftBound interface{} `gorethink:"left_bound,omitempty"` RightBound interface{} `gorethink:"right_bound,omitempty"` }
type EqJoinOpts ¶
type EqJoinOpts struct {
Index interface{} `gorethink:"index,omitempty"`
}
type ExecOpts ¶ added in v0.6.0
type ExecOpts struct { Db interface{} `gorethink:"db,omitempty"` Profile interface{} `gorethink:"profile,omitempty"` UseOutdated interface{} `gorethink:"use_outdated,omitempty"` ArrayLimit interface{} `gorethink:"array_limit,omitempty"` TimeFormat interface{} `gorethink:"time_format,omitempty"` GroupFormat interface{} `gorethink:"group_format,omitempty"` BinaryFormat interface{} `gorethink:"binary_format,omitempty"` GeometryFormat interface{} `gorethink:"geometry_format,omitempty"` MinBatchRows interface{} `gorethink:"min_batch_rows,omitempty"` MaxBatchRows interface{} `gorethink:"max_batch_rows,omitempty"` MaxBatchBytes interface{} `gorethink:"max_batch_bytes,omitempty"` MaxBatchSeconds interface{} `gorethink:"max_batch_seconds,omitempty"` FirstBatchScaledownFactor interface{} `gorethink:"first_batch_scaledown_factor,omitempty"` NoReply interface{} `gorethink:"noreply,omitempty"` }
ExecOpts inherits its options from RunOpts, the only difference is the addition of the NoReply field.
When NoReply is true it causes the driver not to wait to receive the result and return immediately.
type FilterOpts ¶
type FilterOpts struct {
Default interface{} `gorethink:"default,omitempty"`
}
type GetIntersectingOpts ¶ added in v0.5.0
type GetIntersectingOpts struct {
Index interface{} `gorethink:"index,omitempty"`
}
GetIntersectingOpts describes the optional arguments for a GetIntersecting operation
type GetNearestOpts ¶ added in v0.5.0
type GetNearestOpts struct { Index interface{} `gorethink:"index,omitempty"` MaxResults interface{} `gorethink:"max_results,omitempty"` MaxDist interface{} `gorethink:"max_dist,omitempty"` Unit interface{} `gorethink:"unit,omitempty"` GeoSystem interface{} `gorethink:"geo_system,omitempty"` }
GetIntersectingOpts describes the optional arguments for a GetIntersecting operation
type HttpOpts ¶
type HttpOpts struct { // General Options Timeout interface{} `gorethink:"timeout,omitempty"` Reattempts interface{} `gorethink:"reattempts,omitempty"` Redirects interface{} `gorethink:"redirect,omitempty"` Verify interface{} `gorethink:"verify,omitempty"` ResultFormat interface{} `gorethink:"resul_format,omitempty"` // Request Options Method interface{} `gorethink:"method,omitempty"` Auth interface{} `gorethink:"auth,omitempty"` Params interface{} `gorethink:"params,omitempty"` Header interface{} `gorethink:"header,omitempty"` Data interface{} `gorethink:"data,omitempty"` // Pagination Page interface{} `gorethink:"page,omitempty"` PageLimit interface{} `gorethink:"page_limit,omitempty"` }
type ISO8601Opts ¶
type ISO8601Opts struct {
DefaultTimezone interface{} `gorethink:"default_timezone,omitempty"`
}
type IndexCreateOpts ¶
type IndexCreateOpts struct { Multi interface{} `gorethink:"multi,omitempty"` Geo interface{} `gorethink:"geo,omitempty"` }
type IndexRenameOpts ¶ added in v0.4.0
type IndexRenameOpts struct {
Overwrite interface{} `gorethink:"overwrite,omitempty"`
}
type InsertOpts ¶
type InsertOpts struct { Durability interface{} `gorethink:"durability,omitempty"` ReturnChanges interface{} `gorethink:"return_changes,omitempty"` CacheSize interface{} `gorethink:"cache_size,omitempty"` Conflict interface{} `gorethink:"conflict,omitempty"` }
type Node ¶ added in v0.7.0
Node represents a database server in the cluster
func (*Node) DecrementHealth ¶ added in v0.7.0
func (n *Node) DecrementHealth()
DecrementHealth decreases the nodes health by 1 (the nodes health starts at 100)
func (*Node) IsHealthy ¶ added in v0.7.0
IsHealthy checks the nodes health by ensuring that the health counter is above 0.
func (*Node) NoReplyWait ¶ added in v0.7.0
NoReplyWait ensures that previous queries with the noreply flag have been processed by the server. Note that this guarantee only applies to queries run on the given connection
func (*Node) Refresh ¶ added in v0.7.0
func (n *Node) Refresh()
Refresh attempts to connect to the node and check that it is still connected to the cluster.
If an error occurred or the node is no longer connected then the nodes health is decrease, if there were no issues then the node is marked as being healthy.
func (*Node) ResetHealth ¶ added in v0.7.0
func (n *Node) ResetHealth()
ResetHealth sets the nodes health back to 100 (fully healthy)
func (*Node) SetMaxIdleConns ¶ added in v0.7.0
SetMaxIdleConns sets the maximum number of connections in the idle connection pool.
func (*Node) SetMaxOpenConns ¶ added in v0.7.0
SetMaxOpenConns sets the maximum number of open connections to the database.
type OrderByOpts ¶
type OrderByOpts struct {
Index interface{} `gorethink:"index,omitempty"`
}
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
A Pool is used to store a pool of connections to a single RethinkDB server
func NewPool ¶ added in v0.6.0
func NewPool(host Host, opts *ConnectOpts) (*Pool, error)
NewPool creates a new connection pool for the given host
func (*Pool) Close ¶
Close closes the database, releasing any open resources.
It is rare to Close a Pool, as the Pool handle is meant to be long-lived and shared between many goroutines.
func (*Pool) Ping ¶ added in v0.6.0
Ping verifies a connection to the database is still alive, establishing a connection if necessary.
func (*Pool) SetMaxIdleConns ¶ added in v0.6.0
SetMaxIdleConns sets the maximum number of connections in the idle connection pool.
If MaxOpenConns is greater than 0 but less than the new MaxIdleConns then the new MaxIdleConns will be reduced to match the MaxOpenConns limit
If n <= 0, no idle connections are retained.
func (*Pool) SetMaxOpenConns ¶ added in v0.6.0
SetMaxOpenConns sets the maximum number of open connections to the database.
If MaxIdleConns is greater than 0 and the new MaxOpenConns is less than MaxIdleConns, then MaxIdleConns will be reduced to match the new MaxOpenConns limit
If n <= 0, then there is no limit on the number of open connections. The default is 0 (unlimited).
type Query ¶ added in v0.4.0
type Query struct { Type p.Query_QueryType Token int64 Term *Term Opts map[string]interface{} }
type RandomOpts ¶
type RandomOpts struct {
Float interface{} `gorethink:"float,omitempty"`
}
type ReconfigureOpts ¶ added in v0.6.0
type ReconfigureOpts struct { Shards interface{} `gorethink:"shards,omitempty"` Replicas interface{} `gorethink:"replicas,omitempty"` PrimaryTag interface{} `gorethink:"primary_replicas_tag,omitempty"` DryRun interface{} `gorethink:"dry_run,omitempty"` }
type ReplaceOpts ¶
type ReplaceOpts struct { Durability interface{} `gorethink:"durability,omitempty"` ReturnChanges interface{} `gorethink:"return_changes,omitempty"` NotAtomic interface{} `gorethink:"non_atomic,omitempty"` }
type Response ¶ added in v0.4.0
type Response struct { Token int64 Type p.Response_ResponseType `json:"t"` Notes []p.Response_ResponseNote `json:"n"` Responses []json.RawMessage `json:"r"` Backtrace []interface{} `json:"b"` Profile interface{} `json:"p"` }
type RqlClientError ¶
type RqlClientError struct {
// contains filtered or unexported fields
}
type RqlCompileError ¶
type RqlCompileError struct {
// contains filtered or unexported fields
}
type RqlConnectionError ¶
type RqlConnectionError struct {
// contains filtered or unexported fields
}
func (RqlConnectionError) Error ¶
func (e RqlConnectionError) Error() string
func (RqlConnectionError) String ¶
func (e RqlConnectionError) String() string
type RqlDriverError ¶
type RqlDriverError struct {
// contains filtered or unexported fields
}
func (RqlDriverError) Error ¶
func (e RqlDriverError) Error() string
func (RqlDriverError) String ¶
func (e RqlDriverError) String() string
type RqlRuntimeError ¶
type RqlRuntimeError struct {
// contains filtered or unexported fields
}
type RunOpts ¶
type RunOpts struct { Db interface{} `gorethink:"db,omitempty"` Profile interface{} `gorethink:"profile,omitempty"` UseOutdated interface{} `gorethink:"use_outdated,omitempty"` ArrayLimit interface{} `gorethink:"array_limit,omitempty"` TimeFormat interface{} `gorethink:"time_format,omitempty"` GroupFormat interface{} `gorethink:"group_format,omitempty"` BinaryFormat interface{} `gorethink:"binary_format,omitempty"` GeometryFormat interface{} `gorethink:"geometry_format,omitempty"` MinBatchRows interface{} `gorethink:"min_batch_rows,omitempty"` MaxBatchRows interface{} `gorethink:"max_batch_rows,omitempty"` MaxBatchBytes interface{} `gorethink:"max_batch_bytes,omitempty"` MaxBatchSeconds interface{} `gorethink:"max_batch_seconds,omitempty"` FirstBatchScaledownFactor interface{} `gorethink:"first_batch_scaledown_factor,omitempty"` }
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
A Session represents a connection to a RethinkDB cluster and should be used when executing queries.
func Connect ¶
func Connect(opts ConnectOpts) (*Session, error)
Connect creates a new database session. To view the available connection options see ConnectOpts.
By default maxIdle and maxOpen are set to 1: passing values greater than the default (e.g. MaxIdle: "10", MaxOpen: "20") will provide a pool of re-usable connections.
Basic connection example:
session, err := r.Connect(r.ConnectOpts{ Host: "localhost:28015", Database: "test", AuthKey: "14daak1cad13dj", })
Cluster connection example:
session, err := r.Connect(r.ConnectOpts{ Hosts: []string{"localhost:28015", "localhost:28016"}, Database: "test", AuthKey: "14daak1cad13dj", })
func (*Session) Exec ¶ added in v0.7.0
Exec executes a ReQL query using the session to connect to the database
func (*Session) NoReplyWait ¶
NoReplyWait ensures that previous queries with the noreply flag have been processed by the server. Note that this guarantee only applies to queries run on the given connection
func (*Session) Query ¶ added in v0.7.0
Query executes a ReQL query using the session to connect to the database
func (*Session) SetHosts ¶ added in v0.7.0
SetHosts resets the hosts used when connecting to the RethinkDB cluster
func (*Session) SetMaxIdleConns ¶
SetMaxIdleConns sets the maximum number of connections in the idle connection pool.
func (*Session) SetMaxOpenConns ¶
SetMaxOpenConns sets the maximum number of open connections to the database.
type SliceOpts ¶
type SliceOpts struct { LeftBound interface{} `gorethink:"left_bound,omitempty"` RightBound interface{} `gorethink:"right_bound,omitempty"` }
type TableCreateOpts ¶
type TableCreateOpts struct { PrimaryKey interface{} `gorethink:"primary_key,omitempty"` Durability interface{} `gorethink:"durability,omitempty"` CacheSize interface{} `gorethink:"cache_size,omitempty"` DataCenter interface{} `gorethink:"datacenter,omitempty"` }
type TableOpts ¶
type TableOpts struct { UseOutdated interface{} `gorethink:"use_outdated,omitempty"` IdentifierFormat interface{} `gorethink:"identifier_format,omitempty"` }
type Term ¶
type Term struct {
// contains filtered or unexported fields
}
func Args ¶
func Args(args ...interface{}) Term
Args is a special term usd to splice an array of arguments into another term. This is useful when you want to call a varadic term such as GetAll with a set of arguments provided at runtime.
func Binary ¶ added in v0.4.0
func Binary(data interface{}) Term
Binary encapsulates binary data within a query.
func Branch ¶
func Branch(args ...interface{}) Term
Evaluate one of two control paths based on the value of an expression. branch is effectively an if renamed due to language constraints.
The type of the result is determined by the type of the branch that gets executed.
func Circle ¶ added in v0.5.0
func Circle(point, radius interface{}, optArgs ...CircleOpts) Term
Circle constructs a circular line or polygon. A circle in RethinkDB is a polygon or line approximating a circle of a given radius around a given center, consisting of a specified number of vertices (default 32).
func DbCreate ¶
func DbCreate(args ...interface{}) Term
Create a database. A RethinkDB database is a collection of tables, similar to relational databases.
If successful, the operation returns an object: {created: 1}. If a database with the same name already exists the operation throws RqlRuntimeError.
Note: that you can only use alphanumeric characters and underscores for the database name.
func DbDrop ¶
func DbDrop(args ...interface{}) Term
Drop a database. The database, all its tables, and corresponding data will be deleted.
If successful, the operation returns the object {dropped: 1}. If the specified database doesn't exist a RqlRuntimeError is thrown.
func Distance ¶ added in v0.5.0
func Distance(point1, point2 interface{}, optArgs ...DistanceOpts) Term
Distance calculates the Haversine distance between two points. At least one of the geometry objects specified must be a point.
func Do ¶
func Do(args ...interface{}) Term
Evaluate the expr in the context of one or more value bindings. The type of the result is the type of the value returned from expr.
func EpochTime ¶
func EpochTime(args ...interface{}) Term
Returns a time object based on seconds since epoch
func Error ¶
func Error(args ...interface{}) Term
Throw a runtime error. If called with no arguments inside the second argument to `default`, re-throw the current error.
func Expr ¶
func Expr(val interface{}) Term
Expr converts any value to an expression. Internally it uses the `json` module to convert any literals, so any type annotations or methods understood by that module can be used. If the value cannot be converted, an error is returned at query .Run(session) time.
If you want to call expression methods on an object that is not yet an expression, this is the function you want.
func Ge ¶
func Ge(args ...interface{}) Term
Ge returns true if the first value is greater than or equal to the second.
func Geojson ¶ added in v0.5.0
func Geojson(args ...interface{}) Term
Geojson converts a GeoJSON object to a ReQL geometry object.
func Gt ¶
func Gt(args ...interface{}) Term
Gt returns true if the first value is greater than the second.
func ISO8601 ¶
func ISO8601(date interface{}, optArgs ...ISO8601Opts) Term
Returns a time object based on an ISO8601 formatted date-time string
Optional arguments (see http://www.rethinkdb.com/api/#js:dates_and_times-iso8601 for more information): "default_timezone" (string)
func Le ¶
func Le(args ...interface{}) Term
Le returns true if the first value is less than or equal to the second.
func Line ¶ added in v0.5.0
func Line(args ...interface{}) Term
Line constructs a geometry object of type Line. The line can be specified in one of two ways:
- Two or more two-item arrays, specifying longitude and latitude numbers of the line's vertices;
- Two or more Point objects specifying the line's vertices.
func Lt ¶
func Lt(args ...interface{}) Term
Lt returns true if the first value is less than the second.
func Map ¶ added in v0.6.0
func Map(args ...interface{}) Term
Map transform each element of the sequence by applying the given mapping function. It takes two arguments, a sequence and a function of type `func (r.Term) interface{}`.
For example this query doubles each element in an array:
r.Map([]int{1,3,6}, func (row r.Term) interface{} { return row.Mul(2) })
func Now ¶
func Now(args ...interface{}) Term
Returns a time object representing the current time in UTC
func Object ¶
func Object(args ...interface{}) Term
Creates an object from a list of key-value pairs, where the keys must be strings.
func Point ¶ added in v0.5.0
func Point(lon, lat interface{}) Term
Point constructs a geometry object of type Point. The point is specified by two floating point numbers, the longitude (−180 to 180) and latitude (−90 to 90) of the point on a perfect sphere.
func Polygon ¶ added in v0.5.0
func Polygon(args ...interface{}) Term
Polygon constructs a geometry object of type Polygon. The Polygon can be specified in one of two ways:
- Three or more two-item arrays, specifying longitude and latitude numbers of the polygon's vertices;
- Three or more Point objects specifying the polygon's vertices.
func Range ¶ added in v0.6.0
func Range(args ...interface{}) Term
Range generates a stream of sequential integers in a specified range. It accepts 0, 1, or 2 arguments, all of which should be numbers.
func Table ¶
Select all documents in a table. This command can be chained with other commands to do further processing on the data.
Optional arguments (see http://www.rethinkdb.com/api/#js:selecting_data-table for more information): "use_outdated" (boolean - defaults to false)
func UUID ¶ added in v0.5.0
func UUID(args ...interface{}) Term
UUID returns a UUID (universally unique identifier), a string that can be used as a unique ID.
func Wait ¶ added in v0.6.0
Wait for a table or all the tables in a database to be ready. A table may be temporarily unavailable after creation, rebalancing or reconfiguring. The wait command blocks until the given table (or database) is fully up to date.
func (Term) AtIndex ¶ added in v0.5.0
AtIndex gets a single field from an object or the nth element from a sequence.
func (Term) Avg ¶
Averages all the elements of a sequence. If called with a field name, averages all the values of that field in the sequence, skipping elements of the sequence that lack that field. If called with a function, calls that function on every element of the sequence and averages the results, skipping elements of the sequence where that function returns null or a non-existence error.
func (Term) Between ¶
func (t Term) Between(lowerKey, upperKey interface{}, optArgs ...BetweenOpts) Term
Get all documents between two keys. Accepts three optional arguments: `index`, `left_bound`, and `right_bound`. If `index` is set to the name of a secondary index, `between` will return all documents where that index's value is in the specified range (it uses the primary key by default). `left_bound` or `right_bound` may be set to `open` or `closed` to indicate whether or not to include that endpoint of the range (by default, `left_bound` is closed and `right_bound` is open).
func (Term) Changes ¶
func (t Term) Changes(optArgs ...ChangesOpts) Term
Takes a table and returns an infinite stream of objects representing changes to that table. Whenever an insert, delete, update or replace is performed on the table, an object of the form {old_val:..., new_val:...} will be added to the stream. For an insert, old_val will be null, and for a delete, new_val will be null.
func (Term) CoerceTo ¶
Converts a value of one type into another.
You can convert: a selection, sequence, or object into an ARRAY, an array of pairs into an OBJECT, and any DATUM into a STRING.
func (Term) ConcatMap ¶
Flattens a sequence of arrays returned by the mapping function into a single sequence.
func (Term) Config ¶ added in v0.6.0
Config can be used to read and/or update the configurations for individual tables or databases.
func (Term) Contains ¶
Returns whether or not a sequence contains all the specified values, or if functions are provided instead, returns whether or not a sequence contains values matching all the specified functions.
func (Term) Count ¶
Count the number of elements in the sequence. With a single argument, count the number of elements equal to it. If the argument is a function, it is equivalent to calling filter before count.
func (Term) Date ¶
Return a new time object only based on the day, month and year (ie. the same day at 00:00).
func (Term) DayOfWeek ¶
Return the day of week of a time object as a number between 1 and 7 (following ISO 8601 standard). For your convenience, the terms r.Monday(), r.Tuesday() etc. are defined and map to the appropriate integer.
func (Term) DayOfYear ¶
Return the day of the year of a time object as a number between 1 and 366 (following ISO 8601 standard).
func (Term) Default ¶
Handle non-existence errors. Tries to evaluate and return its first argument. If an error related to the absence of a value is thrown in the process, or if its first argument returns null, returns its second argument. (Alternatively, the second argument may be a function which will be called with either the text of the non-existence error or null.)
func (Term) Delete ¶
func (t Term) Delete(optArgs ...DeleteOpts) Term
Delete one or more documents from a table. The optional argument return_changes will return the old value of the row you're deleting when set to true (only valid for single-row deletes). The optional argument durability with value 'hard' or 'soft' will override the table or query's default durability setting.
func (Term) DeleteAt ¶
Remove an element from an array at a given index. Returns the modified array.
func (Term) Difference ¶
Remove the elements of one array from another array.
func (Term) Distance ¶ added in v0.5.0
func (t Term) Distance(point interface{}, optArgs ...DistanceOpts) Term
Distance calculates the Haversine distance between two points. At least one of the geometry objects specified must be a point.
func (Term) Distinct ¶
func (t Term) Distinct(optArgs ...DistinctOpts) Term
Remove duplicate elements from the sequence.
func (Term) Do ¶
Evaluate the expr in the context of one or more value bindings. The type of the result is the type of the value returned from expr.
func (Term) During ¶
func (t Term) During(startTime, endTime interface{}, optArgs ...DuringOpts) Term
Returns true if a time is between two other times (by default, inclusive for the start, exclusive for the end).
Optional arguments (see http://www.rethinkdb.com/api/#js:dates_and_times-during for more information): "left_bound" and "right_bound" ("open" for exclusive or "closed" for inclusive)
func (Term) EqJoin ¶
func (t Term) EqJoin(left, right interface{}, optArgs ...EqJoinOpts) Term
An efficient join that looks up elements in the right table by primary key.
Optional arguments: "index" (string - name of the index to use in right table instead of the primary key)
func (Term) Exec ¶
Exec runs the query but does not return the result. Exec will still wait for the response to be received unless the NoReply field is true.
err := r.Db("database").Table("table").Insert(doc).Exec(sess, r.ExecOpts{ NoReply: true, })
func (Term) Field ¶
Get a single field from an object. If called on a sequence, gets that field from every object in the sequence, skipping objects that lack it.
func (Term) Fill ¶ added in v0.5.0
Fill converts a Line object into a Polygon object. If the last point does not specify the same coordinates as the first point, polygon will close the polygon by connecting them
func (Term) Filter ¶
func (t Term) Filter(f interface{}, optArgs ...FilterOpts) Term
Get all the documents for which the given predicate is true.
Filter can be called on a sequence, selection, or a field containing an array of elements. The return type is the same as the type on which the function was called on. The body of every filter is wrapped in an implicit `.default(false)`, and the default value can be changed by passing the optional argument `default`. Setting this optional argument to `r.error()` will cause any non-existence errors to abort the filter.
func (Term) ForEach ¶
ForEach loops over a sequence, evaluating the given write query for each element.
It takes one argument of type `func (r.Term) interface{}`, for example clones a table:
r.Table("table").ForEach(func (row r.Term) interface{} { return r.Table("new_table").Insert(row) })
func (Term) Get ¶
Get a document by primary key. If nothing was found, RethinkDB will return a nil value.
func (Term) GetAll ¶
Get all documents where the given value matches the value of the primary index.
func (Term) GetAllByIndex ¶
Get all documents where the given value matches the value of the requested index.
func (Term) GetIntersecting ¶ added in v0.5.0
func (t Term) GetIntersecting(args interface{}, optArgs ...GetIntersectingOpts) Term
GetIntersecting gets all documents where the given geometry object intersects the geometry object of the requested geospatial index.
func (Term) GetNearest ¶ added in v0.5.0
func (t Term) GetNearest(point interface{}, optArgs ...GetNearestOpts) Term
GetNearest gets all documents where the specified geospatial index is within a certain distance of the specified point (default 100 kilometers).
func (Term) Group ¶
Takes a stream and partitions it into multiple groups based on the fields or functions provided. Commands chained after group will be
called on each of these grouped sub-streams, producing grouped data.
func (Term) GroupByIndex ¶
Takes a stream and partitions it into multiple groups based on the fields or functions provided. Commands chained after group will be called on each of these grouped sub-streams, producing grouped data.
func (Term) HasFields ¶
Test if an object has all of the specified fields. An object has a field if it has the specified key and that key maps to a non-null value. For instance,
the object `{'a':1,'b':2,'c':null}` has the fields `a` and `b`.
func (Term) InTimezone ¶
Returns a new time object with a different time zone. While the time stays the same, the results returned by methods such as hours() will change since they take the timezone into account. The timezone argument has to be of the ISO 8601 format.
func (Term) Includes ¶ added in v0.5.0
Includes tests whether a geometry object is completely contained within another. When applied to a sequence of geometry objects, includes acts as a filter, returning a sequence of objects from the sequence that include the argument.
func (Term) IndexCreate ¶
func (t Term) IndexCreate(name interface{}, optArgs ...IndexCreateOpts) Term
Create a new secondary index on this table.
A multi index can be created by passing an optional multi argument. Multi indexes
functions should return arrays and allow you to query based on whether a value is present in the returned array. The example would allow us to get heroes who possess a specific ability (the field 'abilities' is an array).
func (Term) IndexCreateFunc ¶
func (t Term) IndexCreateFunc(name, f interface{}, optArgs ...IndexCreateOpts) Term
Create a new secondary index on this table based on the value of the function passed.
A compound index can be created by returning an array of values to use as the secondary index key.
func (Term) IndexRename ¶ added in v0.4.0
func (t Term) IndexRename(oldName, newName interface{}, optArgs ...IndexRenameOpts) Term
IndexRename renames an existing secondary index on a table. If the optional argument overwrite is specified as True, a previously existing index with the new name will be deleted and the index will be renamed. If overwrite is False (the default) an error will be raised if the new index name already exists.
func (Term) IndexStatus ¶
Get the status of the specified indexes on this table, or the status of all indexes on this table if no indexes are specified.
func (Term) IndexWait ¶
Wait for the specified indexes on this table to be ready, or for all indexes on this table to be ready if no indexes are specified.
func (Term) InnerJoin ¶
Returns the inner product of two sequences (e.g. a table, a filter result) filtered by the predicate. The query compares each row of the left sequence with each row of the right sequence to find all pairs of rows which satisfy the predicate. When the predicate is satisfied, each matched pair of rows of both sequences are combined into a result row.
func (Term) Insert ¶
func (t Term) Insert(arg interface{}, optArgs ...InsertOpts) Term
Insert JSON documents into a table. Accepts a single JSON document or an array of documents. You may also pass the optional argument durability with value 'hard' or 'soft', to override the table or query's default durability setting, or the optional argument return_changes, which will return the value of the row you're inserting when set to true.
table.Insert(map[string]interface{}{"name": "Joe", "email": "joe@example.com"}).RunWrite(sess) table.Insert([]interface{}{map[string]interface{}{"name": "Joe"}, map[string]interface{}{"name": "Paul"}}).RunWrite(sess)
func (Term) Intersects ¶ added in v0.5.0
Intersects tests whether two geometry objects intersect with one another. When applied to a sequence of geometry objects, intersects acts as a filter, returning a sequence of objects from the sequence that intersect with the argument.
func (Term) Map ¶
Map transforms each element of the sequence by applying the given mapping function. It takes one argument of type `func (r.Term) interface{}`.
For example this query doubles each element in an array:
r.Expr([]int{1,3,6}).Map(func (row r.Term) interface{} { return row.Mul(2) })
func (Term) Match ¶
Match against a regular expression. Returns a match object containing the matched string, that string's start/end position, and the capture groups.
Expr("id:0,name:mlucy,foo:bar").Match("name:(\\w+)").Field("groups").Nth(0).Field("str")
func (Term) Max ¶
Finds the maximum of a sequence. If called with a field name, finds the element of that sequence with the largest value in that field. If called with a function, calls that function on every element of the sequence and returns the element which produced the largest value, ignoring any elements where the function returns null or produces a non-existence error.
func (Term) MaxIndex ¶ added in v0.6.0
Finds the maximum of a sequence. If called with a field name, finds the element of that sequence with the largest value in that field. If called with a function, calls that function on every element of the sequence and returns the element which produced the largest value, ignoring any elements where the function returns null or produces a non-existence error.
func (Term) Merge ¶
Merge two objects together to construct a new object with properties from both. Gives preference to attributes from other when there is a conflict.
func (Term) Min ¶
Finds the minimum of a sequence. If called with a field name, finds the element of that sequence with the smallest value in that field. If called with a function, calls that function on every element of the sequence and returns the element which produced the smallest value, ignoring any elements where the function returns null or produces a non-existence error.
func (Term) MinIndex ¶ added in v0.6.0
Finds the minimum of a sequence. If called with a field name, finds the element of that sequence with the smallest value in that field. If called with a function, calls that function on every element of the sequence and returns the element which produced the smallest value, ignoring any elements where the function returns null or produces a non-existence error.
func (Term) Month ¶
Return the month of a time object as a number between 1 and 12. For your convenience, the terms r.January(), r.February() etc. are defined and map to the appropriate integer.
func (Term) OffsetsOf ¶ added in v0.7.0
Get the indexes of an element in a sequence. If the argument is a predicate, get the indexes of all elements matching it.
func (Term) OrderBy ¶
Sort the sequence by document values of the given key(s). To specify the index to use for ordering us a last argument in the following form:
OrderByOpts{Index: "index-name"}
OrderBy defaults to ascending ordering. To explicitly specify the ordering, wrap the attribute with either Asc or Desc.
query.OrderBy("name") query.OrderBy(Asc("name")) query.OrderBy(Desc("name"))
func (Term) OuterJoin ¶
Computes a left outer join by retaining each row in the left table even if no match was found in the right table.
func (Term) Pluck ¶
Plucks out one or more attributes from either an object or a sequence of objects (projection).
func (Term) PolygonSub ¶ added in v0.5.0
PolygonSub "punches a hole" out of the parent polygon using the polygon passed to the function.
polygon1.PolygonSub(polygon2) -> polygon
In the example above polygon2 must be completely contained within polygon1 and must have no holes itself (it must not be the output of polygon_sub itself).
func (Term) Random ¶
Generate a random number between the given bounds. If no arguments are given, the result will be a floating-point number in the range [0,1).
When passing a single argument, r.random(x), the result will be in the range [0,x), and when passing two arguments, r.random(x,y), the range is [x,y). If x and y are equal, an error will occur, unless generating a floating-point number, for which x will be returned.
Note: The last argument given will always be the 'open' side of the range, but when generating a floating-point number, the 'open' side may be less than the 'closed' side.
func (Term) Rebalance ¶ added in v0.6.0
Rebalance rebalances the shards of a table. When called on a database, all the tables in that database will be rebalanced.
func (Term) Reconfigure ¶ added in v0.6.0
func (t Term) Reconfigure(opts ReconfigureOpts) Term
Reconfigure a table's sharding and replication.
func (Term) Reduce ¶
Reduce produces a single value from a sequence through repeated application of a reduction function
It takes one argument of type `func (r.Term, r.Term) interface{}`, for example this query sums all elements in an array:
r.Expr([]int{1,3,6}).Reduce(func (left, right r.Term) interface{} { return left.Add(right) })
func (Term) Replace ¶
func (t Term) Replace(arg interface{}, optArgs ...ReplaceOpts) Term
Replace documents in a table. Accepts a JSON document or a RQL expression, and replaces the original document with the new one. The new document must have the same primary key as the original document. The optional argument durability with value 'hard' or 'soft' will override the table or query's default durability setting. The optional argument return_changes will return the old and new values of the row you're modifying when set to true (only valid for single-row replacements). The optional argument non_atomic lets you permit non-atomic updates.
func (Term) Run ¶
Run runs a query using the given connection.
rows, err := query.Run(sess) if err != nil { // error } var doc MyDocumentType for rows.Next(&doc) { // Do something with document }
func (Term) RunWrite ¶
func (t Term) RunWrite(s *Session, optArgs ...RunOpts) (WriteResponse, error)
RunWrite runs a query using the given connection but unlike Run automatically scans the result into a variable of type WriteResponss. This function should be used if you are running a write query (such as Insert, Update, TableCreate, etc...)
res, err := r.Db("database").Table("table").Insert(doc).RunWrite(sess)
func (Term) Sample ¶
Select a given number of elements from a sequence with uniform random distribution. Selection is done without replacement.
func (Term) Seconds ¶
Return the seconds in a time object as a number between 0 and 59.999 (double precision).
func (Term) SetDifference ¶
Remove the elements of one array from another and return them as a set (an array with distinct values).
func (Term) SetInsert ¶
Add a value to an array and return it as a set (an array with distinct values).
func (Term) SetIntersection ¶
Intersect two arrays returning values that occur in both of them as a set (an array with distinct values).
func (Term) SetUnion ¶
Add a several values to an array and return it as a set (an array with distinct values).
func (Term) SpliceAt ¶
Insert several values in to an array at a given index. Returns the modified array.
func (Term) Split ¶
Splits a string into substrings. Splits on whitespace when called with no arguments. When called with a separator, splits on that separator. When called with a separator and a maximum number of splits, splits on that separator at most max_splits times. (Can be called with null as the separator if you want to split on whitespace while still specifying max_splits.)
Mimics the behavior of Python's string.split in edge cases, except for splitting on the empty string, which instead produces an array of single-character strings.
func (Term) Sum ¶
Sums all the elements of a sequence. If called with a field name, sums all the values of that field in the sequence, skipping elements of the sequence that lack that field. If called with a function, calls that function on every element of the sequence and sums the results, skipping elements of the sequence where that function returns null or a non-existence error.
func (Term) Sync ¶
Sync ensures that writes on a given table are written to permanent storage. Queries that specify soft durability (Durability: "soft") do not give such guarantees, so sync can be used to ensure the state of these queries. A call to sync does not return until all previous writes to the table are persisted.
func (Term) Table ¶
Select all documents in a table. This command can be chained with other commands to do further processing on the data.
Optional arguments (see http://www.rethinkdb.com/api/#js:selecting_data-table for more information): "use_outdated" (boolean - defaults to false)
func (Term) TableCreate ¶
func (t Term) TableCreate(name interface{}, optArgs ...TableCreateOpts) Term
Create a table. A RethinkDB table is a collection of JSON documents.
If successful, the operation returns an object: {created: 1}. If a table with the same name already exists, the operation throws RqlRuntimeError.
Note: that you can only use alphanumeric characters and underscores for the table name.
r.Db("database").TableCreate("table", "durability", "soft").Run(sess)
func (Term) TableDrop ¶
Drop a table. The table and all its data will be deleted.
If successful, the operation returns an object: {dropped: 1}. If the specified table doesn't exist a RqlRuntimeError is thrown.
func (Term) TimeOfDay ¶
Return the number of seconds elapsed since the beginning of the day stored in the time object.
func (Term) ToEpochTime ¶
Convert a time object to its epoch time.
func (Term) ToGeojson ¶ added in v0.5.0
ToGeojson converts a ReQL geometry object to a GeoJSON object.
func (Term) Update ¶
func (t Term) Update(arg interface{}, optArgs ...UpdateOpts) Term
Update JSON documents in a table. Accepts a JSON document, a RQL expression, or a combination of the two. The optional argument durability with value 'hard' or 'soft' will override the table or query's default durability setting. The optional argument return_changes will return the old and new values of the row you're modifying when set to true (only valid for single-row updates). The optional argument non_atomic lets you permit non-atomic updates.
func (Term) Wait ¶ added in v0.6.0
Wait for a table or all the tables in a database to be ready. A table may be temporarily unavailable after creation, rebalancing or reconfiguring. The wait command blocks until the given table (or database) is fully up to date.
func (Term) WithFields ¶
Takes a sequence of objects and a list of fields. If any objects in the sequence don't have all of the specified fields, they're dropped from the sequence. The remaining objects have the specified fields plucked out. (This is identical to `HasFields` followed by `Pluck` on a sequence.)
type UpdateOpts ¶
type UpdateOpts struct { Durability interface{} `gorethink:"durability,omitempty"` ReturnChanges interface{} `gorethink:"return_changes,omitempty"` NotAtomic interface{} `gorethink:"non_atomic,omitempty"` }
type WaitOpts ¶ added in v0.7.0
type WaitOpts struct { WaitFor interface{} `gorethink:"wait_for,omitempty"` Timeout interface{} `gorethink:"timeout,omitempty"` }
type WriteChanges ¶ added in v0.4.2
type WriteChanges struct { NewValue interface{} `gorethink:"new_val"` OldValue interface{} `gorethink:"old_val"` }
type WriteResponse ¶
type WriteResponse struct { Errors int `gorethink:"errors"` Inserted int `gorethink:"inserted"` Updated int `gorethink:"updadte"` Unchanged int `gorethink:"unchanged"` Replaced int `gorethink:"replaced"` Renamed int `gorethink:"renamed"` Skipped int `gorethink:"skipped"` Deleted int `gorethink:"deleted"` Created int `gorethink:"created"` DBsCreated int `gorethink:"dbs_created"` TablesCreated int `gorethink:"tables_created"` Dropped int `gorethink:"dropped"` DBsDropped int `gorethink:"dbs_dropped"` TablesDropped int `gorethink:"tables_dropped"` GeneratedKeys []string `gorethink:"generated_keys"` FirstError string `gorethink:"first_error"` // populated if Errors > 0 ConfigChanges []WriteChanges `gorethink:"config_changes"` Changes []WriteChanges }
Source Files ¶
- buffer.go
- cluster.go
- connection.go
- connection_helper.go
- cursor.go
- doc.go
- errors.go
- gorethink.go
- host.go
- node.go
- pool.go
- pool_conn.go
- pseudotypes.go
- query.go
- query_admin.go
- query_aggregation.go
- query_control.go
- query_db.go
- query_geospatial.go
- query_join.go
- query_manipulation.go
- query_math.go
- query_select.go
- query_string.go
- query_table.go
- query_time.go
- query_transformation.go
- query_write.go
- session.go
- utils.go