Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyConnectionPool(db *gorm.DB, cfg ConnectionPoolConfig) error
- type Config
- type ConnectionPoolConfig
- type DB
- func ConnectionMysql(host string, port int, username string, password string, dbname string, ...) (db *DB, err error)
- func ConnectionPostgres(host string, port int, username, password, database string, sslMode string) (db *DB, err error)
- func ConnectionSQLite(FilePath string) (db *DB, err error)
- func CreateDB(c config.IConfig) (*DB, error)
- type IConfig
- type MysqlConfig
- type PostgresConfig
- type SQLiteConfig
- type Session
- type Source
- type Table
- func (t *Table) AutoMigrate(v ...any) error
- func (t *Table) Count(i *int64) error
- func (t *Table) Create(value any) error
- func (t *Table) CreateMapWithPk(mapValue map[string]any, keyName string) (any, error)
- func (t *Table) CreateMapWithUintPk(mapValue map[string]any, keyName string) (uint, error)
- func (t *Table) CreateWithPk(value any, keyName string, kind reflect.Kind) (any, error)
- func (t *Table) Delete(value any, conds ...any) error
- func (t *Table) Find(dest any, conds ...any) error
- func (t *Table) First(dest any, conds ...any) error
- func (t *Table) Joins(query string, args ...any) *Table
- func (t *Table) Limit(size int) *Table
- func (t *Table) NewTable() *Table
- func (t *Table) Offset(i int) *Table
- func (t *Table) Order(query any) *Table
- func (t *Table) Preload(query string, args ...any) *Table
- func (t *Table) Raw(sql string, args ...any) *Table
- func (t *Table) Save(entry any) error
- func (t *Table) Scan(dest any) error
- func (t *Table) Session(g *gorm.Session) *Session
- func (t *Table) UpdateColumn(column string, value any) error
- func (t *Table) Updates(values any) error
- func (t *Table) Where(query any, args ...any) *Table
Constants ¶
const ( MYSQL = "mysql" POSTGRES = "postgres" POSTGRESQL = "postgresql" SQLITE = "sqlite" )
const ConfigKey = "web.db"
Variables ¶
var NoConfigDBError = &noConfigDBError{}
Functions ¶
func ApplyConnectionPool ¶ added in v0.5.1
func ApplyConnectionPool(db *gorm.DB, cfg ConnectionPoolConfig) error
ApplyConnectionPool applies connection pool settings to the underlying sql.DB
Types ¶
type ConnectionPoolConfig ¶ added in v0.5.1
type ConnectionPoolConfig interface {
GetMaxOpenConns() int
GetMaxIdleConns() int
GetConnMaxLifetime() int
}
ConnectionPoolConfig defines the interface for database connection pool configuration
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func ConnectionMysql ¶ added in v0.1.4
func ConnectionPostgres ¶ added in v0.5.1
func ConnectionPostgres(host string, port int, username, password, database string, sslMode string) (db *DB, err error)
ConnectionPostgres creates a new PostgreSQL connection with given parameters
func ConnectionSQLite ¶ added in v0.1.4
type MysqlConfig ¶ added in v0.1.1
type MysqlConfig struct {
Dbname string
Database string
Charset string
Username string
User string
Password string
Host string
Port int
// Connection pool settings
MaxOpenConns int `mapstructure:"max_open_conns"`
MaxIdleConns int `mapstructure:"max_idle_conns"`
ConnMaxLifetime int `mapstructure:"conn_max_lifetime"` // in seconds
}
func (*MysqlConfig) Connection ¶ added in v0.1.3
func (mysqlConfig *MysqlConfig) Connection() (db *DB, err error)
func (*MysqlConfig) GetConnMaxLifetime ¶ added in v0.5.1
func (mysqlConfig *MysqlConfig) GetConnMaxLifetime() int
func (*MysqlConfig) GetMaxIdleConns ¶ added in v0.5.1
func (mysqlConfig *MysqlConfig) GetMaxIdleConns() int
func (*MysqlConfig) GetMaxOpenConns ¶ added in v0.5.1
func (mysqlConfig *MysqlConfig) GetMaxOpenConns() int
type PostgresConfig ¶ added in v0.5.1
type PostgresConfig struct {
Host string
Port int
Username string
User string
Password string
Database string
Dbname string
SSLMode string // disable, require, verify-ca, verify-full
// Connection pool settings
MaxOpenConns int `mapstructure:"max_open_conns"`
MaxIdleConns int `mapstructure:"max_idle_conns"`
ConnMaxLifetime int `mapstructure:"conn_max_lifetime"` // in seconds
}
PostgresConfig holds PostgreSQL connection configuration
func (*PostgresConfig) Connection ¶ added in v0.5.1
func (c *PostgresConfig) Connection() (db *DB, err error)
Connection creates a new PostgreSQL database connection
func (*PostgresConfig) GetConnMaxLifetime ¶ added in v0.5.1
func (c *PostgresConfig) GetConnMaxLifetime() int
GetConnMaxLifetime implements ConnectionPoolConfig
func (*PostgresConfig) GetMaxIdleConns ¶ added in v0.5.1
func (c *PostgresConfig) GetMaxIdleConns() int
GetMaxIdleConns implements ConnectionPoolConfig
func (*PostgresConfig) GetMaxOpenConns ¶ added in v0.5.1
func (c *PostgresConfig) GetMaxOpenConns() int
GetMaxOpenConns implements ConnectionPoolConfig
type SQLiteConfig ¶ added in v0.1.2
type SQLiteConfig struct {
FilePath string
// Connection pool settings
MaxOpenConns int `mapstructure:"max_open_conns"`
MaxIdleConns int `mapstructure:"max_idle_conns"`
ConnMaxLifetime int `mapstructure:"conn_max_lifetime"` // in seconds
}
func (*SQLiteConfig) Connection ¶ added in v0.1.3
func (sqliteConfig *SQLiteConfig) Connection() (db *DB, err error)
func (*SQLiteConfig) GetConnMaxLifetime ¶ added in v0.5.1
func (sqliteConfig *SQLiteConfig) GetConnMaxLifetime() int
func (*SQLiteConfig) GetMaxIdleConns ¶ added in v0.5.1
func (sqliteConfig *SQLiteConfig) GetMaxIdleConns() int
func (*SQLiteConfig) GetMaxOpenConns ¶ added in v0.5.1
func (sqliteConfig *SQLiteConfig) GetMaxOpenConns() int
type Table ¶ added in v0.1.3
type Table struct {
// contains filtered or unexported fields
}
func (*Table) AutoMigrate ¶ added in v0.1.3
func (*Table) CreateMapWithPk ¶ added in v0.1.4
CreateMapWithPk creates a record from a map and returns the generated primary key If keyName is empty, it will try common ID field names (ID, Id, id)
func (*Table) CreateMapWithUintPk ¶ added in v0.1.4
CreateMapWithUintPk creates a record from a map and returns the primary key as uint
func (*Table) CreateWithPk ¶ added in v0.1.4
CreateWithPk creates a record and returns the generated primary key If keyName is empty, it will try common ID field names (ID, Id, id) If kind is reflect.Invalid, it will try to determine the type automatically
func (*Table) Joins ¶ added in v0.5.1
Joins performs a join operation (GORM join support) Usage: db.Table("users").Joins("Profile").Find(&users)
func (*Table) Offset ¶ added in v0.1.3
func (t *Table) Set(column string, value any) *Table {
tx := t.db.Set(column, value)
return &Table{db: tx}
}
func (*Table) Preload ¶ added in v0.5.1
Preload preloads associations for the query (GORM foreign key support) Usage: db.Table("users").Preload("Profile").Preload("Role").Find(&users)
func (*Table) Raw ¶ added in v0.5.1
Raw executes a raw SQL query and returns a Table for further chaining (e.g., with Scan)