Documentation ¶
Overview ¶
utils for working with dotsql structs
abstractions for working with postgres databases
Index ¶
- func ConnectToDb(driverName, url string, db *sql.DB) error
- func EnsureSeedData(db *sql.DB, schemaFilepath, dataFilepath string, tables ...string) (created []string, err error)
- func EnsureTables(db *sql.DB, schemaFilepath string, tables ...string) ([]string, error)
- func SetupConnection(driverName, connString string) (db *sql.DB, err error)
- type DataCommands
- type Execable
- type Queryable
- type Scannable
- type SchemaCommands
- type TestSuite
- type TestSuiteOpts
- type Transactable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConnectToDb ¶
Uniform Database connector
func EnsureSeedData ¶
func EnsureSeedData(db *sql.DB, schemaFilepath, dataFilepath string, tables ...string) (created []string, err error)
EnsureSeedData runs "EnsureTables", and then injects seed data for any newly-created tables
func EnsureTables ¶
EnsureTables checks for table existence, creating them from the schema file if not, returning a slice of table names that were created
Types ¶
type DataCommands ¶
type DataCommands struct {
// contains filtered or unexported fields
}
SchemaFile is an sql file that defines a database schema
func LoadDataCommands ¶
func LoadDataCommands(sqlFilePath string) (*DataCommands, error)
LoadDataCommands takes a filepath to a sql file with create & drop table commands and returns a DataCommands
func LoadDataString ¶
func LoadDataString(sql string) (*DataCommands, error)
func (*DataCommands) Commands ¶
func (d *DataCommands) Commands() []string
func (*DataCommands) DeleteAll ¶
func (d *DataCommands) DeleteAll(db Execable) error
DropAll executes the command named "drop-all" from the sql file this should be a command in the form: DROP TABLE IF EXISTS foo, bar, baz ...
type Queryable ¶
type Queryable interface { Query(query string, args ...interface{}) (*sql.Rows, error) QueryRow(query string, args ...interface{}) *sql.Row }
Querable unifies both *sql.DB & *sql.Tx for querying purposes
type Scannable ¶
type Scannable interface {
Scan(...interface{}) error
}
Scannable unifies both *sql.Row & *sql.Rows, functions can accept Scannable & work with both
type SchemaCommands ¶
type SchemaCommands struct {
// contains filtered or unexported fields
}
SchemaCommands is an sql file that defines a database schema
func LoadSchemaCommands ¶
func LoadSchemaCommands(sqlFilePath string) (*SchemaCommands, error)
LoadSchemaCommands takes a filepath to a sql file with create & drop table commands and returns a SchemaCommands
func LoadSchemaString ¶
func LoadSchemaString(sql string) (*SchemaCommands, error)
func (*SchemaCommands) Create ¶
func (s *SchemaCommands) Create(db Execable, tables ...string) ([]string, error)
Create tables if they don't already exist
func (*SchemaCommands) DropAll ¶
func (s *SchemaCommands) DropAll(db Execable) error
DropAll executes the command named "drop-all" from the sql file this should be a command in the form: DROP TABLE IF EXISTS foo, bar, baz ...
func (*SchemaCommands) DropAllCreate ¶
func (s *SchemaCommands) DropAllCreate(db Execable, tables ...string) error
type TestSuite ¶
type TestSuite struct { DB *sql.DB Schema *SchemaCommands Data *DataCommands Cascade []string }
func InitTestSuite ¶
func InitTestSuite(o *TestSuiteOpts) (*TestSuite, error)