Documentation ¶
Index ¶
- Constants
- func Append(fmter Formatter, b []byte, v interface{}) []byte
- func AppendBoolValue(fmter Formatter, b []byte, v reflect.Value) []byte
- func AppendFloat32Value(fmter Formatter, b []byte, v reflect.Value) []byte
- func AppendFloat64Value(fmter Formatter, b []byte, v reflect.Value) []byte
- func AppendIntValue(fmter Formatter, b []byte, v reflect.Value) []byte
- func AppendJSONValue(fmter Formatter, b []byte, v reflect.Value) []byte
- func AppendQueryAppender(fmter Formatter, b []byte, app QueryAppender) []byte
- func AppendStringValue(fmter Formatter, b []byte, v reflect.Value) []byte
- func AppendUintValue(fmter Formatter, b []byte, v reflect.Value) []byte
- func DiscoverSQLType(typ reflect.Type) string
- func SetTableNameInflector(fn func(string) string)
- type AfterScanHook
- type AfterScanRowHook
- type AppenderFunc
- type BaseDialect
- func (BaseDialect) AppendBool(b []byte, v bool) []byte
- func (BaseDialect) AppendBytes(b, bs []byte) []byte
- func (BaseDialect) AppendJSON(b, jsonb []byte) []byte
- func (BaseDialect) AppendString(b []byte, s string) []byte
- func (BaseDialect) AppendTime(b []byte, tm time.Time) []byte
- func (BaseDialect) AppendUint32(b []byte, n uint32) []byte
- func (BaseDialect) AppendUint64(b []byte, n uint64) []byte
- type BaseModel
- type BeforeAppendModelHook
- type BeforeScanHook
- type BeforeScanRowHook
- type ColumnsAppender
- type CustomAppender
- type Dialect
- type Field
- func (f *Field) AppendValue(fmter Formatter, b []byte, strct reflect.Value) []byte
- func (f *Field) Clone() *Field
- func (f *Field) HasNilValue(v reflect.Value) bool
- func (f *Field) HasZeroValue(v reflect.Value) bool
- func (f *Field) ScanValue(strct reflect.Value, src interface{}) error
- func (f *Field) ScanWithCheck(fv reflect.Value, src interface{}) error
- func (f *Field) SkipUpdate() bool
- func (f *Field) String() string
- func (f *Field) Value(strct reflect.Value) reflect.Value
- type Formatter
- func (f Formatter) AppendIdent(b []byte, ident string) []byte
- func (f Formatter) AppendQuery(dst []byte, query string, args ...interface{}) []byte
- func (f Formatter) AppendValue(b []byte, v reflect.Value) []byte
- func (f Formatter) Dialect() Dialect
- func (f Formatter) FormatQuery(query string, args ...interface{}) string
- func (f Formatter) HasFeature(feature feature.Feature) bool
- func (f Formatter) IdentQuote() byte
- func (f Formatter) IsNop() bool
- func (f Formatter) WithArg(arg NamedArgAppender) Formatter
- func (f Formatter) WithNamedArg(name string, value interface{}) Formatter
- type Ident
- type IsZeroerFunc
- type Model
- type NamedArgAppender
- type NullTime
- type Query
- type QueryAppender
- type QueryWithArgs
- type QueryWithSep
- type Relation
- type Safe
- type ScannerFunc
- type Table
- func (t *Table) AppendNamedArg(fmter Formatter, b []byte, name string, strct reflect.Value) ([]byte, bool)
- func (t *Table) CheckPKs() error
- func (t *Table) Dialect() Dialect
- func (t *Table) Field(name string) (*Field, error)
- func (t *Table) HasAfterScanHook() bool
- func (t *Table) HasAfterScanRowHook() bool
- func (t *Table) HasBeforeAppendModelHook() bool
- func (t *Table) HasBeforeScanHook() bool
- func (t *Table) HasBeforeScanRowHook() bool
- func (t *Table) HasField(name string) bool
- func (t *Table) String() string
- type Tables
Constants ¶
View Source
const ( InvalidRelation = iota HasOneRelation BelongsToRelation HasManyRelation ManyToManyRelation )
Variables ¶
This section is empty.
Functions ¶
func AppendFloat32Value ¶
func AppendFloat64Value ¶
func AppendQueryAppender ¶
func AppendQueryAppender(fmter Formatter, b []byte, app QueryAppender) []byte
func DiscoverSQLType ¶
func SetTableNameInflector ¶
SetTableNameInflector overrides the default func that pluralizes model name to get table name, e.g. my_article becomes my_articles.
Types ¶
type AfterScanHook ¶
type AfterScanRowHook ¶
type AppenderFunc ¶
func FieldAppender ¶
func FieldAppender(dialect Dialect, field *Field) AppenderFunc
func PtrAppender ¶
func PtrAppender(fn AppenderFunc) AppenderFunc
type BaseDialect ¶
type BaseDialect struct{}
func (BaseDialect) AppendBool ¶
func (BaseDialect) AppendBool(b []byte, v bool) []byte
func (BaseDialect) AppendBytes ¶
func (BaseDialect) AppendBytes(b, bs []byte) []byte
func (BaseDialect) AppendJSON ¶
func (BaseDialect) AppendJSON(b, jsonb []byte) []byte
func (BaseDialect) AppendString ¶
func (BaseDialect) AppendString(b []byte, s string) []byte
func (BaseDialect) AppendTime ¶
func (BaseDialect) AppendTime(b []byte, tm time.Time) []byte
func (BaseDialect) AppendUint32 ¶
func (BaseDialect) AppendUint32(b []byte, n uint32) []byte
func (BaseDialect) AppendUint64 ¶
func (BaseDialect) AppendUint64(b []byte, n uint64) []byte
type BeforeAppendModelHook ¶
type BeforeScanHook ¶
type BeforeScanRowHook ¶
type ColumnsAppender ¶
type CustomAppender ¶
type CustomAppender func(typ reflect.Type) AppenderFunc
type Dialect ¶
type Dialect interface { Init(db *sql.DB) Name() dialect.Name Features() feature.Feature Tables() *Tables OnTable(table *Table) IdentQuote() byte AppendUint32(b []byte, n uint32) []byte AppendUint64(b []byte, n uint64) []byte AppendTime(b []byte, tm time.Time) []byte AppendString(b []byte, s string) []byte AppendBytes(b []byte, bs []byte) []byte AppendJSON(b, jsonb []byte) []byte AppendBool(b []byte, v bool) []byte // DefaultVarcharLen should be returned for dialects in which specifying VARCHAR length // is mandatory in queries that modify the schema (CREATE TABLE / ADD COLUMN, etc). // Dialects that do not have such requirement may return 0, which should be interpreted so by the caller. DefaultVarcharLen() int }
type Field ¶
type Field struct { StructField reflect.StructField IsPtr bool Tag tagparser.Tag IndirectType reflect.Type Index []int Name string // SQL name, .e.g. id SQLName Safe // escaped SQL name, e.g. "id" GoName string // struct field name, e.g. Id DiscoveredSQLType string UserSQLType string CreateTableSQLType string SQLDefault string OnDelete string OnUpdate string IsPK bool NotNull bool NullZero bool AutoIncrement bool Identity bool Append AppenderFunc Scan ScannerFunc IsZero IsZeroerFunc }
func (*Field) AppendValue ¶
func (*Field) ScanWithCheck ¶
func (*Field) SkipUpdate ¶
type Formatter ¶
type Formatter struct {
// contains filtered or unexported fields
}
func NewFormatter ¶
func NewNopFormatter ¶
func NewNopFormatter() Formatter
func (Formatter) AppendQuery ¶
func (Formatter) FormatQuery ¶
func (Formatter) IdentQuote ¶
func (Formatter) WithArg ¶
func (f Formatter) WithArg(arg NamedArgAppender) Formatter
func (Formatter) WithNamedArg ¶
type Ident ¶
type Ident string
Ident represents a SQL identifier, for example, table or column name.
type IsZeroerFunc ¶
type NamedArgAppender ¶
type NullTime ¶
NullTime is a time.Time wrapper that marshals zero time as JSON null and SQL NULL.
func (NullTime) AppendQuery ¶
func (NullTime) MarshalJSON ¶
func (*NullTime) UnmarshalJSON ¶
type Query ¶
type Query interface { QueryAppender Operation() string GetModel() Model GetTableName() string }
type QueryAppender ¶
func In ¶
func In(slice interface{}) QueryAppender
type QueryWithArgs ¶
type QueryWithArgs struct { Query string Args []interface{} }
func SafeQuery ¶
func SafeQuery(query string, args []interface{}) QueryWithArgs
func UnsafeIdent ¶
func UnsafeIdent(ident string) QueryWithArgs
func (QueryWithArgs) AppendQuery ¶
func (q QueryWithArgs) AppendQuery(fmter Formatter, b []byte) ([]byte, error)
func (QueryWithArgs) IsZero ¶
func (q QueryWithArgs) IsZero() bool
type QueryWithSep ¶
type QueryWithSep struct { QueryWithArgs Sep string }
func SafeQueryWithSep ¶
func SafeQueryWithSep(query string, args []interface{}, sep string) QueryWithSep
type Relation ¶
type ScannerFunc ¶
func FieldScanner ¶
func FieldScanner(dialect Dialect, field *Field) ScannerFunc
func PtrScanner ¶
func PtrScanner(fn ScannerFunc) ScannerFunc
func Scanner ¶
func Scanner(typ reflect.Type) ScannerFunc
type Table ¶
type Table struct { Type reflect.Type ZeroValue reflect.Value // reflect.Struct ZeroIface interface{} // struct pointer TypeName string ModelName string Name string SQLName Safe SQLNameForSelects Safe Alias string SQLAlias Safe Fields []*Field // PKs + DataFields PKs []*Field DataFields []*Field FieldMap map[string]*Field Relations map[string]*Relation Unique map[string][]*Field SoftDeleteField *Field UpdateSoftDeleteField func(fv reflect.Value, tm time.Time) error // contains filtered or unexported fields }
Table represents a SQL table created from Go struct.
func (*Table) AppendNamedArg ¶
func (*Table) HasAfterScanHook ¶
DEPRECATED. Use HasAfterScanRowHook.
func (*Table) HasAfterScanRowHook ¶
func (*Table) HasBeforeAppendModelHook ¶
func (*Table) HasBeforeScanHook ¶
DEPRECATED. Use HasBeforeScanRowHook.
func (*Table) HasBeforeScanRowHook ¶
Click to show internal directories.
Click to hide internal directories.