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


Golang gorethink.DBCreate函数代码示例

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


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


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