本文整理汇总了Golang中github.com/dancannon/gorethink.Desc函数的典型用法代码示例。如果您正苦于以下问题:Golang Desc函数的具体用法?Golang Desc怎么用?Golang Desc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Desc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: baseFind
func baseFind(o Option) r.Term {
q := r.Table(resourceName)
// slicing
if o.Slice != "" {
slice := strings.Split(o.Slice, ",")
start, _ := strconv.Atoi(slice[0])
end, _ := strconv.Atoi(slice[1])
q = q.Slice(start, end)
}
// ordering
if o.Order != "" {
order := strings.Split(strings.ToLower(o.Order), ",")
if len(order) == 2 && order[1] == "desc" {
q = q.OrderBy(r.Desc(order[0]))
} else {
q = q.OrderBy(order[0])
}
}
// filtering
q = q.Filter(o.Filter)
return q
}
示例2: 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)
}
示例3: loadLatestSales
func loadLatestSales(websocketConnection *websocket.Conn) {
results, err := r.Table("analytics").Filter(M{
"type": "sale",
}).OrderBy(
r.Desc(r.Row.Field("data").Field("date")),
).Limit(10).Map(func(row r.Term) interface{} {
return row.Field("data")
}).Run(rethinkSession)
if err != nil {
log.Printf("error loadLatestSales: %q", err)
}
defer results.Close()
var latestSales []interface{}
err = results.All(&latestSales)
if err != nil {
log.Println(err)
return
}
log.Printf("sending latest %d sales\n", len(latestSales))
socketOutgoingMessage := &SocketOutgoingMessage{
Function: "loadLatestSales",
Data: M{
"type": "sale",
"data": latestSales,
},
}
err = websocketConnection.WriteJSON(socketOutgoingMessage)
if err != nil {
log.Println(err)
}
}
示例4: Slot
func Slot(r Repository) (*db.Cursor, error) {
return db.Table(r.Table()).
Filter(db.Row.Field("slot").Gt(0)).
OrderBy(db.Desc("slot")).
Pluck("id", "name", "slot").
Run(r.Session())
}
示例5: GetAllArticlesInBlog
func (r *repo) GetAllArticlesInBlog(blog *blogalert.Blog) ([]*blogalert.Article, error) {
if blog == nil {
return nil, nil
}
cursor, err := gorethink.DB(Database).Table(ArticleTable).
OrderBy(gorethink.Desc("ts")).
Filter(gorethink.Row.Field("blog").Eq(blog.URL.String())).
Limit(100).
Run(r.session)
if err != nil {
return nil, err
}
a := []*article{}
err = cursor.All(&a)
if err != nil {
return nil, err
}
articles := make([]*blogalert.Article, 0, len(a))
for _, v := range a {
if article, err := v.ToArticle(blog); err == nil {
articles = append(articles, article)
r.cache.SetArticle(article)
}
}
return articles, nil
}
示例6: GetUserArticlesRead
func (r *repo) GetUserArticlesRead(UID string, blog *blogalert.Blog) ([]*blogalert.Article, error) {
if blog == nil {
return nil, nil
}
cursor, err := gorethink.DB(Database).Table(ArticleReadTable).
OrderBy(gorethink.Desc("ts")).
Filter(gorethink.Row.Field("uid").Eq(UID)).
Filter(gorethink.Row.Field("blog").Eq(blog.URL.String())).
Limit(100).
Run(r.session)
if err != nil {
return nil, err
}
a := []*articleRead{}
err = cursor.All(&a)
if err != nil {
return nil, err
}
articles := make([]*blogalert.Article, 0, len(a))
for _, v := range a {
if article, err := r.GetArticle(v.ArticleURL); err == nil {
articles = append(articles, article)
}
}
return articles, nil
}
示例7: List
func List(r Repository, nameField string, offset int, limit int) (*db.Cursor, error) {
return db.Table(r.Table()).
OrderBy(db.OrderByOpts{Index: db.Desc("id")}).
Slice(offset, limit).
Pluck("id", nameField).
Run(r.Session())
}
示例8: subscribeChannelMessage
func subscribeChannelMessage(client *Client, data interface{}) {
go func() {
eventData := data.(map[string]interface{})
val, ok := eventData["channelId"]
if !ok {
return
}
channelId, ok := val.(string)
if !ok {
return
}
stop := client.NewStopChannel(MessageStop)
cursor, err := r.Table("message").
OrderBy(r.OrderByOpts{Index: r.Desc("createdAt")}).
Filter(r.Row.Field("channelId").Eq(channelId)).
Changes(r.ChangesOpts{IncludeInitial: true}).
Run(client.session)
if err != nil {
client.send <- Message{"error", err.Error()}
return
}
changeFeedHelper(cursor, "message", client.send, stop)
}()
}
示例9: Events
func (m *Manager) Events(limit int) ([]*shipyard.Event, error) {
res, err := r.Table(tblNameEvents).OrderBy(r.Desc("Time")).Limit(limit).Run(m.session)
if err != nil {
return nil, err
}
var events []*shipyard.Event
if err := res.All(&events); err != nil {
return nil, err
}
return events, nil
}
示例10: main
func main() {
log.Println("VERSION: ", VERSION)
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(cors.Default().Handler)
e.Index("public/index.html")
e.Static("/", "public")
if len(os.Args) < 2 {
fmt.Println("\nPlease input callback url.\n Usage: app.exe [callback_url]")
os.Exit(0)
}
callback_url = os.Args[1]
//e.Favicon("public/favicon.ico")
server, err := socketio.NewServer(nil)
if err != nil {
log.Fatal(err)
}
e.Get("/publish/photo", CallbackHandler)
e.Post("/publish/photo", ReceiveHandler)
e.Get("/socket.io/", server)
server.On("connection", func(so socketio.Socket) {
log.Println("====================== on connection ======================")
result := make([]interface{}, 12)
cur, err := r.Table("instacat").OrderBy(r.OrderByOpts{
Index: r.Desc("time"),
}).Limit(12).Run(session)
if err != nil {
log.Println(err.Error())
}
cur.All(&result)
fmt.Println("Get result over. ")
err = so.Emit("recent", result)
if err != nil {
log.Println(err.Error())
}
so.On("disconnect", func() {
log.Println("on disconnect")
})
RealtimeChangefeed(so)
})
//go SubscribeTag()
go sub()
port := ":3000"
log.Printf("Starting HTTP service on %s ...", port)
e.Run(port)
}
示例11: Events
func (m DefaultManager) Events(limit int) ([]*shipyard.Event, error) {
t := r.Table(tblNameEvents).OrderBy(r.Desc("Time"))
if limit > -1 {
t.Limit(limit)
}
res, err := t.Run(m.session)
if err != nil {
return nil, err
}
events := []*shipyard.Event{}
if err := res.All(&events); err != nil {
return nil, err
}
return events, nil
}
示例12: GetLatestQuote
func (s *Storage) GetLatestQuote() Quote {
rows, err := r.Table("quotes").OrderBy(r.Desc("timestamp")).Run(s.Session)
if err != nil {
fmt.Println(err)
}
defer rows.Close()
var quote Quote
err2 := rows.One("e)
if err2 != nil {
fmt.Println(err2)
}
fmt.Printf("Fetch one record %#v\n", quote)
return quote
}
示例13: GetPipelineRunStatusLatest
func (c *rethinkClient) GetPipelineRunStatusLatest(id string) (*pps.PipelineRunStatus, error) {
cursor, err := c.statuses.
GetAllByIndex("pipeline_run_id", id).
OrderBy(gorethink.Desc("timestamp")).
Nth(0).
ToJSON().
Run(c.session)
if err != nil {
return nil, err
}
data := ""
if !cursor.Next(&data) {
return nil, cursor.Err()
}
var pipelineRunStatus pps.PipelineRunStatus
if err := jsonpb.UnmarshalString(data, &pipelineRunStatus); err != nil {
return nil, err
}
return &pipelineRunStatus, nil
}
示例14: ListPipelineInfos
func (a *rethinkAPIServer) ListPipelineInfos(ctx context.Context, request *google_protobuf.Empty) (response *persist.PipelineInfos, err error) {
defer func(start time.Time) { a.Log(request, response, err, time.Since(start)) }(time.Now())
pipelineInfoObjs, err := a.getAllMessages(
pipelineInfosTable,
func() proto.Message { return &persist.PipelineInfo{} },
func(term gorethink.Term) gorethink.Term {
return term.OrderBy(gorethink.Desc("created_at"))
},
)
if err != nil {
return nil, err
}
pipelineInfos := make([]*persist.PipelineInfo, len(pipelineInfoObjs))
for i, pipelineInfoObj := range pipelineInfoObjs {
pipelineInfos[i] = pipelineInfoObj.(*persist.PipelineInfo)
}
return &persist.PipelineInfos{
PipelineInfo: pipelineInfos,
}, nil
}
示例15: GetBookmarks
func (c *Connection) GetBookmarks(userID string, page int64) ([]Bookmark, error) {
var bookmarks []Bookmark
cursor, err := r.DB("magnet").
Table("bookmarks").
OrderBy(r.OrderByOpts{r.Desc("Created")}).
Filter(r.Row.Field("User").Eq(userID)).
Skip(50 * page).
Limit(50).
Run(c.session)
if err != nil {
log.Print(err)
return bookmarks, err
}
cursor.All(&bookmarks)
cursor.Close()
return bookmarks, err
}