db

package
v0.0.0-...-db93ecf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DatabaseMigrationURL

func DatabaseMigrationURL() (string, error)

DatabaseMigrationURL returns the DSN to connect to the database for schema migration using a conventional environment variable. If the schema migration DSN is not set, it will fallback to the regular database DSN.

func DatabaseTestURL

func DatabaseTestURL() (string, error)

DatabaseTestURL returns the DSN to connect to the test database using a conventional environment variable.

func DatabaseURL

func DatabaseURL() (string, error)

DatabaseURL returns the DSN to connect to the database using a conventional environment variable.

Types

type MySqlAdapter

type MySqlAdapter struct {
	// contains filtered or unexported fields
}

func (MySqlAdapter) Config

func (m MySqlAdapter) Config() *SqlAdapterConfig

func (MySqlAdapter) GetConn

func (m MySqlAdapter) GetConn() (*sql.DB, error)

func (MySqlAdapter) GetDB

func (m MySqlAdapter) GetDB() (*gorm.DB, error)

func (MySqlAdapter) Migrate

func (m MySqlAdapter) Migrate(tables ...interface{}) error

func (MySqlAdapter) Ping

func (m MySqlAdapter) Ping() error

func (MySqlAdapter) SetupConnectionPool

func (m MySqlAdapter) SetupConnectionPool() error

type MySqlAdapterConfig

type MySqlAdapterConfig struct {
	Host     string
	Port     int16
	Username string
	Password string
	Database string
}

type PostgreSqlAdapter

type PostgreSqlAdapter struct {
	// contains filtered or unexported fields
}

func (PostgreSqlAdapter) Config

func (m PostgreSqlAdapter) Config() *SqlAdapterConfig

func (PostgreSqlAdapter) GetConn

func (m PostgreSqlAdapter) GetConn() (*sql.DB, error)

func (PostgreSqlAdapter) GetDB

func (m PostgreSqlAdapter) GetDB() (*gorm.DB, error)

func (PostgreSqlAdapter) Migrate

func (m PostgreSqlAdapter) Migrate(tables ...interface{}) error

func (PostgreSqlAdapter) Ping

func (m PostgreSqlAdapter) Ping() error

func (PostgreSqlAdapter) SetupConnectionPool

func (m PostgreSqlAdapter) SetupConnectionPool() error

type PostgreSqlAdapterConfig

type PostgreSqlAdapterConfig struct {
	DSN string

	// A name to report as part of the tracer plugin
	TracingDBName string

	// Translate errors to gorms internal error types
	TranslateError bool

	EnableTracing bool
	EnableMetrics bool

	// This is an optional pointer to the SqlAdapterConfig struct.
	// If not supplied, we will use the defaultSqlAdapterConfig.
	SqlAdapterConfig *SqlAdapterConfig
}

GORM internally uses pgx as the default driver for PostgreSQL. The DSN format can be anything supported by pgx. For example: postgres://${user}:${password}@${host}/${db}?sslmode=verify-none

type SqlAdapterConfig

type SqlAdapterConfig struct {
	MaxIdleConnections int
	MaxOpenConnections int
}

func DefaultSqlAdapterConfig

func DefaultSqlAdapterConfig() SqlAdapterConfig

type SqlDataAdapter

type SqlDataAdapter interface {
	GetDB() (*gorm.DB, error)
	GetConn() (*sql.DB, error)
	Migrate(...interface{}) error
	Ping() error
}

SqlDataAdapter represents a contract for implementing RDBMS data adapters

func NewMySqlAdapter

func NewMySqlAdapter(config MySqlAdapterConfig) (SqlDataAdapter, error)

func NewPostgreSqlAdapter

func NewPostgreSqlAdapter(config PostgreSqlAdapterConfig) (SqlDataAdapter, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL