示例#1
0
文件: init.go 项目: ChunyuLabs/dbweb
func Init() error {
	cfg := config.NewConfigDefault()
	cfg.DataDir = "./metas"

	var err error
	// init nosql
	db, err := nodb.Open(cfg)
	if err != nil {
		return err
	}

	// select db
	Db, err = db.Select(0)
	if err != nil {
		return err
	}

	// add admin
	_, err = GetUserByName("admin")
	if err == ErrNotExist {
		err = AddUser(&User{
			Name:     "admin",
			Password: "******",
		})
	}

	return err
}
示例#2
0
文件: nodb.go 项目: weisd/gin-contrib
// Init initializes nodb session provider.
func (p *NodbProvider) Init(expire int64, configs string) error {
	p.expire = expire

	cfg := new(config.Config)
	cfg.DataDir = configs
	dbs, err := nodb.Open(cfg)
	if err != nil {
		return fmt.Errorf("session/nodb: error opening db: %v", err)
	}

	p.c, err = dbs.Select(0)
	return err
}
示例#3
0
文件: nodb.go 项目: kenno/cache
func (c *NodbCacher) new() (err error) {
	if c.db != nil {
		return ErrDBExists
	}

	cfg := new(config.Config)
	cfg.DataDir = c.filepath
	c.dbs, err = nodb.Open(cfg)
	if err != nil {
		return fmt.Errorf("cache/nodb: error opening db: %v", err)
	}

	c.db, err = c.dbs.Select(0)
	return err
}