Documentation
¶
Index ¶
- Constants
- func CockroachURLFromEnv() string
- func HandleMigrationArgs(mig Migrate)
- func MustMigrateUp(mig Migrate)
- func MustOpenMigration(driverName, dsn, sourceURL string) *migrate.Migrate
- func MySQLURLFromEnv() string
- func OpenMigration(driverName, dsn, sourceURL string) (*migrate.Migrate, error)
- type Agent
- type Connector
- type DB
- func MustOpen(driverName, dsn string) *DB
- func MustOpenCockroachWithMigration(dsn, sourceURL string) (*DB, *migrate.Migrate)
- func MustOpenWithMigrations(driverName, dsn, sourceURL string) (*DB, *migrate.Migrate)
- func Open(driverName, dsn string) (*DB, error)
- func OpenCockroachWithMigration(dsn, sourceURL string) (*DB, *migrate.Migrate, error)
- func OpenWithMigrations(driverName, dsn, sourceURL string) (*DB, *migrate.Migrate, error)
- type Executor
- type Migrate
- type Operator
- type Pinger
- type Preparer
- type Querier
- type Transactor
Constants ¶
const (
// DefaultCockroachURL is the default url to a CockroachDB database.
DefaultCockroachURL = "tcp(127.0.0.1:26257)/defaultdb"
)
const (
// DefaultMySQLURL is the default url to a MYSQL database.
DefaultMySQLURL = "tcp(127.0.0.1:3306)/service"
)
Variables ¶
This section is empty.
Functions ¶
func CockroachURLFromEnv ¶
func CockroachURLFromEnv() string
CockroachURLFromEnv tries to retrieve the cockroach url from the environment.
func HandleMigrationArgs ¶
func HandleMigrationArgs(mig Migrate)
HandleMigrationArgs should be invoked to handle command line arguments for running migrations.
func MustMigrateUp ¶
func MustMigrateUp(mig Migrate)
MustMigrateUp will attempt to migrate your database up.
func MustOpenMigration ¶
MustOpenMigration will open a migration instance with and crashes if unsuccessful.
func MySQLURLFromEnv ¶
func MySQLURLFromEnv() string
MySQLURLFromEnv tries to retrieve the redis url from the environment.
Types ¶
type Agent ¶
type Agent interface {
Preparer
Transactor
Executor
Querier
}
Agent defines a common set of methods for interacting with the data in an SQL database.
type Connector ¶
type Connector interface {
Driver() driver.Driver
SetMaxIdleConns(n int)
SetMaxOpenConns(n int)
SetConnMaxLifetime(d time.Duration)
Conn(ctx context.Context) (*sql.Conn, error)
Stats() sql.DBStats
}
Connector defines a common set of methods for dealing with the connection to an SQL database.
type DB ¶
DB represents a wrapper for SQL DB providing extra methods.
func MustOpenCockroachWithMigration ¶
MustOpenCockroachWithMigration opens a cockroach database connection with an associated migration instance and craches if the connection cannot be obtained. This assumes you use a postgres driver like https://github.com/lib/pq to interact with your postgres database.
func MustOpenWithMigrations ¶
MustOpenWithMigrations opens a database connection with an associated migration instance and crashes if unsuccessful.
func OpenCockroachWithMigration ¶
OpenCockroachWithMigration opens a cockroach database connection with an associated migration instance. This assumes you use a postgres driver like https://github.com/lib/pq to interact with your postgres database.
func OpenWithMigrations ¶
OpenWithMigrations opens a database connection with an associated migration instance.
type Executor ¶
type Executor interface {
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
Exec(query string, args ...interface{}) (sql.Result, error)
}
Executor defines a common set of methods for executing stored procedures, statements or queries.
type Operator ¶
Operator defines a common set of methods for operating a connection with an SQL database.
type Preparer ¶
type Preparer interface {
PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
Prepare(query string) (*sql.Stmt, error)
}
Preparer defines a common set of methods for preparing statements in an SQL database.
type Querier ¶
type Querier interface {
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
Query(query string, args ...interface{}) (*sql.Rows, error)
QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
QueryRow(query string, args ...interface{}) *sql.Row
}
Querier defines a common set of methods for querying an SQL database.