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

Golang gorethink.DBCreate函数代码示例

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

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



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

示例1: initdb

func initdb() {
	// retries
	for i := 0; i < 5; i++ {
		s, err := rethink.Connect(rethink.ConnectOpts{
			Address:  dbAddr,
			Database: dbName,
		})
		if err != nil {
			log.Printf("unable to connect; retrying: %s", err)
			time.Sleep(2 * time.Second)
			continue
		}

		session = s
	}

	if session == nil {
		log.Fatalf("unable to get database connection")
	}

	// Create database
	rethink.DBCreate(dbName).Run(session)

	// Check if table exists
	_, err := rethink.Table(tblVisits).Run(session)
	if err != nil {
		// If not, create it
		if _, err = rethink.DB(dbName).TableCreate(tblVisits).Run(session); err != nil {
			log.Fatalf("error creating table: %s", err)
		}
	}
}
开发者ID:tombee,项目名称:docker-demo,代码行数:32,代码来源:main.go


示例2: init

func init() {

	Log = logrus.New()

	session, err := r.Connect(r.ConnectOpts{
		Address:  "172.17.8.150:32768",
		Database: "gettingstarted",
	})
	if err != nil {
		log.WithFields(log.Fields{
			"Error": err,
		}).Error("Error getting rethink")
	}

	// if err = r.DbCreate("gettingstarted").Run(session).Exec(); err != nil {
	resp, err := r.DBCreate("gettingstarted").RunWrite(session)
	if err != nil {
		log.WithFields(log.Fields{
			"Error": err,
		}).Error("Error creating db")
	}
	fmt.Printf("RESP: %+v\n", resp.DBsCreated)

	// if err = r.TableCreate("bookmarks").Run(session).Exec(); err != nil {
	resp, err = r.DB("gettingstarted").TableCreate("bookmarks").RunWrite(session)
	if err != nil {
		log.WithFields(log.Fields{
			"Error": err,
		}).Error("Error creating table")
	}
	fmt.Printf("RESP %+v\n", resp.TablesCreated)

}
开发者ID:TechnotronicOz,项目名称:darksky,代码行数:33,代码来源:darksky.go


示例3: NewManager

func NewManager(addr string, database string, authKey string, client *dockerclient.DockerClient, disableUsageInfo bool, authenticator auth.Authenticator) (Manager, error) {
	session, err := r.Connect(r.ConnectOpts{
		Address:  addr,
		Database: database,
		AuthKey:  authKey,
		MaxIdle:  10,
	})
	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:nfoonf,项目名称:shipyard,代码行数:27,代码来源:manager.go


示例4: Setup

func (d *Db) Setup() (*Db, error) {
	db := d.Name
	tables := []string{"hourly_state", "daily_summary", "hourly_summary"}

	rSession, err := r.Connect(r.ConnectOpts{
		Address:  d.Address,
		Database: db,
	})
	if err != nil {
		return nil, err
	}

	d.Session = rSession

	log.Printf("Setting up database..")
	_, err = r.DBCreate(db).Run(rSession)
	if err != nil {
		log.Printf("Database already exists. Skipping..")
	}
	for _, tbl := range tables {
		log.Printf("Creating table %v", tbl)
		_, err = r.DB(db).TableCreate(tbl).Run(rSession)
		if err != nil {
			log.Printf("Table %v already exists. Skipping..", tbl)
		}
	}

	return d, nil
}
开发者ID:vivangkumar,项目名称:statban,代码行数:29,代码来源:db.go


示例5: init

func init() {
	flag.Parse()
	err := gcfg.ReadFileInto(&cfg, *configFile)
	if err != nil {
		log.Fatal(err)
	}

	session, err = r.Connect(r.ConnectOpts{
		Address:  cfg.Database.Host + ":" + cfg.Database.Port, //localhost:28015
		Database: cfg.Database.DB,                             //DB: cats
	})
	if err != nil {
		log.Fatal("Could not connect")
	}
	res, err := r.DBCreate(cfg.Database.DB).RunWrite(session)
	if err != nil {
		log.Println(err.Error())
	}

	fmt.Printf("%d DB created\n", res.DBsCreated)
	r.DB(cfg.Database.DB).TableCreate("instacat").Run(session)
	log.Println("Create table instacat.")
	r.Table("instacat").IndexCreate("time").Run(session)
	log.Println("Create index time.")
	r.Table("instacat").IndexCreate("place", r.IndexCreateOpts{Geo: true}).Run(session)
	log.Println("Create index place.")
}
开发者ID:jimmyplaza,项目名称:RethinkDB-Instagram,代码行数:27,代码来源:main.go


示例6: Cp

// Cp copies all data from a database to another
func Cp(conn *r.Session, src, dest string, force bool) {
	fmt.Println("Copying db", src, "to", dest)
	exists := false
	for _, db := range Ls(conn) {
		if db == dest {
			exists = true
		}
	}
	if exists {
		fmt.Print("Destination db ", dest, " already exists")
		if force {
			fmt.Println(", overwriting")
		} else {
			fmt.Println()
			return
		}
	}
	if !exists {
		_, err := r.DBCreate(dest).Run(conn)
		if err != nil {
			fmt.Println("Couldn't create db", dest)
			panic(err)
		}
	}
	for _, v := range LsTables(conn, src) {
		CpTable(conn, src, v, dest, v, true)
	}
}
开发者ID:andreis,项目名称:rekit,代码行数:29,代码来源:cp.go


示例7: InitDBs

// InitDBs prepares a RethinkDB instance to be used by rethinkClient.
// rethinkClients will error if they are pointed at databases that haven't had
// InitDBs run on them
// InitDBs should only be run once per instance of RethinkDB, it will error if
// it's called a second time.
func InitDBs(address string, databaseName string) error {
	session, err := gorethink.Connect(gorethink.ConnectOpts{Address: address})
	if err != nil {
		return err
	}
	if _, err := gorethink.DBCreate(databaseName).RunWrite(session); err != nil {
		return err
	}
	for _, table := range tables {
		tableCreateOpts, ok := tableToTableCreateOpts[table]
		if ok {
			if _, err := gorethink.DB(databaseName).TableCreate(table, tableCreateOpts...).RunWrite(session); err != nil {
				return err
			}
		} else {
			if _, err := gorethink.DB(databaseName).TableCreate(table).RunWrite(session); err != nil {
				return err
			}
		}
	}
	for table, indexes := range tableToIndexes {
		for _, index := range indexes {
			if _, err := gorethink.DB(databaseName).Table(table).IndexCreate(index).RunWrite(session); err != nil {
				return err
			}
		}
	}
	return nil
}
开发者ID:sr,项目名称:pachyderm,代码行数:34,代码来源:rethink_client.go


示例8: CreateDatabase

// CreateDatabase creates a new RethinkDB database with then given name.
func (a *App) CreateDatabase(name string) error {
	resp, err := r.DBCreate(name).RunWrite(a.Session)
	if err != nil {
		return err
	}
	a.Logger.Printf("%d DBs created\n", resp.DBsCreated)
	return nil
}
开发者ID:bentranter,项目名称:devtbay,代码行数:9,代码来源:db.go


示例9: CreateDatabase

// CreateDatabase creates a new RethinkDB database with then given name.
func CreateDatabase(name string) error {
	resp, err := rdb.DBCreate(name).RunWrite(RDB)
	if err != nil {
		return err
	}
	log.Printf("%d DBs created\n", resp.DBsCreated)
	return nil
}
开发者ID:bentranter,项目名称:startupweekend2016,代码行数:9,代码来源:db.go


示例10: bootstrapDB

func bootstrapDB(session *r.Session, config Config) {
	r.DBCreate(config.DatabaseName).Run(session)
	r.DB(config.DatabaseName).TableCreate("Comment").Run(session)
	r.DB(config.DatabaseName).TableCreate("Posts").Run(session)
	r.DB(config.DatabaseName).TableCreate("Sessions").Run(session)
	r.DB(config.DatabaseName).TableCreate("Sites").Run(session)
	r.DB(config.DatabaseName).TableCreate("Template").Run(session)
	r.DB(config.DatabaseName).TableCreate("Users").Run(session)
}
开发者ID:jaydubbyasee,项目名称:seemus,代码行数:9,代码来源:database.go


示例11: createDB

func createDB(database string, conn *r.Session) (string, error) {
	var response interface{}
	res, _ := r.DBList().Contains(database).Run(conn)
	res.One(&response)
	if response == false {
		return fmt.Sprintf("New database %s created", database), r.DBCreate(database).Exec(conn)
	}
	return fmt.Sprintf("Database %s already exists", database), nil
}
开发者ID:yetis-br,项目名称:travelPlanning,代码行数:9,代码来源:db.go


示例12: main

func main() {

	config := a.NewConfig("config.gcfg")
	echo := echo.New()
	s := slack.New(config.Slack.Token)

	var session *r.Session

	session, err := r.Connect(r.ConnectOpts{
		Address:  fmt.Sprint(config.Database.URL, ":", config.Database.Port),
		Database: config.Database.Name,
		MaxIdle:  10,
		MaxOpen:  10,
	})
	if err != nil {
		log.Fatalln(err.Error())
	}
	session.SetMaxOpenConns(5)

	r.DBCreate(config.Database.Name).Exec(session)
	if err != nil {
		log.Println(err)
	}

	_, err = r.DB(config.Database.Name).TableCreate("quotes").RunWrite(session)
	if err != nil {
		fmt.Print(err)
	}
	_, err = r.DB(config.Database.Name).TableCreate("activities").RunWrite(session)
	if err != nil {
		fmt.Print(err)
	}

	// Middleware
	echo.Use(mw.Logger())
	echo.Use(mw.Recover())

	appcontext := &a.AppContext{
		Slack:  s,
		Config: config,
		Storage: &storage.Storage{
			Name:    "quotes",
			URL:     "192.168.10.10",
			Session: session,
		},
	}

	go appcontext.Monitor()

	//Routes
	a.Route(echo, appcontext)

	addr := fmt.Sprintf(":%d", config.App.Port)
	log.Printf("Starting server on: %s", addr)
	echo.Run(addr)
}
开发者ID:wvdeutekom,项目名称:GoQuotes,代码行数:56,代码来源:main.go


示例13: createDatabase

func createDatabase(dbName string) {
	_, err := r.Branch(
		r.DBList().Contains(dbName),
		nil,
		r.DBCreate(dbName),
	).Run(Session)
	if err != nil {
		panic(err)
	}
}
开发者ID:curly-garbanzo,项目名称:backend,代码行数:10,代码来源:main.go


示例14: createDb

func createDb(session *r.Session, dbName string) {
	err := r.DBCreate(dbName).Exec(session)
	if err != nil {
		fmt.Printf("%v", err)
		log.Fatalln(err)
		return
	}

	fmt.Printf("%v DB created.\n", dbName)
}
开发者ID:optionalg,项目名称:tutorials_as_code,代码行数:10,代码来源:rethinkdb-test.go


示例15: InitDatabase

func (c *Connection) InitDatabase() {
	r.DBCreate("magnet").Exec(c.session)
	r.TableCreate("users").Exec(c.session)
	r.TableCreate("bookmarks").Exec(c.session)
	_, err := r.DB("magnet").Table("bookmarks").IndexCreate("Created").RunWrite(c.session)
	if err != nil {
		log.Printf("Error creating index: %s", err)
	}
	r.TableCreate("sessions").Exec(c.session)
}
开发者ID:gauthierc,项目名称:magnet,代码行数:10,代码来源:data.go


示例16: InitDBs

// InitDBs prepares a RethinkDB instance to be used by the rethink server.
// Rethink servers will error if they are pointed at databases that haven't had InitDBs run on them.
// InitDBs is idempotent (unless rethink dies in the middle of the function)
func InitDBs(address string, databaseName string) error {
	session, err := gorethink.Connect(gorethink.ConnectOpts{Address: address})
	if err != nil {
		return err
	}
	if _, err := gorethink.DBCreate(databaseName).RunWrite(session); err != nil {
		if _, ok := err.(gorethink.RQLRuntimeError); ok {
			return nil
		}
		return err
	}
	for _, table := range tables {
		tableCreateOpts, ok := tableToTableCreateOpts[table]
		if ok {
			if _, err := gorethink.DB(databaseName).TableCreate(table, tableCreateOpts...).RunWrite(session); err != nil {
				return err
			}
		} else {
			if _, err := gorethink.DB(databaseName).TableCreate(table).RunWrite(session); err != nil {
				return err
			}
		}
	}
	for table, indexes := range tableToIndexes {
		for _, index := range indexes {
			if _, err := gorethink.DB(databaseName).Table(table).IndexCreate(index).RunWrite(session); err != nil {
				return err
			}
		}
	}
	if _, err := gorethink.DB(databaseName).Table(jobInfosTable).IndexCreateFunc(
		pipelineNameAndInputIndex,
		func(row gorethink.Term) interface{} {
			return []interface{}{
				row.Field("pipeline_name"),
				row.Field("input").Field("repo").Field("name"),
				row.Field("input").Field("id"),
			}
		}).RunWrite(session); err != nil {
		return err
	}
	if _, err := gorethink.DB(databaseName).Table(jobInfosTable).IndexCreateFunc(
		inputIndex,
		func(row gorethink.Term) interface{} {
			return []interface{}{
				row.Field("input").Field("repo").Field("name"),
				row.Field("input").Field("id"),
			}
		}).RunWrite(session); err != nil {
		return err
	}
	return nil
}
开发者ID:klucar,项目名称:pachyderm,代码行数:56,代码来源:rethink_api_server.go


示例17: setupDB

func setupDB(t *testing.T) (sess *r.Session, dbName string, err error) {

	dbName = fmt.Sprintf("db%d", int32(time.Now().Unix()))

	sess, err = r.Connect(r.ConnectOpts{
		Address:  "localhost:28015",
		Database: dbName,
	})
	if err != nil {
		return
	}

	_, err = r.DBCreate(dbName).Run(sess)
	if err != nil {
		t.Errorf("couldn't create table, err: %s ", err)
		return
	}
	r.DB(dbName).Wait().Run(sess)

	r.DB(dbName).TableCreate("test1", r.TableCreateOpts{PrimaryKey: "id"}).Exec(sess)
	r.DB(dbName).TableCreate("test2", r.TableCreateOpts{PrimaryKey: "id"}).Exec(sess)

	res, err := r.DB(dbName).TableList().Run(sess)
	if err != nil {
		t.Errorf("couldn't load table list, err: %s ", err)
		return
	}

	var tables []interface{}
	if err = res.All(&tables); err != nil {
		t.Errorf("couldn't load table list, err: %s ", err)
		return
	}

	if len(tables) != 2 {
		t.Errorf("table list off, %d    %v ", len(tables), tables)
		return
	}

	for idx, n := range names {

		var rec = struct {
			Name string
			Age  int
		}{Name: n, Age: 56 + idx}

		r.DB(dbName).Table("test1").Insert(rec).RunWrite(sess)
	}

	sess.Use(dbName)
	return
}
开发者ID:concur,项目名称:rethinkdb_exporter,代码行数:52,代码来源:rethinkdb_exporter_test.go


示例18: InitBookerDB

// InitBookerDB intis the primary DB
func InitBookerDB() {
	s, err := rdb.Connect(rdb.ConnectOpts{
		Address: "localhost:28015",
	})
	if err != nil {
		log.Println(err.Error())
	}
	defer s.Close()
	resp, err := rdb.DBCreate("Booker").RunWrite(s)
	if err != nil {
		log.Println(err.Error())
	}
	log.Printf("%d DBs created\n", resp.DBsCreated)
}
开发者ID:bentranter,项目名称:startupweekend2016,代码行数:15,代码来源:db.go


示例19: initDB

func (a *API) initDB() error {
	_, err := r.DB(a.dbName).Run(a.session)

	// create db
	if strings.Contains(err.Error(), "does not exist") {
		if _, err := r.DBCreate(a.dbName).RunWrite(a.session); err != nil {
			return err
		}

		log.Debugf("database created: name=%s", a.dbName)
	}

	return nil
}
开发者ID:faction-labs,项目名称:quorra,代码行数:14,代码来源:api.go


示例20: checkDatabase

func checkDatabase() {
	session := connect()
	defer killSession(session)

	databases, err := r.DBList().Run(session)
	var result string
	for databases.Next(&result) {
		if result == databaseName {
			return
		}
	}
	_, err = r.DBCreate(databaseName).Run(session)
	LogError(err)
}
开发者ID:ederoyd46,项目名称:osmimport-go,代码行数:14,代码来源:database.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang gorethink.Db函数代码示例发布时间:2022-05-23
下一篇:
Golang gorethink.DB函数代码示例发布时间: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