Documentation
¶
Index ¶
- Constants
- Variables
- func CreateModelFile(schema string, table string, path string) (*os.File, string, error)
- func MakeModel(db Queryer, path string, schema string, table string, templatePath string, ...) error
- func ModelColumn(model IModel, field interface{}) string
- func ModelUpdateQuery(model IModel, condition *Condition, fields ...interface{}) (sql string, params []interface{}, e goerr.IError)
- type Column
- type Columns
- type Condition
- func (c *Condition) AddArgument(values ...interface{}) *Condition
- func (c *Condition) AddExpression(expression string, values ...interface{}) *Condition
- func (c *Condition) GetArguments() []interface{}
- func (c *Condition) IsEmpty() bool
- func (c *Condition) Merge(operator string, conditions ...*Condition) *Condition
- func (c *Condition) String() string
- type Connection
- type ConnectionConfig
- type DBO
- func (dbo *DBO) Begin() (*SqlTx, error)
- func (dbo *DBO) Exec(query string, args ...interface{}) (sql.Result, error)
- func (dbo DBO) Init() (*DBO, error)
- func (dbo *DBO) Prepare(query string) (*SqlStmt, error)
- func (dbo *DBO) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (dbo *DBO) QueryRow(query string, args ...interface{}) *sql.Row
- type IMigrationFile
- type IModel
- type ISoftModel
- type Iterator
- type Logger
- type Migration
- type MigrationRegistry
- type Options
- type PostgresConnectionConfig
- type Query
- func (f *Query) AddOrder(expression ...string) *Query
- func (f *Query) Columns(column ...string) *Query
- func (f *Query) From(table ...string) *Query
- func (f *Query) GetArguments() []interface{}
- func (f *Query) GetWith(name string) *Query
- func (f *Query) GroupBy(fields ...string) *Query
- func (f *Query) Having() *Condition
- func (f *Query) ModelColumns(model ...IModel) *Query
- func (f *Query) ModelFrom(model ...IModel) *Query
- func (f *Query) Relate(relation ...string) *Query
- func (f *Query) ResetColumns() *Query
- func (f *Query) ResetFrom() *Query
- func (f *Query) ResetGroupBy() *Query
- func (f *Query) ResetOrder() *Query
- func (f *Query) ResetRelations() *Query
- func (f *Query) ResetWith() *Query
- func (f *Query) SetPagination(limit int, offset int) *Query
- func (f Query) String() string
- func (f *Query) Where() *Condition
- func (f *Query) With(name string, qb *Query) *Query
- type Queryer
- type SqlStmt
- type SqlTx
- func (tx *SqlTx) Exec(query string, args ...interface{}) (sql.Result, error)
- func (tx *SqlTx) Prepare(query string) (*SqlStmt, error)
- func (tx *SqlTx) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (tx *SqlTx) QueryRow(query string, args ...interface{}) *sql.Row
- func (tx *SqlTx) Stmt(stmt *SqlStmt) *SqlStmt
- type SystemColumns
Constants ¶
View Source
const ( ConditionOperatorAnd = "AND" ConditionOperatorOr = "OR" ConditionOperatorXor = "XOR" )
Variables ¶
View Source
var DefaultSystemColumns = SystemColumns{Created: "created_at", Updated: "updated_at"}
View Source
var DefaultSystemColumnsSoft = SystemColumns{Created: "created_at", Updated: "updated_at", Deleted: "deleted_at"}
Functions ¶
func CreateModelFile ¶
Types ¶
type Column ¶
type Column struct {
Name string // DB column name
ModelName string // Model name
Default *string // DB default value
IsNullable bool // DB is nullable
DataType string // DB column type
ModelType string // Model type
Schema string // DB Schema
Table string // DB table
Sequence *string // DB sequence
ForeignSchema *string // DB foreign schema name
ForeignTable *string // DB foreign table name
ForeignColumnName *string // DB foreign column name
ForeignIsSoft bool // DB foreign table is soft
Description *string // DB column description
IsPrimaryKey bool // DB is primary key
Tags string // Model Tags name
Import string // Model Import custom lib
IsArray bool // Array column
IsCreated bool // Is created at column
IsUpdated bool // Is updated at column
IsDeleted bool // Is deleted at column
HasUniqueIndex bool // If column is a part of unique index
UniqueIndexName *string // Unique index name
}
Column information
type Columns ¶
type Columns []Column
func GetTableColumns ¶
func GetTableColumns(dbo Queryer, schema string, table string, sysCols SystemColumns) (*Columns, error)
Get table columns from db
func (Columns) GetImports ¶
type Condition ¶
type Condition struct {
// contains filtered or unexported fields
}
Condition type
func (*Condition) AddArgument ¶
Add argument
func (*Condition) AddExpression ¶
Add expression
type Connection ¶
type Connection interface {
String() string
GetDbType() string
GetMaxConnection() int
GetConnMaxLifetime() int
GetMaxIdleConns() int
}
Database Object Connection Interface
type ConnectionConfig ¶
type ConnectionConfig struct {
Host string
Port int
Name string
User string
Password string
MaxConnections int `yaml:"maxConnections"`
MaxIdleConnections int `yaml:"maxIdleConnections"`
ConnectionIdleLifetime int `yaml:"connectionIdleLifetime"`
}
Client connection config
func (*ConnectionConfig) GetConnMaxLifetime ¶
func (cc *ConnectionConfig) GetConnMaxLifetime() int
Connection idle lifetime
func (*ConnectionConfig) GetMaxConnection ¶
func (cc *ConnectionConfig) GetMaxConnection() int
Get Max Connection
func (*ConnectionConfig) GetMaxIdleConns ¶
func (cc *ConnectionConfig) GetMaxIdleConns() int
Connection max idle connections
type DBO ¶
type DBO struct {
*sql.DB
Options
Connection Connection
}
Main Database Object
type IMigrationFile ¶
Migration file interface
type IModel ¶
type IModel interface {
Table() string
Columns() []string
Values() []interface{}
Load(q Queryer) goerr.IError
Save(q Queryer) goerr.IError
Delete(q Queryer) goerr.IError
}
DB model interface
type ISoftModel ¶
type ISoftModel interface {
IModel
SoftLoad(q Queryer) goerr.IError
SoftDelete(q Queryer) goerr.IError
SoftRecover(q Queryer) goerr.IError
}
DB model interface
type Logger ¶
type Logger interface {
Print(v ...interface{})
Println(v ...interface{})
Printf(format string, v ...interface{})
}
Logger
type Migration ¶
type Migration struct {
MigrationPath string
DBO *DBO
Config ConnectionConfig
Registry MigrationRegistry
RegistryPath string
RegistryXPath string
}
Migration struct
func (*Migration) CreateMigrationFile ¶
func (*Migration) GetTemplate ¶
func (*Migration) InitMigration ¶
type PostgresConnectionConfig ¶
type PostgresConnectionConfig struct {
ConnectionConfig `yaml:",inline"`
SSLMode string `yaml:"sslMode"`
BinaryParameters bool `yaml:"binaryParameters"`
}
Postgres connection config
func (*PostgresConnectionConfig) GetDbType ¶
func (pcc *PostgresConnectionConfig) GetDbType() string
Get database type
func (*PostgresConnectionConfig) String ¶
func (pcc *PostgresConnectionConfig) String() string
To string
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
func (*Query) GetArguments ¶
func (f *Query) GetArguments() []interface{}
func (*Query) ModelColumns ¶
func (*Query) ResetColumns ¶
func (*Query) ResetGroupBy ¶
func (*Query) ResetOrder ¶
func (*Query) ResetRelations ¶
type Queryer ¶
type Queryer interface {
Exec(query string, args ...interface{}) (sql.Result, error)
Prepare(query string) (*SqlStmt, error)
Query(query string, args ...interface{}) (*sql.Rows, error)
QueryRow(query string, args ...interface{}) *sql.Row
}
Queryer interface
type SqlTx ¶
Transaction
type SystemColumns ¶
Click to show internal directories.
Click to hide internal directories.