Documentation
¶
Overview ¶
Package mogodb provides utilities for working with databases. Currently supports PostgreSQL with PostGIS.
Index ¶
- func CommitTx(ctx context.Context) error
- func InTx(ctx context.Context) bool
- func MigrateDownAll(conn *Conn, fs fs.FS, dir string) error
- func MigrateUpAll(conn *Conn, fs fs.FS, dir string) error
- func NewConnURL(p *ConnURLParams) string
- func RollbackTx(ctx context.Context) error
- func Tx(ctx context.Context) pgx.Tx
- func WithTx[T any](ctx context.Context, conn *Conn, fn func(ctx context.Context) (T, error)) (T, error)
- type Conn
- type ConnParams
- type ConnURLParams
- type ConnURLType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MigrateDownAll ¶
MigrateDownAll rolls back all applied migrations in the database using the embedded migration files.
func MigrateUpAll ¶
MigrateUpAll applies all pending migrations to the database using the embedded migration files.
func NewConnURL ¶
func NewConnURL(p *ConnURLParams) string
NewConnURL creates a connection URL from the parameters.
func RollbackTx ¶
RollbackTx rolls back the transaction stored in the context, if any.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn represents a connection to the mogodb.
func NewConn ¶
func NewConn(ctx context.Context, p *ConnParams) (*Conn, error)
NewConn creates a new database connection using the provided parameters.
func (*Conn) BeginTx ¶
BeginTx starts a new transaction and returns a new context containing the transaction.
func (*Conn) Handle ¶
Handle returns a *sql.DB instance for compatibility with database/sql package, acting as a connection handle.
type ConnParams ¶
ConnParams holds the parameters for connecting to the mogodb.
type ConnURLParams ¶
type ConnURLParams struct {
// Type of connection.
Type ConnURLType
// Host to connect to.
Host string
// Port to connect on.
Port string
// Username to connect with.
User string
// Password to connect with.
Password string
// DB name to connect to.
DB string
// IsSSL is true if connection is over SSL.
IsSSL bool
}
ConnURLParams represents the parameters of the connection URL.
type ConnURLType ¶
type ConnURLType string
ConnURLType represents the type of the connection URL.
const ( // ConnURLTypePostgres is for connecting to a PostgreSQL database. ConnURLTypePostgres ConnURLType = "postgres" )