Documentation
¶
Index ¶
- func Begin(ctx context.Context, tag string) context.Context
- func Commit(ctx context.Context)
- func CreateDBTables(ctx context.Context, tag string, db *sqlx.DB) error
- func Ext(ctx context.Context, tag string) sqlx.Ext
- func GetDB(ctx context.Context, tag string) *sqlx.DB
- func GetDBMap(ctx context.Context) map[string]*sqlx.DB
- func LoggedRollback(ctx context.Context)
- func Middleware(m map[string]*sqlx.DB) func(http.Handler) http.Handler
- func NewDBForDSN(ctx context.Context, dsn string, defaultDSN string) (*sqlx.DB, error)
- func NewPostgresDBForDSN(ctx context.Context, dsn string) (*sqlx.DB, error)
- func NewSqlite3DBForPath(ctx context.Context, path string) (*sqlx.DB, error)
- func NewSqlite3DBInMemory(ctx context.Context) (*sqlx.DB, error)
- func RegisterSchema(tag string, table string, schema string)
- func WithDB(ctx context.Context, tag string, db *sqlx.DB) context.Context
- func WithDBMap(ctx context.Context, m map[string]*sqlx.DB) context.Context
- func WithTransaction(ctx context.Context, transaction Transaction) context.Context
- type ContextKey
- type Transaction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateDBTables ¶
CreateDBTables creates the Mint DB tables if they don't exist.
func LoggedRollback ¶
LoggedRollback logs a rollback a commit or another rollback didn't take place before this call. Used in general with defer right after calling `Begin`. ```
ctx = tx.Begin(ctx) defer tx.LoggedRollback(ctx)
```
func Middleware ¶
Middleware returns a middleware that injects the specified DB in requests.
func NewDBForDSN ¶
NewDBForDSN parses the provided DSN and returns the initialized DB for it. Supported DSN are: ```
sqlite3:///home/spolu/foo.db sqlite3://:memory: postgres://foo:password@localhost/mydb?sslmode=verify-full
``` If no DSN is specified, the default DSN is used instead.
func NewPostgresDBForDSN ¶
NewPostgresDBForDSN returns a new Postgres DB found at the DSN provided.
func NewSqlite3DBForPath ¶
NewSqlite3DBForPath returns a new sqlite3 DB stored at the provided path or defaulting to `~/.mint/mint-$env.dr`.
func NewSqlite3DBInMemory ¶
NewSqlite3DBInMemory returns a new in-memory sqlite3 DB.
func RegisterSchema ¶
RegisterSchema lets schemas register themselves.
func WithTransaction ¶
func WithTransaction( ctx context.Context, transaction Transaction, ) context.Context
WithTransaction stores the transaction in the provided context.
Types ¶
type ContextKey ¶
type ContextKey string
ContextKey is the type of the key used with context to carry the contextual db and transaction.
type Transaction ¶
Transaction stores the current mintDB transaction.
func GetTransaction ¶
func GetTransaction( ctx context.Context, ) Transaction
GetTransaction retrieves the current transaction form the context.