• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang gorethink.Db函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: SetupSuite

func (suite *UserStoreSuite) SetupSuite() {
	store, err := newTestUserStore()
	if err != nil {
		panic(err)
	}
	suite.store = store

	// create necessary DB, table, indices
	_, err = r.DbCreate("test").Run(suite.store.conn)
	if err != nil {
		panic(err)
	}
	_, err = r.Db("test").TableCreate("users").Run(suite.store.conn)
	if err != nil {
		panic(err)
	}
	_, err = r.Db("test").Table("users").IndexCreate("email").Run(suite.store.conn)
	if err != nil {
		panic(err)
	}

	suite.user = NewUser("[email protected]", "password")
	_, err = r.Db("test").Table("users").Insert(suite.user).RunWrite(suite.store.conn)
	if err != nil {
		panic(err)
	}
}
开发者ID:plants,项目名称:sesame,代码行数:27,代码来源:persistence_test.go


示例2: createTableWithOptions

func (db *RethinkDBAdapter) createTableWithOptions(tableName string, rdbOptions *r.TableCreateOpts) *CASServerError {
	logMessagef(db.LogLevel, "INFO", "Creating table [%s], options: %v", tableName, rdbOptions)

	// Check again that rdbOptions is not nil, optionally leave out argument
	var err error
	if rdbOptions == nil {

		// Create table with no options
		_, err = r.Db(db.dbName).TableCreate(tableName).Run(db.session)

	} else {

		// Set and get the table options (so that they can be retrieved later
		db.setTableSetupOptions(tableName, rdbOptions)
		options, err := db.getTableSetupOptions(tableName)
		if err != nil {
			casError := &FailedToCreateTableError
			casError.err = &err
			return casError
		}

		// Create table
		_, err = r.Db(db.dbName).TableCreate(tableName, *options).Run(db.session)
	}

	if err != nil {
		casError := &FailedToCreateTableError
		casError.err = &err
		return casError
	}

	return nil
}
开发者ID:jostyee,项目名称:casgo,代码行数:33,代码来源:rethinkdb_adapter.go


示例3: main

func main() {
	// Connecting to the database
	addr := *rethinkdbHost + ":" + *rethinkdbPort
	log.Info("Connecting to RethinkDB at ", addr)
	sess, err := r.Connect(r.ConnectOpts{
		Address:  addr,
		Database: *env,
	})
	if err != nil {
		log.Fatal(err.Error())
	}
	defer sess.Close()

	_, err = r.Db(*env).TableCreate(tmpTable).RunWrite(sess)
	if err != nil {
		log.Fatal("Couldn't create temp table. ", err.Error())
	}
	log.Info("Created temp table ", *tmpTable, " in db ", *env)

	// init tmp table with accounts

	// process array of table names (i.e. emails, files, etc.)
	for _, t := range bigTables {
		processTable(sess, t)
	}

	_, err = r.Db(*env).TableDrop(*tmpTable).RunWrite(sess)
	if err != nil {
		log.Fatal("Couldn't drop temp table. ", err.Error())
	}
	log.Info("Dropped temp table ", *tmpTable, " in db ", *env)
}
开发者ID:tiare-lava,项目名称:worker-sizeup,代码行数:32,代码来源:main.go


示例4: Example_IndexCreate_compound

func Example_IndexCreate_compound() {
	sess, err := r.Connect(r.ConnectOpts{
		Address: url,
		AuthKey: authKey,
	})
	if err != nil {
		log.Fatalf("Error connecting to DB: %s", err)
	}

	// Setup database
	r.Db("test").TableDrop("table").Run(sess)
	r.Db("test").TableCreate("table").Run(sess)

	response, err := r.Db("test").Table("table").IndexCreateFunc("full_name", func(row r.Term) interface{} {
		return []interface{}{row.Field("first_name"), row.Field("last_name")}
	}).RunWrite(sess)
	if err != nil {
		log.Fatalf("Error creating index: %s", err)
	}

	fmt.Printf("%d index created", response.Created)

	// Output:
	// 1 index created
}
开发者ID:carriercomm,项目名称:lavabot,代码行数:25,代码来源:example_query_table_test.go


示例5: checkCleared

func (sr *Runner) checkCleared(check stalker.Check) {
	log.Debugln("check cleared")
	log.Infof("%s %s detected as cleared", check.Hostname, check.Check)
	query := map[string]string{"hostname": check.Hostname, "check": check.Check}
	cursor, err := r.Db(STALKERDB).Table("notifications").Filter(query).Run(sr.rsess)
	if err != nil {
		log.Errorln("Error checking for existing notification:", err.Error())
		return
	}
	defer cursor.Close()
	result := stalker.Notification{}
	cursor.One(&result)
	if result.Active == false {
		log.Infoln("No notification to clear")
		return
	}
	_, err = r.Db(STALKERDB).Table("notifications").Filter(query).Delete().RunWrite(sr.rsess)
	if err != nil {
		log.Errorln("Error deleting notification entry:", err.Error())
		return
	}
	sr.emitClear(check)
	return

}
开发者ID:pandemicsyn,项目名称:stalker,代码行数:25,代码来源:runner.go


示例6: processTable

func processTable(sess *r.Session, table string) {
	rows, err := r.Db(*env).Table(table).Run(sess)
	if err != nil {
		log.Fatal("Couldn't fetch rows for table ", table)
	}
	defer rows.Close()

	var doc map[string]interface{}
	var size uint64
	var id string
	var ok bool

	// WIP
	for rows.Next(&doc) {
		if size, ok = doc["size"].(uint64); !ok {
			if id, ok = doc["id"].(string); !ok {
				log.Warn("Found a document without ID! ", doc)
				continue
			}
			sizeTerm, err := r.Db(*env).Table(table).Get(id).
				CoerceTo("string").CoerceTo("binary").Count().Run(sess)
			err = sizeTerm.One(&size)
			if err != nil {
				log.Warn("Couldn't compute the size of document ", id, ". It might've been deleted.", err)
				continue
			}
		}
		fmt.Println(doc)
		return
	} else {

	}
}
开发者ID:tiare-lava,项目名称:worker-sizeup,代码行数:33,代码来源:main.go


示例7: init

func init() {
	var err error
	session, err = gorethink.Connect(gorethink.ConnectOpts{
		Address: "127.0.0.1:28015",
	})
	if err != nil {
		panic(err)
	}

	key2find = uniuri.New()

	// Create a new table
	gorethink.Db("test").TableDrop("benchmark_keys_list").Run(session)
	gorethink.Db("test").TableCreate("benchmark_keys_list").Run(session)

	var klist []*KeysList

	// Populate with sample data
	for n := 0; n < 300; n++ {
		keys := rndStringSlice(999)
		keys = randomlyInsert(keys, key2find)

		y := uniuri.New()
		if n == 153 {
			table2search = y
		}

		klist = append(klist, &KeysList{
			ID:    y,
			Voted: keys,
		})
	}

	gorethink.Db("test").Table("benchmark_keys_list").Insert(klist).Run(session)
}
开发者ID:carriercomm,项目名称:api-1,代码行数:35,代码来源:benchmark_test.go


示例8: main

func main() {
	log.SetFlags(log.LstdFlags | log.Lshortfile)

	flag.Parse()

	// Connect to RethinkDB
	var err error
	session, err = r.Connect(r.ConnectOpts{
		Address: *rethinkAddress,
	})
	if err != nil {
		log.Fatal(err)
	}

	// Create the database and tables
	r.DbCreate(*rethinkName).Exec(session)
	r.Db(*rethinkName).TableCreate("invites").Exec(session)
	r.Db(*rethinkName).Table("invites").IndexCreate("email").Exec(session)
	r.Db(*rethinkName).Table("invites").IndexCreate("name").Exec(session)

	// Add a CORS middleware
	goji.Use(cors.New(cors.Options{
		AllowCredentials: true,
	}).Handler)

	// Add routes to goji
	goji.Get("/", index)
	goji.Post("/check", check)
	goji.Post("/free", free)
	goji.Post("/create", create)

	// Start the server
	goji.Serve()
}
开发者ID:tiare-lava,项目名称:invite-api,代码行数:34,代码来源:main.go


示例9: main

func main() {
	flag.Parse()

	log = logrus.New()
	if *logFormatterType == "text" {
		log.Formatter = &logrus.TextFormatter{
			ForceColors: *logForceColors,
		}
	} else if *logFormatterType == "json" {
		log.Formatter = &logrus.JSONFormatter{}
	}
	log.Level = logrus.DebugLevel

	if *enableHub || *enableSender {
		var err error
		session, err = r.Connect(r.ConnectOpts{
			Address: *rethinkdbAddress,
		})
		if err != nil {
			log.WithField("error", err.Error()).Fatal("Unable to connect to RethinkDB")
		}

		r.DbCreate(*rethinkdbDatabase).Exec(session)
		r.Db(*rethinkdbDatabase).TableCreate("templates").Exec(session)
		r.Db(*rethinkdbDatabase).Table("templates").IndexCreate("name").Exec(session)
		r.Db(*rethinkdbDatabase).Table("templates").IndexCreate("version").Exec(session)
		r.Db(*rethinkdbDatabase).TableCreate("hub_state").Exec(session)
		r.Db(*rethinkdbDatabase).Table("hub_state").IndexCreate("time").Exec(session)
	}

	up := strings.Split(*usernames, ",")
	pp := strings.Split(*passwords, ",")

	if len(up) != len(pp) {
		log.Fatal("length of usernames and passwords is different")
	}

	if *enableSender {
		go initTemplates()

		for i, username := range up {
			go initSender(username, pp[i])
		}
	}

	if *enableHub {
		change := make(chan struct{})

		go initChurner(change)
		go initHub(change)
	}

	select {}
}
开发者ID:carriercomm,项目名称:lavabot,代码行数:54,代码来源:main.go


示例10: BenchmarkDelete

func BenchmarkDelete(b *testing.B) {
	for n := 0; n < b.N; n++ {
		_, err := gorethink.Db("test").Table("benchmark_keys_list").Get(table2search).Field("voted").DeleteAt(
			gorethink.Expr(gorethink.Db("test").Table("benchmark_keys_list").Get(table2search).Field("voted").IndexesOf(key2find).AtIndex(0)),
		).Run(session)
		if err != nil {
			b.Log(err)
			b.Fail()
		}
	}
}
开发者ID:carriercomm,项目名称:api-1,代码行数:11,代码来源:benchmark_test.go


示例11: InitTable

func InitTable(s *r.Session, databaseName string, tableName string) error {
	exists, err := ListContains(s, r.Db(databaseName).TableList(), tableName)
	if err != nil {
		return err
	}
	if !exists {
		_, err = r.Db(databaseName).TableCreate(tableName).RunWrite(s)
		if err != nil {
			return err
		}
	}
	return nil
}
开发者ID:pombredanne,项目名称:downloaderd-common,代码行数:13,代码来源:dbutils.go


示例12: main

func main() {
	rand.Seed(time.Now().UTC().UnixNano())

	var response []interface{}
	var session *r.Session

	session, err := r.Connect(map[string]interface{}{
		"address":     "localhost:28015",
		"database":    "test",
		"maxIdle":     10,
		"idleTimeout": time.Second * 10,
	})

	if err != nil {
		panic(err)
	}

	r.Db("test").TableCreate("test").Exec(session)

	objects := []interface{}{}

	for i := 3000; i < 3001; i++ {
		www := FetchURL("http://www.cnn.com")
		row := map[string]interface{}{"id": i, "g1": 6771, "www": www}
		objects = append(objects, row)
	}

	log.Println(objects)

	query := r.Db("test").Table("Table1").Insert(objects)

	_, err = query.Run(session)

	if err != nil {
		panic(err)
	}

	query = r.Db("test").Table("Table1").OrderBy("id")

	rows, err := query.Run(session)

	if err != nil {
		panic(err)
	}

	err = rows.ScanAll(&response)

	log.Println(response)
}
开发者ID:NovemberFoxtrot,项目名称:bytekeg,代码行数:49,代码来源:bytekeg.go


示例13: expireNotifications

// scan the notifications db for checks older than our expiration time and remove them. This will allow them be re-alerted on.
func (sm *Manager) expireNotifications() {
	log.Debugln("Expiring notifications")
	err := r.Db(STALKERDB).Table("notifications").Filter(r.Row.Field("ts").Lt(time.Now().Unix() - sm.notificationExpiration)).Delete().Exec(sm.rsess)
	if err != nil {
		log.Errorln("Error deleting expired notifications:", err.Error())
	}
}
开发者ID:pandemicsyn,项目名称:stalker,代码行数:8,代码来源:manager.go


示例14: createTable

func createTable(name string) error {
	ensureSession()
	// TODO return the object in a useable format instead of just the error
	// object, error
	_, err := r.Db(*db).TableCreate(name).Run(session)
	return err
}
开发者ID:ifo,项目名称:probablyvalidurl.com,代码行数:7,代码来源:database.go


示例15: InitDB

func InitDB() *rethink.Session {

	session, err := rethink.Connect(map[string]interface{}{
		"address":     "localhost:8080", //os.Getenv("RETHINKDB_URL"),
		"database":    "test",
		"maxIdle":     10,
		"idleTimeout": time.Second * 10,
	})

	if err != nil {
		log.Println(err)
	}

	err = rethink.DbCreate("test").Exec(session)
	if err != nil {
		log.Println(err)
	}

	_, err = rethink.Db("test").TableCreate("articles").RunWrite(session)
	if err != nil {
		log.Println(err)
	}

	return session
}
开发者ID:runemadsen,项目名称:api.runemadsen.com,代码行数:25,代码来源:database.go


示例16: FindUserByApiKeyAndSecret

// Find a user by API secret and key
func (db *RethinkDBAdapter) FindUserByApiKeyAndSecret(key, secret string) (*User, *CASServerError) {
	// Find the user
	cursor, err := r.
		Db(db.dbName).
		Table(db.apiKeysTableName).
		Get(key).
		Run(db.session)
	if err != nil {
		casErr := &FailedToFindUserByApiKeyAndSecretError
		casErr.err = &err
		return nil, casErr
	}

	// Get the user from the returned cursor
	var apiKeyPair *CasgoAPIKeyPair
	err = cursor.One(&apiKeyPair)
	if err != nil {
		casErr := &FailedToFindUserByApiKeyAndSecretError
		casErr.err = &err
		return nil, casErr
	}

	// Return error of the secret is invalid
	if apiKeyPair.Secret != secret {
		casErr := &FailedToFindUserByApiKeyAndSecretError
		return nil, casErr
	}

	return apiKeyPair.User, nil
}
开发者ID:jostyee,项目名称:casgo,代码行数:31,代码来源:rethinkdb_adapter.go


示例17: DeleteUser

func DeleteUser(user models.User) {
	_, err := r.Db("harbor").Table("users").Get(user.Id).Delete().Run(service.Session())
	if err != nil {
		fmt.Println(err)
		return
	}
}
开发者ID:jcarley,项目名称:harbor,代码行数:7,代码来源:authentication_test.go


示例18: addItem

func addItem(w http.ResponseWriter, q *http.Request) {
	//check if SKU exist, if not then generate SKU
	err := q.ParseMultipartForm(32 << 20)

	if err != nil {
		// Handle error
		fmt.Println(err)
	}
	if q.FormValue("SKU") != "" {

		slice := []string{"Image", "Image1", "Image2", "Image3"}

		images := checkifImageneedUpload(q, slice, q.FormValue("SKU"))

		product := Product{
			Title:       q.FormValue("Title"),
			Price:       q.FormValue("Price"),
			SKU:         q.FormValue("SKU"),
			Image:       images,
			Description: q.FormValue("Description"),
		}

		db := dbinit()
		defer db.Close()
		_, err = r.Db("goShop").Table("items").Insert(product).RunWrite(db)
		if err != nil {
			log.Println(err)
		}

		//fmt.Println(q.FormValue("cat"))

		http.Redirect(w, q, "/items", http.StatusFound)
	}

}
开发者ID:ivansyi,项目名称:goShop,代码行数:35,代码来源:app.go


示例19: CreateTable

// CreateTable creates a new table.
func CreateTable(tableName string) (bool, error) {

	if Session() == nil {
		return false, invalidSession()
	}

	results, err := r.Db(Db()).TableCreate(tableName).RunWrite(Session())
	if err != nil {
		return false, err
	}

	if results.Created == createdSuccessful {

		return true, nil
	}

	// *NOTE* Another way of getting results. For reference.
	//results, err := r.Db(dbName).TableCreate(tableName).Run(session)
	//if err != nil {
	//	return false, err
	//}

	//if results.Next() {
	//	var row TableResult
	//	results.Scan(&row)
	//	if row.Created == createdSuccssful {

	//		return true, nil
	//	}
	//}
	// -----------------------------------------------------------------

	return false, fmt.Errorf("Unable to create table `%s`.", tableName)
}
开发者ID:vFense,项目名称:warp,代码行数:35,代码来源:table_actions.go


示例20: BenchmarkAppend

func BenchmarkAppend(b *testing.B) {
	for n := 0; n < b.N; n++ {
		_, err := gorethink.Db("test").Table("benchmark_keys_list").Get(table2search).Field("voted").Append(uniuri.New()).Run(session)
		if err != nil {
			b.Log(err)
			b.Fail()
		}
	}
}
开发者ID:carriercomm,项目名称:api-1,代码行数:9,代码来源:benchmark_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang gorethink.Desc函数代码示例发布时间:2022-05-23
下一篇:
Golang gorethink.DBCreate函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap