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

Golang v2.DBCreate函数代码示例

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

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



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

示例1: NewManager

func NewManager(addr string, database string, authKey string, client *dockerclient.DockerClient, disableUsageInfo bool, authenticator auth.Authenticator) (Manager, error) {
	log.Debug("setting up rethinkdb session")
	session, err := r.Connect(r.ConnectOpts{
		Address:  addr,
		Database: database,
		AuthKey:  authKey,
	})
	if err != nil {
		return nil, err
	}
	log.Info("checking database")

	r.DBCreate(database).Run(session)
	m := &DefaultManager{
		database:         database,
		authKey:          authKey,
		session:          session,
		authenticator:    authenticator,
		store:            store,
		client:           client,
		storeKey:         storeKey,
		disableUsageInfo: disableUsageInfo,
	}
	m.initdb()
	m.init()
	return m, nil
}
开发者ID:XuesongYang,项目名称:shipyard,代码行数:27,代码来源:manager.go


示例2: SetupTest

func (suite *MutationUpdateSuite) SetupTest() {
	suite.T().Log("Setting up MutationUpdateSuite")
	// Use imports to prevent errors
	_ = time.Time{}
	_ = compare.AnythingIsFine

	session, err := r.Connect(r.ConnectOpts{
		Address: url,
	})
	suite.Require().NoError(err, "Error returned when connecting to server")
	suite.session = session

	r.DBDrop("test").Exec(suite.session)
	err = r.DBCreate("test").Exec(suite.session)
	suite.Require().NoError(err)
	err = r.DB("test").Wait().Exec(suite.session)
	suite.Require().NoError(err)

	r.DB("test").TableDrop("tbl").Exec(suite.session)
	err = r.DB("test").TableCreate("tbl").Exec(suite.session)
	suite.Require().NoError(err)
	err = r.DB("test").Table("tbl").Wait().Exec(suite.session)
	suite.Require().NoError(err)
	r.DB("test").TableDrop("tbl2").Exec(suite.session)
	err = r.DB("test").TableCreate("tbl2").Exec(suite.session)
	suite.Require().NoError(err)
	err = r.DB("test").Table("tbl2").Wait().Exec(suite.session)
	suite.Require().NoError(err)
}
开发者ID:freedmand,项目名称:doc.vu,代码行数:29,代码来源:reql_mutation_update_test.go


示例3: connectRDB

func connectRDB() {
	var err error
	var session *r.Session

	c, err := dockertest.ConnectToRethinkDB(20, time.Second, func(url string) bool {
		if session, err = r.Connect(r.ConnectOpts{Address: url, Database: "hydra"}); err != nil {
			return false
		} else if _, err = r.DBCreate("hydra").RunWrite(session); err != nil {
			log.Printf("Database exists: %s", err)
			return false
		} else if _, err = r.TableCreate("hydra_policies").RunWrite(session); err != nil {
			log.Printf("Could not create table: %s", err)
			return false
		}

		rethinkManager = &RethinkManager{
			Session:  session,
			Table:    r.Table("hydra_policies"),
			Policies: make(map[string]Policy),
		}

		rethinkManager.Watch(context.Background())
		time.Sleep(time.Second)
		return true
	})
	if err != nil {
		log.Fatalf("Could not connect to database: %s", err)
	}

	containers = append(containers, c)
	managers["rethink"] = rethinkManager
}
开发者ID:ory-am,项目名称:ladon,代码行数:32,代码来源:manager_test.go


示例4: createDbAndTables

func createDbAndTables() {

	//On creer la db Todolist si elle n'existe pas. (si elle existe deja, rien n'est fait)
	r.DBCreate("Todolist").Run(session)

	//On creer la table Todos si elle n'existe pas dans la db Todolist (si elle existe deja, rien n'est fait)
	r.DB("Todolist").TableCreate("Todos").Run(session)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:8,代码来源:main.go


示例5: createDBAndTables

func createDBAndTables() {
	r.DBCreate("SpottedWays").Run(Sess)
	r.DB("SpottedWays").TableCreate("users").Run(Sess)
	r.DB("SpottedWays").TableCreate("places").Run(Sess)
	r.DB("SpottedWays").TableCreate("posts").Run(Sess)
	r.DB("SpottedWays").TableCreate("likes").Run(Sess)
	r.DB("SpottedWays").TableCreate("talks").Run(Sess)
	r.DB("SpottedWays").TableCreate("matchs").Run(Sess)
	r.DB("SpottedWays").TableCreate("notifications").Run(Sess)
	r.DB("SpottedWays").TableCreate("history").Run(Sess)
	r.DB("SpottedWays").TableCreate("messages").Run(Sess)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:12,代码来源:api.go


示例6: TestCases

func (suite *MetaCompositeSuite) TestCases() {
	suite.T().Log("Running MetaCompositeSuite: Tests meta operations in composite queries")

	{
		// meta/composite.py.yaml line #4
		/* ({'dbs_created':3,'config_changes':arrlen(3)}) */
		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"dbs_created": 3, "config_changes": arrlen(3)}
		/* r.expr([1,2,3]).for_each(r.db_create('db_' + r.row.coerce_to('string'))) */

		suite.T().Log("About to run line #4: r.Expr([]interface{}{1, 2, 3}).ForEach(r.DBCreate(r.Add('db_', r.Row.CoerceTo('string'))))")

		runAndAssert(suite.Suite, expected_, r.Expr([]interface{}{1, 2, 3}).ForEach(r.DBCreate(r.Add("db_", r.Row.CoerceTo("string")))), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #4")
	}

	{
		// meta/composite.py.yaml line #8
		/* partial({'tables_created':9}) */
		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"tables_created": 9})
		/* r.db_list().set_difference(["rethinkdb", "test"]).for_each(lambda db_name:
		r.expr([1,2,3]).for_each(lambda i:
		r.db(db_name).table_create('tbl_' + i.coerce_to('string')))) */

		suite.T().Log("About to run line #8: r.DBList().SetDifference([]interface{}{'rethinkdb', 'test'}).ForEach(func(db_name r.Term) interface{} { return r.Expr([]interface{}{1, 2, 3}).ForEach(func(i r.Term) interface{} { return r.DB(db_name).TableCreate(r.Add('tbl_', i.CoerceTo('string')))})})")

		runAndAssert(suite.Suite, expected_, r.DBList().SetDifference([]interface{}{"rethinkdb", "test"}).ForEach(func(db_name r.Term) interface{} {
			return r.Expr([]interface{}{1, 2, 3}).ForEach(func(i r.Term) interface{} { return r.DB(db_name).TableCreate(r.Add("tbl_", i.CoerceTo("string"))) })
		}), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #8")
	}

	{
		// meta/composite.py.yaml line #13
		/* partial({'dbs_dropped':3,'tables_dropped':9}) */
		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"dbs_dropped": 3, "tables_dropped": 9})
		/* r.db_list().set_difference(["rethinkdb", "test"]).for_each(r.db_drop(r.row)) */

		suite.T().Log("About to run line #13: r.DBList().SetDifference([]interface{}{'rethinkdb', 'test'}).ForEach(r.DBDrop(r.Row))")

		runAndAssert(suite.Suite, expected_, r.DBList().SetDifference([]interface{}{"rethinkdb", "test"}).ForEach(r.DBDrop(r.Row)), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #13")
	}
}
开发者ID:freedmand,项目名称:doc.vu,代码行数:52,代码来源:reql_meta_composite_test.go


示例7: GetSession

func (c *RethinkDBConnection) GetSession() *r.Session {
	if c.session != nil {
		return c.session
	}

	var err error
	var username, password string
	database := c.URL.Path[1:]
	if c.URL.User != nil {
		password, _ = c.URL.User.Password()
		username = c.URL.User.Username()
	}

	if err := pkg.Retry(time.Second*15, time.Minute*2, func() error {
		logrus.Infof("Connecting with RethinkDB: %s (%s) (%s)", c.URL.String(), c.URL.Host, database)
		if c.session, err = r.Connect(r.ConnectOpts{
			Address:  c.URL.Host,
			Username: username,
			Password: password,
		}); err != nil {
			return errors.Errorf("Could not connect to RethinkDB: %s", err)
		}

		if _, err := r.DBList().Contains(database).Do(func(e r.Term) r.Term {
			return r.Branch(
				e,
				map[string]interface{}{"dbs_created": 0},
				r.DBCreate(database),
			)
		}).RunWrite(c.session); err != nil {
			return errors.Errorf("Could not create database: %s", err)
		}

		c.session.Use(database)
		logrus.Infof("Connected to RethinkDB!")
		return nil
	}); err != nil {
		logrus.Fatalf("Could not connect to RethinkDB: %s", err)
	}

	return c.session
}
开发者ID:jemacom,项目名称:hydra,代码行数:42,代码来源:backend_connections.go


示例8: TestMain

func TestMain(m *testing.M) {
	var session *r.Session
	var err error

	c, err := dockertest.ConnectToRethinkDB(20, time.Second, func(url string) bool {
		if session, err = r.Connect(r.ConnectOpts{Address: url, Database: "hydra"}); err != nil {
			return false
		} else if _, err = r.DBCreate("hydra").RunWrite(session); err != nil {
			log.Printf("Database exists: %s", err)
			return false
		} else if _, err = r.TableCreate("hydra_clients").RunWrite(session); err != nil {
			log.Printf("Could not create table: %s", err)
			return false
		}

		rethinkManager = &RethinkManager{
			Session: session,
			Table:   r.Table("hydra_clients"),
			Clients: make(map[string]*fosite.DefaultClient),
			Hasher: &hash.BCrypt{
				// Low workfactor reduces test time
				WorkFactor: 4,
			},
		}
		rethinkManager.Watch(context.Background())
		time.Sleep(100 * time.Millisecond)
		return true
	})
	if session != nil {
		defer session.Close()
	}
	if err != nil {
		log.Fatalf("Could not connect to database: %s", err)
	}
	clientManagers["rethink"] = rethinkManager

	retCode := m.Run()
	c.KillRemove()
	os.Exit(retCode)
}
开发者ID:jemacom,项目名称:hydra,代码行数:40,代码来源:manager_test.go


示例9: TestCases


//.........这里部分代码省略.........
		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"tables_dropped": 1})
		/* db.table_drop('b') */

		suite.T().Log("About to run line #306: db.TableDrop('b')")

		runAndAssert(suite.Suite, expected_, db.TableDrop("b"), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #306")
	}

	{
		// meta/table.yaml line #308
		/* partial({'tables_dropped':1}) */
		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"tables_dropped": 1})
		/* db.table_drop('c') */

		suite.T().Log("About to run line #308: db.TableDrop('c')")

		runAndAssert(suite.Suite, expected_, db.TableDrop("c"), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #308")
	}

	{
		// meta/table.yaml line #312
		/* partial({'dbs_created':1}) */
		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"dbs_created": 1})
		/* r.db_create("test2") */

		suite.T().Log("About to run line #312: r.DBCreate('test2')")

		runAndAssert(suite.Suite, expected_, r.DBCreate("test2"), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #312")
	}

	// meta/table.yaml line #315
	// db2 = r.db("test2")
	suite.T().Log("Possibly executing: var db2 r.Term = r.DB('test2')")

	db2 := r.DB("test2")
	_ = db2 // Prevent any noused variable errors

	{
		// meta/table.yaml line #317
		/* partial({'tables_created':1}) */
		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"tables_created": 1})
		/* db.table_create("testA") */

		suite.T().Log("About to run line #317: db.TableCreate('testA')")

		runAndAssert(suite.Suite, expected_, db.TableCreate("testA"), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #317")
	}

	{
		// meta/table.yaml line #319
开发者ID:freedmand,项目名称:doc.vu,代码行数:67,代码来源:reql_meta_table_test.go


示例10: TestCases

func (suite *MetaDbsSuite) TestCases() {
	suite.T().Log("Running MetaDbsSuite: Tests meta queries for databases")

	{
		// meta/dbs.yaml line #6
		/* bag(['rethinkdb', 'test']) */
		var expected_ compare.Expected = compare.UnorderedMatch([]interface{}{"rethinkdb", "test"})
		/* r.db_list() */

		suite.T().Log("About to run line #6: r.DBList()")

		runAndAssert(suite.Suite, expected_, r.DBList(), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #6")
	}

	{
		// meta/dbs.yaml line #11
		/* partial({'dbs_created':1}) */
		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"dbs_created": 1})
		/* r.db_create('a') */

		suite.T().Log("About to run line #11: r.DBCreate('a')")

		runAndAssert(suite.Suite, expected_, r.DBCreate("a"), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #11")
	}

	{
		// meta/dbs.yaml line #13
		/* partial({'dbs_created':1}) */
		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"dbs_created": 1})
		/* r.db_create('b') */

		suite.T().Log("About to run line #13: r.DBCreate('b')")

		runAndAssert(suite.Suite, expected_, r.DBCreate("b"), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #13")
	}

	{
		// meta/dbs.yaml line #18
		/* bag(['rethinkdb', 'a', 'b', 'test']) */
		var expected_ compare.Expected = compare.UnorderedMatch([]interface{}{"rethinkdb", "a", "b", "test"})
		/* r.db_list() */

		suite.T().Log("About to run line #18: r.DBList()")

		runAndAssert(suite.Suite, expected_, r.DBList(), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #18")
	}

	{
		// meta/dbs.yaml line #23
		/* {'name':'a','id':uuid()} */
		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"name": "a", "id": compare.IsUUID()}
		/* r.db('a').config() */

		suite.T().Log("About to run line #23: r.DB('a').Config()")

		runAndAssert(suite.Suite, expected_, r.DB("a").Config(), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #23")
	}

	{
		// meta/dbs.yaml line #28
		/* partial({'dbs_dropped':1}) */
		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"dbs_dropped": 1})
		/* r.db_drop('b') */

		suite.T().Log("About to run line #28: r.DBDrop('b')")

		runAndAssert(suite.Suite, expected_, r.DBDrop("b"), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #28")
	}

	{
		// meta/dbs.yaml line #31
		/* bag(['rethinkdb', 'a', 'test']) */
		var expected_ compare.Expected = compare.UnorderedMatch([]interface{}{"rethinkdb", "a", "test"})
		/* r.db_list() */

		suite.T().Log("About to run line #31: r.DBList()")
//.........这里部分代码省略.........
开发者ID:freedmand,项目名称:doc.vu,代码行数:101,代码来源:reql_meta_dbs_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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