func openPostgresql(constr string) (Database, error) {
	settings, err := postgresql.ParseURL(constr)
	if err != nil {
		return Database{nil}, err
	}

	d, err := db.Open(postgresql.Adapter, settings)
	if err != nil {
		return Database{nil}, err
	}

	return Database{d}, nil
}
Beispiel #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
}