Documentation
¶
Overview ¶
Actions is all helper functions that are called within the dialects
Index ¶
- Constants
- Variables
- func BulkDelete(db *sql.DB, model any, dialectType string) error
- func Create(db *sql.DB, model any, dialectType string) error
- func Delete(db *sql.DB, model any, dialectType string) error
- func Find(db *sql.DB, model any, dialectType string, args ...any) error
- func Update(db *sql.DB, model any, dialectType string) error
- func Where(db *sql.DB, model any, stmt string, limit int, dialectType string, args ...any) error
- type DBConfig
- type DialectHandler
- type MultiTenantDialectHandler
- type Mysql
- func (m *Mysql) BulkDelete(model any) error
- func (m *Mysql) Create(model any) error
- func (m *Mysql) Delete(model any) error
- func (m *Mysql) Find(model any, args ...any) error
- func (m *Mysql) GetConfig() DBConfig
- func (m *Mysql) QueryString() string
- func (m *Mysql) Raw(query string, args ...any) (*RawQuery, error)
- func (m *Mysql) SetConfig(config DBConfig)
- func (m *Mysql) SetDB(connDB *sql.DB)
- func (m *Mysql) Update(model any) error
- func (m *Mysql) Where(model any, stmt string, limit int, args ...any) error
- type Postgres
- func (pd *Postgres) BulkDelete(model any) error
- func (pd *Postgres) Create(model any) error
- func (pd *Postgres) Delete(model any) error
- func (pd *Postgres) Find(model any, args ...any) error
- func (pd *Postgres) GetConfig() DBConfig
- func (pd *Postgres) QueryString() string
- func (pd *Postgres) Raw(query string, args ...any) (*RawQuery, error)
- func (pd *Postgres) SetConfig(config DBConfig)
- func (pd *Postgres) SetDB(connDB *sql.DB)
- func (pd *Postgres) Update(model any) error
- func (pd *Postgres) Where(model any, stmt string, limit int, args ...any) error
- type RawQuery
- type SQLite
- func (s *SQLite) BulkDelete(model any) error
- func (s *SQLite) Create(model any) error
- func (s *SQLite) Delete(model any) error
- func (s *SQLite) Find(model any, args ...any) error
- func (s *SQLite) GetConfig() DBConfig
- func (s *SQLite) QueryString() string
- func (s *SQLite) Raw(query string, args ...any) (*RawQuery, error)
- func (s *SQLite) SetConfig(config DBConfig)
- func (s *SQLite) SetDB(connDB *sql.DB)
- func (s *SQLite) Update(model any) error
- func (s *SQLite) Where(model any, stmt string, limit int, args ...any) error
Constants ¶
const DIALECT_TYPE_MYSQL = "mysql"
const DIALECT_TYPE_PSQL = "psql"
const DIALECT_TYPE_SQLITE = "sqlite3"
Variables ¶
var Databases map[string]DialectHandler
Functions ¶
func BulkDelete ¶ added in v1.0.1
To delete results in bulk, pass in a slice. This will batch delete records for the given Model
func Delete ¶
No id is present within the model and no args are passed, the FIRST recored (using limit 1) from the given model will be deleted To delete records with values other than ID, you can insert a model without an ID, but with other fields present. i.e. to delete a user by name: Delete(&User{name: "carl"}) Without an ID field, but with name present, only "carl" will be deleted Multiple attributes will be treated as &'s
func Find ¶
Will accept arbitrary arguments, though only 1 is used, which should be the ID of the object to find. If an ID is not passed, ALL objects of the model will be returned If there is no id and the passed model is not a slice, the first row is returned for the given model If an ID IS passed, only a single object should ever be found. If an ID is passed, the the model is converted into a slice of model type
func Where ¶
Will return all rows found unless <= 1 rows are present in result of query Will accept a limit, limit of <= 0 will return all rows found matching the query Where is an all in 1 method with no chaining. Pass in the model, statement, desired limit (if there is one, else pass in <= 0), and any arguments to satiate the query
Types ¶
type DBConfig ¶
type DBConfig struct { Port int `yaml:"port,omitempty"` Host string `yaml:"host,omitempty"` Pool int `yaml:"pool,omitempty"` Connect bool `yaml:"connect,omitempty"` Password string `yaml:"password,omitempty"` User string `yaml:"user,omitempty"` Database string `yaml:"database,omitempty"` Path string `yaml:"path,omitempty"` Dialect string `yaml:"dialect"` Auth bool `yaml:"auth"` MaxIdleTime time.Duration `yaml:"maxIdleTime,omitempty"` MaxLifetime time.Duration `yaml:"maxLifetime,omitempty"` MaxIdleConn int `yaml:"maxIdleConn,omitempty"` MaxOpenConn int `yaml:"maxOpenConn,omitempty"` }
type DialectHandler ¶
type DialectHandler interface { Create(model any) error Update(model any) error Delete(model any) error BulkDelete(model any) error Where(model any, stmt string, limit int, args ...any) error Find(model any, args ...any) error Raw(query string, args ...any) (*RawQuery, error) SetDB(connDB *sql.DB) QueryString() string SetConfig(config DBConfig) GetConfig() DBConfig }
DialectHandler is the primary interface that all database types must comply too
type MultiTenantDialectHandler ¶
type MultiTenantDialectHandler struct {
Handlers map[string]DialectHandler
}
func (MultiTenantDialectHandler) Empty ¶
func (mtd MultiTenantDialectHandler) Empty() bool
Empty will determine if there are not database handlers present
func (*MultiTenantDialectHandler) Set ¶
func (mtd *MultiTenantDialectHandler) Set(key string, handler DialectHandler)
Append will add database handlers to the Handlers slice
func (MultiTenantDialectHandler) SwitchDB ¶
func (mtd MultiTenantDialectHandler) SwitchDB(database string) DialectHandler
Switch allows the caller to alter to different databases to perform executions again
type Mysql ¶
type Mysql struct {
// contains filtered or unexported fields
}
func (*Mysql) BulkDelete ¶ added in v1.0.1
func (*Mysql) QueryString ¶
type Postgres ¶
type Postgres struct {
// contains filtered or unexported fields
}
func (*Postgres) BulkDelete ¶ added in v1.0.1
func (*Postgres) QueryString ¶
type RawQuery ¶
type RawQuery struct {
// contains filtered or unexported fields
}
func Raw ¶
Raw builds a raw query, allowing for a user to either call Exec or All functions to perform execution
type SQLite ¶
type SQLite struct {
// contains filtered or unexported fields
}