Documentation ¶
Index ¶
- Constants
- Variables
- func ColumnString(dialect Dialect, col *schemas.Column, includePrimaryKey, supportCollation bool) (string, error)
- func FormatColumnTime(dialect Dialect, dbLocation *time.Location, col *schemas.Column, t time.Time) (interface{}, error)
- func FullTableName(dialect Dialect, mapper names.Mapper, bean interface{}, includeSchema ...bool) string
- func QueryDefaultPostgresSchema(ctx context.Context, queryer core.Queryer) (string, error)
- func RegisterDialect(dbName schemas.DBType, dialectFunc func() Dialect)
- func RegisterDriver(driverName string, driver Driver)
- func RegisteredDriverSize() int
- func TableNameNoSchema(dialect Dialect, mapper names.Mapper, tableName interface{}) string
- func TableNameWithSchema(dialect Dialect, tableName string) string
- type Base
- func (db *Base) AddColumnSQL(tableName string, col *schemas.Column) string
- func (db *Base) Alias(col string) string
- func (db *Base) CreateIndexSQL(tableName string, index *schemas.Index) string
- func (db *Base) CreateSequenceSQL(ctx context.Context, queryer core.Queryer, seqName string) (string, error)
- func (db *Base) CreateTableSQL(ctx context.Context, queryer core.Queryer, table *schemas.Table, ...) (string, bool, error)
- func (db *Base) DropIndexSQL(tableName string, index *schemas.Index) string
- func (db *Base) DropSequenceSQL(seqName string) (string, error)
- func (db *Base) DropTableSQL(tableName string) (string, bool)
- func (db *Base) HasRecords(queryer core.Queryer, ctx context.Context, query string, args ...interface{}) (bool, error)
- func (db *Base) Init(dialect Dialect, uri *URI) error
- func (db *Base) IsColumnExist(queryer core.Queryer, ctx context.Context, tableName, colName string) (bool, error)
- func (db *Base) IsSequenceExist(ctx context.Context, queryer core.Queryer, seqName string) (bool, error)
- func (db *Base) ModifyColumnSQL(tableName string, col *schemas.Column) string
- func (db *Base) Quoter() schemas.Quoter
- func (db *Base) SetParams(params map[string]string)
- func (db *Base) URI() *URI
- type Dialect
- type DialectFeatures
- type Driver
- type DriverFeatures
- type Filter
- type QuotePolicy
- type ScanContext
- type URI
Constants ¶
const ( IncrAutoincrMode = iota SequenceAutoincrMode )
enumerates all autoincr mode
Variables ¶
var (
// DefaultPostgresSchema default postgres schema
DefaultPostgresSchema = "public"
)
Functions ¶
func ColumnString ¶
func ColumnString(dialect Dialect, col *schemas.Column, includePrimaryKey, supportCollation bool) (string, error)
ColumnString generate column description string according dialect
func FormatColumnTime ¶
func FormatColumnTime(dialect Dialect, dbLocation *time.Location, col *schemas.Column, t time.Time) (interface{}, error)
FormatColumnTime format column time
func FullTableName ¶
func FullTableName(dialect Dialect, mapper names.Mapper, bean interface{}, includeSchema ...bool) string
FullTableName returns table name with quote and schema according parameter
func QueryDefaultPostgresSchema ¶
QueryDefaultPostgresSchema returns the default postgres schema
func RegisterDialect ¶
RegisterDialect register database dialect
func RegisterDriver ¶
RegisterDriver register a driver
func RegisteredDriverSize ¶
func RegisteredDriverSize() int
RegisteredDriverSize returned all drivers's length
func TableNameNoSchema ¶
TableNameNoSchema returns table name with given tableName
func TableNameWithSchema ¶
TableNameWithSchema will add schema prefix on table name if possible
Types ¶
type Base ¶
type Base struct {
// contains filtered or unexported fields
}
Base represents a basic dialect and all real dialects could embed this struct
func (*Base) AddColumnSQL ¶
AddColumnSQL returns a SQL to add a column
func (*Base) CreateIndexSQL ¶
CreateIndexSQL returns a SQL to create index
func (*Base) CreateSequenceSQL ¶
func (*Base) CreateTableSQL ¶
func (db *Base) CreateTableSQL(ctx context.Context, queryer core.Queryer, table *schemas.Table, tableName string) (string, bool, error)
CreateTableSQL implements Dialect
func (*Base) DropIndexSQL ¶
DropIndexSQL returns a SQL to drop index
func (*Base) DropTableSQL ¶
DropTableSQL returns drop table SQL
func (*Base) HasRecords ¶
func (db *Base) HasRecords(queryer core.Queryer, ctx context.Context, query string, args ...interface{}) (bool, error)
HasRecords returns true if the SQL has records returned
func (*Base) IsColumnExist ¶
func (db *Base) IsColumnExist(queryer core.Queryer, ctx context.Context, tableName, colName string) (bool, error)
IsColumnExist returns true if the column of the table exist
func (*Base) IsSequenceExist ¶
func (*Base) ModifyColumnSQL ¶
ModifyColumnSQL returns a SQL to modify SQL
type Dialect ¶
type Dialect interface { Init(*URI) error URI() *URI Version(ctx context.Context, queryer core.Queryer) (*schemas.Version, error) Features() *DialectFeatures SQLType(*schemas.Column) string Alias(string) string // return what a sql type's alias of ColumnTypeKind(string) int // database column type kind IsReserved(string) bool Quoter() schemas.Quoter SetQuotePolicy(quotePolicy QuotePolicy) AutoIncrStr() string GetIndexes(queryer core.Queryer, ctx context.Context, tableName string) (map[string]*schemas.Index, error) IndexCheckSQL(tableName, idxName string) (string, []interface{}) CreateIndexSQL(tableName string, index *schemas.Index) string DropIndexSQL(tableName string, index *schemas.Index) string GetTables(queryer core.Queryer, ctx context.Context) ([]*schemas.Table, error) IsTableExist(queryer core.Queryer, ctx context.Context, tableName string) (bool, error) CreateTableSQL(ctx context.Context, queryer core.Queryer, table *schemas.Table, tableName string) (string, bool, error) DropTableSQL(tableName string) (string, bool) CreateSequenceSQL(ctx context.Context, queryer core.Queryer, seqName string) (string, error) IsSequenceExist(ctx context.Context, queryer core.Queryer, seqName string) (bool, error) DropSequenceSQL(seqName string) (string, error) GetColumns(queryer core.Queryer, ctx context.Context, tableName string) ([]string, map[string]*schemas.Column, error) IsColumnExist(queryer core.Queryer, ctx context.Context, tableName string, colName string) (bool, error) AddColumnSQL(tableName string, col *schemas.Column) string ModifyColumnSQL(tableName string, col *schemas.Column) string Filters() []Filter SetParams(params map[string]string) }
Dialect represents a kind of database
func OpenDialect ¶
OpenDialect opens a dialect via driver name and connection string
func QueryDialect ¶
QueryDialect query if registered database dialect
type DialectFeatures ¶
type DialectFeatures struct {
AutoincrMode int // 0 autoincrement column, 1 sequence
}
DialectFeatures represents a dialect parameters
type Driver ¶
type Driver interface { Parse(string, string) (*URI, error) Features() *DriverFeatures GenScanResult(string) (interface{}, error) // according given column type generating a suitable scan interface Scan(*ScanContext, *core.Rows, []*sql.ColumnType, ...interface{}) error }
Driver represents a database driver
type DriverFeatures ¶
type DriverFeatures struct {
SupportReturnInsertedID bool
}
DriverFeatures represents driver feature
type QuotePolicy ¶
type QuotePolicy int
QuotePolicy describes quote handle policy
const ( QuotePolicyAlways QuotePolicy = iota QuotePolicyNone QuotePolicyReserved )
All QuotePolicies
type ScanContext ¶
ScanContext represents a context when Scan