Documentation
¶
Overview ¶
Package database provides persistent data storage using a postgres or sqlite3 database.
Index ¶
- Constants
- Variables
- func Connect(ctx context.Context, driver string, datasource string) (*sqlx.DB, error)
- func ConnectAndMigrate(ctx context.Context, driver string, datasource string, migrators ...Migrator) (*sqlx.DB, error)
- func ConnectGorm(ctx context.Context, driver string, datasource string, ...) (*gorm.DB, error)
- func EncodeToJSONString(v any) string
- func GormLimit(size int) int
- func GormOffset(page, size int) int
- func Limit(size int) uint64
- func Must(db *sqlx.DB, err error) *sqlx.DB
- func Offset(page, size int) uint64
- func ProcessGormSQLErrorf(ctx context.Context, err error, format string, args ...interface{}) error
- func ProcessSQLErrorf(ctx context.Context, err error, format string, args ...interface{}) error
- type Config
- type GormConfigLogger
- type GormConfigOption
- type Migrator
Constants ¶
View Source
const (
// sqlForUpdate is the sql statement used for locking rows returned by select queries.
SQLForUpdate = "FOR UPDATE"
)
Variables ¶
View Source
var Builder = squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar)
Builder is a global instance of the sql builder. we are able to hardcode to postgres since sqlite3 is compatible with postgres.
Functions ¶
func ConnectAndMigrate ¶
func ConnectAndMigrate( ctx context.Context, driver string, datasource string, migrators ...Migrator, ) (*sqlx.DB, error)
ConnectAndMigrate creates the database handle and migrates the database.
func ConnectGorm ¶
func EncodeToJSONString ¶
func GormOffset ¶
func Must ¶
Must is a helper function that wraps a call to Connect and panics if the error is non-nil.
func ProcessGormSQLErrorf ¶
Types ¶
type Config ¶
type Config struct {
Driver string
Datasource string
Host string
Port int
Username string
Password string
DBName string
Options string
}
Config specifies the config for the database package.
type GormConfigLogger ¶
func (GormConfigLogger) Apply ¶
func (opt GormConfigLogger) Apply(c *gorm.Config)
type GormConfigOption ¶
Click to show internal directories.
Click to hide internal directories.