Documentation ¶
Index ¶
- Constants
- Variables
- func CreateDictionaryTable(q Queryer) error
- func CreateModelFile(schema string, table string, path string) (*os.File, string, error)
- func GenerateDictionaryMapping(path string, q Queryer) error
- func MakeModel(db Queryer, dir string, schema string, table string, templatePath string, ...) error
- func ModelColumn(model IModel, field interface{}) string
- func ModelColumns(model IModel, field ...interface{}) (columns []string)
- func ModelDeleteQuery(model IModel, condition *Condition) (sql string, e porterr.IError)
- func ModelInsertQuery(model IModel, fields ...interface{}) (sql string, columns []string, e porterr.IError)
- func ModelUpdateQuery(model IModel, condition *Condition, fields ...interface{}) (sql string, params []interface{}, e porterr.IError)
- func ModelValues(model IModel, columns ...string) (values []interface{})
- 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 DictionaryModel
- type IMigrationFile
- type IModel
- type IModelCrud
- type ISoftModel
- type Insert
- func (i *Insert) AddReturning(returning ...string) *Insert
- func (i *Insert) AddValues(values []any) *Insert
- func (i *Insert) Columns(column ...string) *Insert
- func (i *Insert) Conflict() *conflict
- func (i *Insert) From(from string) *Insert
- func (i *Insert) GetAllValues() []any
- func (i *Insert) GetValues(start, end int) []any
- func (i *Insert) GetWith(name string) *QB
- func (i *Insert) Into(into string) *Insert
- func (i *Insert) ResetColumns() *Insert
- func (i *Insert) ResetFrom() *Insert
- func (i *Insert) ResetInto() *Insert
- func (i *Insert) ResetReturning() *Insert
- func (i *Insert) ResetValues() *Insert
- func (i *Insert) ResetWith() *Insert
- func (i *Insert) SQL() (query string, params []any)
- func (i *Insert) SetValues(index int, values []any) *Insert
- func (i *Insert) String() string
- func (i *Insert) With(name string, qb *QB) *Insert
- type Iterator
- type Logger
- type Migration
- type MigrationRegistry
- type ModelFiledTag
- type Options
- type PostgresConnectionConfig
- type QB
- func (f *QB) AddOrder(expression ...string) *QB
- func (f *QB) Columns(column ...string) *QB
- func (f *QB) Except(qb *QB) *QB
- func (f *QB) From(table ...string) *QB
- func (f *QB) GetArguments() []interface{}
- func (f *QB) GetWith(name string) *QB
- func (f *QB) GroupBy(fields ...string) *QB
- func (f *QB) Having() *Condition
- func (f *QB) Intersect(qb *QB) *QB
- func (f *QB) ModelColumns(model ...IModel) *QB
- func (f *QB) ModelFrom(model ...IModel) *QB
- func (f *QB) Relate(relation ...string) *QB
- func (f *QB) ResetColumns() *QB
- func (f *QB) ResetExcept() *QB
- func (f *QB) ResetFrom() *QB
- func (f *QB) ResetGroupBy() *QB
- func (f *QB) ResetIntersect() *QB
- func (f *QB) ResetOrder() *QB
- func (f *QB) ResetRelations() *QB
- func (f *QB) ResetUnion() *QB
- func (f *QB) ResetWith() *QB
- func (f *QB) SetPagination(limit int, offset int) *QB
- func (f *QB) String() string
- func (f *QB) Union(qb *QB) *QB
- func (f *QB) Where() *Condition
- func (f *QB) With(name string, qb *QB) *QB
- type Queryer
- type SqlStmt
- type SqlTx
- func (tx *SqlTx) Commit() error
- 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) Rollback() error
- func (tx *SqlTx) Stmt(stmt *SqlStmt) *SqlStmt
- type SystemColumns
- type Transaction
- type TransactionId
- type TransactionPool
Constants ¶
const ( ConditionOperatorAnd = "AND" ConditionOperatorOr = "OR" ConditionOperatorXor = "XOR" )
const ( // ConflictActionNothing On conflict action do nothing ConflictActionNothing = "NOTHING" // ConflictActionUpdate On conflict action do update nothing ConflictActionUpdate = "UPDATE" )
Variables ¶
var DefaultDictionaryTemplate string
var DefaultModelTemplate string
var DefaultSystemColumns = SystemColumns{Created: "created_at", Updated: "updated_at"}
var DefaultSystemColumnsSoft = SystemColumns{Created: "created_at", Updated: "updated_at", Deleted: "deleted_at"}
Functions ¶
func CreateModelFile ¶
Create file in os
func GenerateDictionaryMapping ¶
Create or update dictionary mapping
func MakeModel ¶
func MakeModel(db Queryer, dir string, schema string, table string, templatePath string, systemColumns SystemColumns) error
Create model
func ModelColumn ¶ added in v1.7.6
Model column in db
func ModelColumns ¶ added in v1.11.0
Model columns by fileds
func ModelDeleteQuery ¶ added in v1.7.8
Model delete query
func ModelInsertQuery ¶ added in v1.8.5
func ModelInsertQuery(model IModel, fields ...interface{}) (sql string, columns []string, e porterr.IError)
Model insert query
func ModelUpdateQuery ¶ added in v1.7.7
func ModelUpdateQuery(model IModel, condition *Condition, fields ...interface{}) (sql string, params []interface{}, e porterr.IError)
Model update query
func ModelValues ¶ added in v1.8.6
Model values by columns
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 IsByteArray bool // Do not need type pointer for []byte 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 DefaultTypeValue *string // Default value for type }
Column information
func (Column) GetModelFieldTag ¶ added in v1.11.1
func (c Column) GetModelFieldTag() (field ModelFiledTag)
GetModelFieldTag Prepare ModelFiledTag by Column
type Columns ¶
type Columns []Column
Array of columns
func GetTableColumns ¶
func GetTableColumns(dbo Queryer, schema string, table string, sysCols SystemColumns) (*Columns, error)
Get table columns from db
type Condition ¶ added in v1.2.7
type Condition struct {
// contains filtered or unexported fields
}
Condition type
func NewSqlCondition ¶ added in v1.1.0
Init Condition
func (*Condition) AddArgument ¶ added in v1.2.9
Add argument
func (*Condition) AddExpression ¶ added in v1.2.7
Add expression
func (*Condition) GetArguments ¶ added in v1.2.7
func (c *Condition) GetArguments() []interface{}
Get arguments
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 DictionaryModel ¶
type DictionaryModel struct { Id int `json:"id"` // Идентификатор значения справочника Type string `json:"type"` // Тип значения справочника Code string `json:"code"` // Код значения справочника Label *string `json:"label"` // Описание значения справочника CreatedAt time.Time `json:"createdAt"` // Время создания записи UpdatedAt *time.Time `json:"updatedAt"` // Время обновления записи DeletedAt *time.Time `json:"deletedAt"` // Время удаления записи }
func (*DictionaryModel) SearchDictionary ¶
func (m *DictionaryModel) SearchDictionary(q Queryer) (*[]DictionaryModel, []int, error)
Search by filer
func (*DictionaryModel) Values ¶
func (m *DictionaryModel) Values() (values []interface{})
Model values
type IMigrationFile ¶
Migration file interface
type IModel ¶ added in v1.6.0
type IModel interface { Table() string Columns() []string Values() []interface{} Load(q Queryer) porterr.IError Save(q Queryer) porterr.IError Delete(q Queryer) porterr.IError }
DB model interface
type IModelCrud ¶ added in v1.11.0
type IModelCrud interface { GetLoadQuery() string GetInsertQuery() string GetUpdateQuery() string GetDeleteQuery() string }
IModelCrud CRUD query interface
type ISoftModel ¶ added in v1.6.0
type ISoftModel interface { IModel SoftLoad(q Queryer) porterr.IError SoftDelete(q Queryer) porterr.IError SoftRecover(q Queryer) porterr.IError }
DB model interface
type Insert ¶ added in v1.11.3
type Insert struct {
// contains filtered or unexported fields
}
Insert query builder
func (*Insert) AddReturning ¶ added in v1.11.3
AddReturning Add returning expression
func (*Insert) Conflict ¶ added in v1.11.3
func (i *Insert) Conflict() *conflict
Conflict get conflict expression
func (*Insert) GetAllValues ¶ added in v1.11.3
GetAllValues get all values
func (*Insert) ResetColumns ¶ added in v1.11.3
Columns Set columns
func (*Insert) ResetReturning ¶ added in v1.11.3
ResetReturning Reset returning expressions
func (*Insert) ResetValues ¶ added in v1.11.3
ResetValues Reset all values
type Iterator ¶ added in v1.6.0
type Iterator struct {
// contains filtered or unexported fields
}
Iterator
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 ¶
Create migration file
func (*Migration) GetTemplate ¶
func (*Migration) InitMigration ¶
Init migration
type ModelFiledTag ¶ added in v1.11.0
type ModelFiledTag struct { // DB column name Column string `tag:"col"` // Foreign key definition ForeignKey string `tag:"frk"` // Has sequence IsSequence bool `tag:"seq"` // Is primary key IsPrimaryKey bool `tag:"prk"` // Is not null IsRequired bool `tag:"req"` // Is unique IsUnique bool `tag:"unq"` // Is created at column IsCreatedAt bool `tag:"cat"` // Is updated at column IsUpdatedAt bool `tag:"uat"` // Is deleted at column IsDeletedAt bool `tag:"dat"` // Is ingored column IsIgnored bool `tag:"ign"` }
ModelFiledTag All possible model field tag properties tag must have 3 symbol length
func ParseModelFiledTag ¶ added in v1.11.0
func ParseModelFiledTag(tag string) (field ModelFiledTag)
ParseModelFiledTag parse validation tag for rule and arguments Example db:"col~created_at;seq;sys;prk;frk~master.table(id,name);req;unq'"
func (ModelFiledTag) String ¶ added in v1.11.0
func (t ModelFiledTag) String() string
Prepare string tag
type Options ¶
type Options struct { Debug bool Logger Logger TransactionTTL time.Duration `yaml:"transactionTTL"` }
Database Object Options
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 QB ¶ added in v1.7.0
type QB struct { SubQuery bool // contains filtered or unexported fields }
Query Builder struct Not Thread safety
func (*QB) ModelColumns ¶ added in v1.7.0
Add column from model
func (*QB) SetPagination ¶ added in v1.7.0
Set pagination
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 ¶ added in v1.3.5
type Transaction ¶ added in v1.8.0
type Transaction struct { // Time to live in unix timestampt // 0 - no TTL for transaction TTL int // contains filtered or unexported fields }
Transaction params
type TransactionId ¶ added in v1.8.0
type TransactionId string
Transaction identifier
func GenTransactionId ¶ added in v1.8.0
func GenTransactionId() TransactionId
Generate transaction id
type TransactionPool ¶ added in v1.8.0
type TransactionPool struct {
// contains filtered or unexported fields
}
Transaction pool
func NewTransactionPool ¶ added in v1.8.2
func NewTransactionPool() *TransactionPool
Create Transaction pool
func (*TransactionPool) Count ¶ added in v1.8.2
func (p *TransactionPool) Count() int
Transaction count
func (*TransactionPool) Get ¶ added in v1.8.2
func (p *TransactionPool) Get(id TransactionId) *SqlTx
Get transaction if exists
func (*TransactionPool) Reset ¶ added in v1.8.2
func (p *TransactionPool) Reset() *TransactionPool
Reset pool
func (*TransactionPool) Set ¶ added in v1.8.2
func (p *TransactionPool) Set(id TransactionId, tx *SqlTx) *TransactionPool
Set transaction
func (*TransactionPool) UnSet ¶ added in v1.8.2
func (p *TransactionPool) UnSet(id TransactionId) *TransactionPool
Unset transaction