sql

package
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingConfig      = errors.New("missing config")
	ErrMissingDriver      = errors.New("missing driver")
	ErrDriverNotSupported = errors.New("driver not supported")
)

Functions

func CreateMigration

func CreateMigration(name string) error

Types

type Client

type Client struct {
	*gorm.DB
}

func New

func New(cfg *Config) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) Migrate

func (c *Client) Migrate() error

func (*Client) Rollback

func (c *Client) Rollback() error

type Config

type Config struct {
	Driver Driver `env:"DB_DRIVER" envDefault:"mysql"`
	Host   string `env:"DB_HOST" envDefault:"localhost"`
	Port   int    `env:"DB_PORT" envDefault:"3306"`
	User   string `env:"DB_USER" envDefault:"root"`
	Pass   string `env:"DB_PASS" envDefault:"password"`
	DBName string `env:"DB_NAME" envDefault:"shield"`

	MaxConnLifetime time.Duration `env:"DB_MAX_CONN_LIFETIME" envDefault:"1h"`
	MaxConnIdleTime time.Duration `env:"DB_MAX_CONN_IDLE_TIME" envDefault:"30m"`
	MaxIdleConns    int           `env:"DB_MAX_IDLE_CONNS" envDefault:"10"`
	MaxOpenConns    int           `env:"DB_MAX_OPEN_CONNS" envDefault:"100"`

	// MySQL
	Charset   string `env:"DB_MYSQL_CHARSET" envDefault:"utf8mb4"`
	ParseTime bool   `env:"DB_MYSQL_PARSE_TIME" envDefault:"True"`
	Location  string `env:"DB_MYSQL_LOCATION" envDefault:"Local"`

	// Postgres
	SSLMode  string `env:"DB_POSTGRES_SSL_MODE" envDefault:"disable"`
	TimeZone string `env:"DB_POSTGRES_TIME_ZONE" envDefault:"Europe/Madrid"`

	// CloudSQL
	UnixSocketPath string `env:"INSTANCE_UNIX_SOCKET"`
}

func GetConfigFromEnv

func GetConfigFromEnv() (*Config, error)

func (*Config) CloudSQLDSN

func (c *Config) CloudSQLDSN() string

func (*Config) MySQLDSN

func (c *Config) MySQLDSN() string

func (*Config) PostgresDSN

func (c *Config) PostgresDSN() string

type Driver

type Driver string
const (
	DriverMySQL    Driver = "mysql"
	DriverCloudSQL Driver = "cloudsql"
	DriverPostgres Driver = "postgres"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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