当前位置: 首页>>代码示例>>Golang>>正文


Golang gorethink.Cursor类代码示例

本文整理汇总了Golang中github.com/dancannon/gorethink.Cursor的典型用法代码示例。如果您正苦于以下问题:Golang Cursor类的具体用法?Golang Cursor怎么用?Golang Cursor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Cursor类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: changeFeedHelper

func changeFeedHelper(cursor *r.Cursor, changeEventName string,
	send chan<- Message, stop <-chan bool) {
	change := make(chan r.ChangeResponse)
	cursor.Listen(change)
	for {
		eventName := ""
		var data interface{}
		select {
		case <-stop:
			cursor.Close()
			return
		case val := <-change:
			if val.NewValue != nil && val.OldValue == nil {
				eventName = changeEventName + " add"
				data = val.NewValue
			} else if val.NewValue == nil && val.OldValue != nil {
				eventName = changeEventName + " remove"
				data = val.OldValue
			} else if val.NewValue != nil && val.OldValue != nil {
				eventName = changeEventName + " edit"
				data = val.NewValue
			}
			send <- Message{eventName, data}
		}
	}
}
开发者ID:knowthen,项目名称:rtsupportserver,代码行数:26,代码来源:handlers.go

示例2: createSubscription

func createSubscription(cursor *r.Cursor, client *Client, entityName string, stopKey int) {
	recordChan := make(chan r.ChangeResponse)
	cursor.Listen(recordChan)

	stopChan := client.NewStopChannel(stopKey)

	go func() {
		for {
			select {
			case <-stopChan:
				cursor.Close()
				return
			case change := <-recordChan:
				var command string
				var data interface{}
				if change.NewValue != nil && change.OldValue == nil {
					command = entityName + " add"
					data = change.NewValue
				}
				if change.NewValue == nil && change.OldValue != nil {
					command = entityName + " remove"
					data = change.OldValue
					fmt.Println("sent '" + entityName + " remove' msg")
				}
				if change.NewValue != nil && change.OldValue != nil {
					command = entityName + " edit"
					data = change.NewValue
				}
				client.send <- SocketMessage{command, data}
				fmt.Println("sent '"+command+"' msg ", data)
			}
		}
	}()
}
开发者ID:megaserg,项目名称:reactchat,代码行数:34,代码来源:handlers.go

示例3: printResult

func printResult(result *r.Cursor) {
	var kv map[string]interface{}
	i := 0
	for result.Next(&kv) {
		fmt.Println("result", i)
		fmt.Println(kv)
		i = i + 1
	}
}
开发者ID:sumitasok,项目名称:rethinkdb-samples,代码行数:9,代码来源:samples_test.go

示例4: processMultipleCursor

func processMultipleCursor(
	cursor *gorethink.Cursor,
	messageConstructor func() proto.Message,
) ([]interface{}, error) {
	var data []string
	if err := cursor.All(&data); err != nil {
		return nil, err
	}
	result := make([]interface{}, len(data))
	for i, datum := range data {
		message := messageConstructor()
		if err := jsonpb.UnmarshalString(datum, message); err != nil {
			return nil, err
		}
		result[i] = message
	}
	return result, nil
}
开发者ID:klucar,项目名称:pachyderm,代码行数:18,代码来源:rethink_api_server.go

示例5: GetUser

func (d *dbService) GetUser(email string, isApp bool, appId string) (user models.JSON, err error) {
	var c *r.Cursor
	if isApp {
		c, err = d.Run(
			d.Db().Table(APPS_USERS_TABLE).GetAllByIndex(APPS_USERS_TABLE_EMAILAPPID_INDEX, []interface{}{email, appId}).Nth(0),
		)
	} else {
		c, err = d.Run(
			d.Db().Table(USERS_TABLE).GetAllByIndex(USERS_TABLE_EMAIL_INDEX, email).Nth(0),
		)
	}

	if err != nil {
		return
	}

	err = c.One(&user)
	return
}
开发者ID:neutrinoapp,项目名称:neutrino,代码行数:19,代码来源:dbService.go

示例6: InitDB

func InitDB(dbName string) (session *r.Session, err error) {

	var cursor *r.Cursor

	session, err = r.Connect(r.ConnectOpts{
		Address:  os.Getenv("RETHINKDB_URL"),
		Database: dbName,
		MaxIdle:  10,
		Timeout:  time.Second * 10,
	})

	if err != nil {
		l.Println("Connect", err)
		return
	}

	cursor, err = r.DBList().Contains(dbName).Do(func(row r.Term) r.Term {
		return r.Branch(
			row.Eq(true),
			nil,
			r.DBCreate(dbName),
		)
	}).Run(session)
	defer cursor.Close()

	for _, table := range tables {

		cursor, err = r.DB(dbName).TableList().Contains(table.name).Do(func(row r.Term) r.Term {
			return r.Branch(
				row.Eq(true),
				nil,
				r.DB(dbName).TableCreate(table.name, table.options),
			)
		}).Run(session)
		defer cursor.Close()

		if err != nil {
			return
		}
	}

	return
}
开发者ID:Bnei-Baruch,项目名称:mms-file-manager-old,代码行数:43,代码来源:database.go

示例7: packageCursorToUrl

func packageCursorToUrl(c *r.Cursor) (UrlMap, error) {
	rows := []UrlMap{}
	err := c.All(&rows)
	return rows[0], err
}
开发者ID:ifo,项目名称:probablyvalidurl.com,代码行数:5,代码来源:database.go

示例8: Compute

func (bmo *BMO) Compute(input *os.File) {

	var err error
	var cur *r.Cursor
	var session *r.Session

	// set up database connection pool
	session, err = r.Connect(r.ConnectOpts{
		Addresses:     bmo.nodes,
		Database:      bmo.database,
		DiscoverHosts: true,
	})
	session.SetMaxOpenConns(POOL_SIZE)
	if err != nil {
		log.Fatalln(err)
	}
	// ensure table is present
	var tableNames []string
	cur, err = r.DB(bmo.database).TableList().Run(session)
	if err != nil {
		log.Fatalln(err)
	}
	cur.All(&tableNames)
	set := make(map[string]bool)
	for _, v := range tableNames {
		set[v] = true
	}
	if !set[bmo.table] {
		log.Println("Creating table ", bmo.table)
		_, err = r.DB(bmo.database).TableCreate(bmo.table).RunWrite(session)
		if err != nil {
			log.Fatalln("Error creating table: ", err)
			os.Exit(1)
		}
	}

	// deliver the messages
	decoder := json.NewDecoder(input)
	ms := make([]Message, INSERT_BATCH_SIZE)
	var m *Message
	var i uint64
	var ignoreLast bool

	pool, _ := tunny.CreatePoolGeneric(POOL_SIZE).Open()
	defer pool.Close()

	table := r.Table(bmo.table)
	insertOptions := r.InsertOpts{Durability: "soft"}

	insert := func() {
		j := i
		if !ignoreLast {
			j += 1
		}
		_, err = table.Insert(ms[:j], insertOptions).RunWrite(session)
		if err != nil {
			log.Fatal(err)
			os.Exit(1)
		}
	}

	for {
		i = bmo.seq % INSERT_BATCH_SIZE
		m = &ms[i]
		err = decoder.Decode(&m)

		switch {
		case err == io.EOF:
			ignoreLast = true
			pool.SendWork(insert)
			return
		case err != nil:
			ignoreLast = true
			pool.SendWork(insert)
			log.Fatal("Can't parse json input, \"", err, "\". Object #", bmo.seq, ", after ", m)
			os.Exit(1)
		default:
			if i+1 == INSERT_BATCH_SIZE {
				ignoreLast = false
				pool.SendWork(insert)
			}
		}

		bmo.seq += 1
	}
}
开发者ID:cosmicturtle,项目名称:bmo,代码行数:86,代码来源:bmo.go


注:本文中的github.com/dancannon/gorethink.Cursor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。