Пример #1
0
func init() {
	// os.Setenv("UPPERIO_DB_DEBUG", "1")
	if os.Getenv("TEST_HOST") != "" {
		testHost = os.Getenv("TEST_HOST")
	}

	var err error
	DB = &database{}

	DB.Session, err = bond.Open(`postgresql`, db.Settings{
		Host:     testHost,
		User:     "******",
		Database: "bond_test",
	})

	if err != nil {
		panic(err)
	}

	DB.Account = AccountStore{Store: DB.Store("accounts")}
	DB.User = UserStore{Store: DB.Store("users")}
	DB.Log = LogStore{Store: DB.Store("logs")}
}
Пример #2
0
//NewDB creates a db session
func NewDB(dbURL string) (*Database, error) {
	connURL, err := postgresql.ParseURL(dbURL)

	db := &Database{}
	db.Session, err = bond.Open(postgresql.Adapter, connURL)
	if err != nil {
		return nil, err
	}

	db.Sqlx = db.Session.Driver().(*sql.DB)

	db.User = UserStore{Store: db.Store(`users`)}
	db.App = AppStore{Store: db.Store(`apps`)}
	db.Release = ReleaseStore{Store: db.Store(`releases`)}
	db.Bundle = BundleStore{Store: db.Store(`bundle`)}

	if DB != nil {
		DB.Close()
	}

	DB = db

	return db, nil
}