本文整理汇总了Golang中github.com/dancannon/gorethink.Term类的典型用法代码示例。如果您正苦于以下问题:Golang Term类的具体用法?Golang Term怎么用?Golang Term使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Term类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: addOptions
func addOptions(q rdb.Term, value string, index string, opts *t.BrowseOpt) rdb.Term {
var limit uint = 1024 // TODO(gene): pass into adapter as a config param
var lower, upper interface{}
if opts != nil {
if opts.Since > 0 {
lower = opts.Since
} else {
lower = rdb.MinVal
}
if opts.Before > 0 {
upper = opts.Before
} else {
upper = rdb.MaxVal
}
if value != "" {
lower = []interface{}{value, lower}
upper = []interface{}{value, upper}
}
if opts.Limit > 0 && opts.Limit < limit {
limit = opts.Limit
}
} else {
lower = []interface{}{value, rdb.MinVal}
upper = []interface{}{value, rdb.MaxVal}
}
return q.Between(lower, upper, rdb.BetweenOpts{Index: index}).
OrderBy(rdb.OrderByOpts{Index: rdb.Desc(index)}).Limit(limit)
}
开发者ID:ycaihua,项目名称:chat,代码行数:33,代码来源:adapter.go
示例2: Exec
func (this *Instance) Exec(term r.Term) error {
session, err := this.connect()
if err != nil {
return err
}
return term.Exec(session)
}
开发者ID:ngthorg,项目名称:grox,代码行数:7,代码来源:rethink.go
示例3: RunWrite
func (this *Instance) RunWrite(term r.Term) (r.WriteResponse, error) {
session, err := this.connect()
if err != nil {
return r.WriteResponse{}, err
}
return term.RunWrite(session)
}
开发者ID:ngthorg,项目名称:grox,代码行数:7,代码来源:rethink.go
示例4: Run
func (this *Instance) Run(term r.Term) (*r.Cursor, error) {
session, err := this.connect()
if err != nil {
return nil, err
}
return term.Run(session)
}
开发者ID:ngthorg,项目名称:grox,代码行数:8,代码来源:rethink.go
示例5: asyncDatabaseQuery
func asyncDatabaseQuery(client *Client, operation r.Term) {
go func() {
err := operation.Exec(client.session)
if err != nil {
client.send <- SocketMessage{"error", err.Error()}
}
}()
}
开发者ID:megaserg,项目名称:reactchat,代码行数:8,代码来源:handlers.go
示例6: All
func (this *Instance) All(term r.Term, result interface{}) error {
cursor, err := term.Run(this.session)
if err != nil {
return err
}
return cursor.All(result)
}
开发者ID:ngthorg,项目名称:grox,代码行数:8,代码来源:rethink.go
示例7: addMessage
func (c *rethinkClient) addMessage(term gorethink.Term, message proto.Message) error {
data, err := marshaller.MarshalToString(message)
if err != nil {
return err
}
_, err = term.Insert(gorethink.JSON(data)).RunWrite(c.session)
return err
}
开发者ID:sr,项目名称:pachyderm,代码行数:8,代码来源:rethink_client.go
示例8: Run
func (d *dbService) Run(t r.Term) (*r.Cursor, error) {
s, err := d.GetSession()
if err != nil {
return nil, err
}
defer s.Close()
return t.Run(s)
}
开发者ID:neutrinoapp,项目名称:neutrino,代码行数:9,代码来源:dbService.go
示例9: ListContains
func ListContains(s *r.Session, t r.Term, name string) (bool, error) {
rows, err := t.Contains(name).Run(s)
if err != nil {
return false, err
}
var contains bool
err = rows.One(&contains)
if err != nil {
return false, err
}
return contains, nil
}
开发者ID:pombredanne,项目名称:downloaderd-common,代码行数:13,代码来源:dbutils.go
示例10: getMessageByID
func (c *rethinkClient) getMessageByID(term gorethink.Term, id string, message proto.Message) error {
cursor, err := term.Get(id).ToJSON().Run(c.session)
if err != nil {
return err
}
data := ""
if !cursor.Next(&data) {
return cursor.Err()
}
if err := jsonpb.UnmarshalString(data, message); err != nil {
return err
}
return nil
}
开发者ID:sr,项目名称:pachyderm,代码行数:14,代码来源:rethink_client.go
示例11: getMultiRequest
func (s *RequestStore) getMultiRequest(term r.Term, offset uint, count uint) ([]*download.Request, error) {
var results []*download.Request
rows, err := term.Slice(offset, (offset + count)).Run(s.Session)
if err != nil {
return nil, err
}
err = rows.All(&results)
if err != nil {
return nil, err
}
return results, nil
}
开发者ID:patdowney,项目名称:downloaderd,代码行数:15,代码来源:requeststore.go
示例12: getMultiHook
func (s *HookStore) getMultiHook(term r.Term) ([]*download.Hook, error) {
var results []*download.Hook
rows, err := term.Run(s.Session)
if err != nil {
return results, err
}
err = rows.All(&results)
if err != nil {
return nil, err
}
return results, nil
}
开发者ID:pombredanne,项目名称:downloaderd-worker,代码行数:15,代码来源:hookstore.go
示例13: getMultiple
func (a *rethinkAPIServer) getMultiple(
term gorethink.Term,
messageConstructor func() proto.Message,
modifiers ...func(gorethink.Term) gorethink.Term,
) ([]interface{}, error) {
for _, modifier := range modifiers {
term = modifier(term)
}
term = term.Map(func(row gorethink.Term) interface{} {
return row.ToJSON()
})
cursor, err := term.Run(a.session)
if err != nil {
return nil, err
}
return processMultipleCursor(cursor, messageConstructor)
}
开发者ID:klucar,项目名称:pachyderm,代码行数:17,代码来源:rethink_api_server.go
示例14: getSingleRequest
func (s *RequestStore) getSingleRequest(term r.Term) (*download.Request, error) {
row, err := term.Run(s.Session)
if err != nil {
return nil, err
}
if row.IsNil() {
return nil, nil
}
var request download.Request
err = row.One(&request)
if err != nil {
return nil, err
}
return &request, nil
}
开发者ID:patdowney,项目名称:downloaderd,代码行数:18,代码来源:requeststore.go
示例15: getSingleDownload
func (s *DownloadStore) getSingleDownload(term r.Term) (*download.Download, error) {
row, err := term.Run(s.Session)
if err != nil {
return nil, err
}
if row.IsNil() {
return nil, nil
}
var download download.Download
err = row.One(&download)
if err != nil {
return nil, err
}
return &download, nil
}
开发者ID:pombredanne,项目名称:downloaderd-worker,代码行数:18,代码来源:downloadstore.go
示例16: rethinkToJSON
func rethinkToJSON(row gorethink.Term) interface{} {
return row.ToJSON()
}
开发者ID:klucar,项目名称:pachyderm,代码行数:3,代码来源:rethink_api_server.go
示例17: ResourceKeyIndex
func ResourceKeyIndex(row r.Term) interface{} {
return []interface{}{row.Field("URL"), row.Field("Metadata").Field("ETag")}
}
开发者ID:patdowney,项目名称:downloaderd,代码行数:3,代码来源:requeststore.go
示例18: URLETagIndex
func URLETagIndex(row r.Term) interface{} {
return []interface{}{
row.Field("URL"),
row.Field("Metadata").Field("ETag")}
}
开发者ID:pombredanne,项目名称:downloaderd-worker,代码行数:5,代码来源:downloadindices.go
示例19: List
func (t *ThreadsTable) List(
owner string,
sort []string,
offset int,
limit int,
labels []string,
) ([]*models.Thread, error) {
term := t.GetTable()
if owner != "" {
term = t.GetTable().GetAllByIndex("owner", owner)
}
// If sort array has contents, parse them and add to the term
if sort != nil && len(sort) > 0 {
var conds []interface{}
for _, cond := range sort {
if cond[0] == '-' {
conds = append(conds, gorethink.Desc(cond[1:]))
} else if cond[0] == '+' || cond[0] == ' ' {
conds = append(conds, gorethink.Asc(cond[1:]))
} else {
conds = append(conds, gorethink.Asc(cond))
}
}
term = term.OrderBy(conds...)
}
// Parse labels
hasLabels := []string{}
excLabels := []string{}
for _, label := range labels {
if label[0] == '-' {
excLabels = append(excLabels, label[1:])
} else {
hasLabels = append(hasLabels, label)
}
}
// Transform that into a term
if len(hasLabels) > 0 || len(excLabels) > 0 {
var hasTerm gorethink.Term
if len(hasLabels) == 1 {
hasTerm = gorethink.Row.Field("labels").Contains(hasLabels[0])
} else if len(hasLabels) > 0 {
for i, label := range hasLabels {
if i == 0 {
hasTerm = gorethink.Row.Field("labels").Contains(label)
} else {
hasTerm = hasTerm.And(gorethink.Row.Field("labels").Contains(label))
}
}
}
var excTerm gorethink.Term
if len(excLabels) == 1 {
excTerm = gorethink.Not(gorethink.Row.Field("labels").Contains(excLabels[0]))
} else {
for i, label := range excLabels {
if i == 0 {
excTerm = gorethink.Not(gorethink.Row.Field("labels").Contains(label))
} else {
excTerm = excTerm.And(gorethink.Not(gorethink.Row.Field("labels").Contains(label)))
}
}
}
// Append them into the term
if len(hasLabels) > 0 && len(excLabels) > 0 {
term = term.Filter(hasTerm.And(excTerm))
} else if len(hasLabels) > 0 && len(excLabels) == 0 {
term = term.Filter(hasTerm)
} else if len(hasLabels) == 0 && len(excLabels) > 0 {
term = term.Filter(excTerm)
}
}
// Slice the result
if offset != 0 || limit != 0 {
term = term.Slice(offset, offset+limit)
}
// Add manifests
term = term.Map(func(thread gorethink.Term) gorethink.Term {
return thread.Merge(gorethink.Db(t.GetDBName()).Table("emails").Between([]interface{}{
thread.Field("id"),
time.Date(1990, time.January, 1, 23, 0, 0, 0, time.UTC),
}, []interface{}{
thread.Field("id"),
time.Date(2090, time.January, 1, 23, 0, 0, 0, time.UTC),
}, gorethink.BetweenOpts{
Index: "threadAndDate",
}).OrderBy(gorethink.OrderByOpts{Index: "threadAndDate"}).
Nth(0).Pluck("manifest"))
})
// Run the query
cursor, err := term.Run(t.GetSession())
//.........这里部分代码省略.........
开发者ID:carriercomm,项目名称:lavabot,代码行数:101,代码来源:table_threads.go
示例20: HookKeyIndex
func HookKeyIndex(row r.Term) interface{} {
return []interface{}{row.Field("DownloadID"), row.Field("RequestID")}
}
开发者ID:pombredanne,项目名称:downloaderd-worker,代码行数:3,代码来源:hookstore.go
注:本文中的github.com/dancannon/gorethink.Term类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论