implements Stringer for store and remotes

This commit is contained in:
Brad Rydzewski
2015-10-27 16:48:05 -07:00
parent fc02d38b4a
commit 4a0deff5a5
7 changed files with 35 additions and 15 deletions

View File

@@ -16,19 +16,6 @@ import (
log "github.com/Sirupsen/logrus"
)
// From creates a datastore from an existing database connection.
func From(db *sql.DB) store.Store {
return store.New(
&nodestore{db},
&userstore{db},
&repostore{db},
&keystore{db},
&buildstore{db},
&jobstore{db},
&logstore{db},
)
}
// Load opens a new database connection with the specified driver
// and connection string specified in the environment variables.
func Load(env envconfig.Env) store.Store {
@@ -40,8 +27,20 @@ func Load(env envconfig.Env) store.Store {
log.Infof("using database driver %s", driver)
log.Infof("using database config %s", config)
return From(
Open(driver, config),
return New(driver, config)
}
func New(driver, config string) store.Store {
conn := Open(driver, config)
return store.New(
driver,
&nodestore{conn},
&userstore{conn},
&repostore{conn},
&keystore{conn},
&buildstore{conn},
&jobstore{conn},
&logstore{conn},
)
}

View File

@@ -11,6 +11,7 @@ type Store interface {
}
type store struct {
name string
nodes NodeStore
users UserStore
repos RepoStore
@@ -27,8 +28,10 @@ func (s *store) Keys() KeyStore { return s.keys }
func (s *store) Builds() BuildStore { return s.builds }
func (s *store) Jobs() JobStore { return s.jobs }
func (s *store) Logs() LogStore { return s.logs }
func (s *store) String() string { return s.name }
func New(
name string,
nodes NodeStore,
users UserStore,
repos RepoStore,
@@ -38,6 +41,7 @@ func New(
logs LogStore,
) Store {
return &store{
name,
nodes,
users,
repos,