This package is very opinionated. It aims to eliminate inline code SQL statemnts by requiring a virtual file system that will hold all the sql templates in memory during runtime.
This package wraps the database/sql
package.
This package is still under active development. It is wise to vendor this package because although not planned some breaking API changes may be introduced.
type FileStore interface {
Get(file string) (string, error)
}
The interface FileStore
is a required interface that must be implemented in order to instantiate a new DAL
because this is need when calling the query methods for the purpose of parsing the SQL template.
package main
func main() {
lgr := func(msg string) {
log.Println(msg)
}
dataStore, err := loadDataStore(envcfg.PgDbCreds(), envcfg.DbPingTime(), fileStore, lgr)
if err != nil {
log.Fatalln(err)
}
}
func loadDataStore(dbCreds string, dbPingTime int, fileStore vfs.Store, lgr finlog.Logger) (dal.DAL, error) {
pgdal, openErr := dal.Open("postgres", envcfg.PgDbCreds())
if openErr != nil {
return nil, openErr
}
lgrFunc := func(msg string) {
lgr.Info(msg)
}
pingErr := dal.PingDatabase(pgdal, dbPingTime, lgrFunc)
if pingErr != nil {
return nil, pingErr
}
return dal.New(pgdal, fileStore), nil
}