Documentation ¶
Overview ¶
Package dal is an opinionated package that wraps the functions of go's standard database/sql package. The versions of sql.Query, sql.QueryRow, et al. all are left untouched so that the interfaces are a superset of the standard ones.
The key opinionated approaches used by this libraray is the implementation of an interface: type FileStore interface { Get(sqlTemplate string) (string, error) } that MUST return the string of a SQL template. The other opinionated approach is that the parameters passed on the the Query, QueryRow functions be of: map[string]interface{} versus: interface{} This makes the execution a bit faster than other libraries.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PingDatabase ¶
PingDatabase is a helper function to ping the database with backoff to ensure a connection can be established before we proceed with a database setup whilst logging each ping and returns an error if it fails using the given function to log.
Types ¶
type DAL ¶
type DAL interface { Exec(sqlFile string, params map[string]interface{}) (sql.Result, error) Query(sqlFile string, params map[string]interface{}) (*sql.Rows, error) QueryRow(sqlFile string, params map[string]interface{}) (*sql.Row, error) }
DAL (database access layer) is the type returned when initializing an new instance of this package. The functions listed are the functions that can be used for this package.
func New ¶
New returns a DAL using the given DB and FileStore.
Example ¶
db, openErr := sql.Open("postgres", "dbname=dbdal_test sslmode=disable") if openErr != nil { log.Fatalln(openErr) } // vfs: github.com/magicalbanana/vfs fileStore, fsErr := vfs.LoadFiles("tests") if fsErr != nil { log.Fatalln(fsErr) } New(db, fileStore)
Output:
type DB ¶
type DB interface { Prepare(query string) (*sql.Stmt, error) Exec(query string, args ...interface{}) (sql.Result, error) Query(query string, args ...interface{}) (*sql.Rows, error) QueryRow(query string, args ...interface{}) *sql.Row Ping() error }
DB is an interface modeled after the go's standard database/sql package.