Documentation
¶
Index ¶
- Constants
- Variables
- func IsSafeWhereClause(s string) bool
- func ParseTags(tag string) (map[string]string, error)
- type Clause
- type ClauseType
- type Column
- type ColumnSplitter
- type DB
- type Executor
- type GenerateOptions
- type Generator
- type Mapper
- type OpenOptions
- type Parser
- type SET
- type SaveQuery
- type Saver
- type SerialMapper
- type Table
- type Tx
Constants ¶
View Source
const (
ClauseTypeWhere = "where"
)
Variables ¶
View Source
var ErrRecordNotFound = errors.New("record not found")
Error returned when record not found
Functions ¶
func IsSafeWhereClause ¶
Types ¶
type Clause ¶
type Clause interface {
Query() (string, error)
Args() []interface{}
Type() ClauseType
}
type ClauseType ¶
type ClauseType string
type Column ¶
type Column struct {
FieldName string `json:"field_name"`
FieldType string `json:"field_type"`
FieldIndex int `json:"field_index"`
GoFieldType string `json:"go_field_type"`
Nullable bool `json:"nullable"`
DefaultValue sql.NullString `json:"default_value"`
Key sql.NullString `json:"key"`
Extra sql.NullString `json:"extra"`
}
func (*Column) ParseExtra ¶
type ColumnSplitter ¶
type DB ¶
type DB interface {
Saver
Mapper
// Return *sql.DB instance
DB() *sql.DB
// Set db object
SetDB(db *sql.DB)
// Begin transaction and commit.
// If error returned from callback, transaction is rolled back.
// Internally call tx.BeginTx(context.Background(), nil)
Transaction(callback func(tx Tx) error) error
// Same as Transaction()
// Internally call tx.BeginTx(ctx, opts)
TransactionWithContext(ctx context.Context, opts *sql.TxOptions, callback func(tx Tx) error) error
// Call db.Close()
Close() error
}
func Open ¶
func Open(opts *OpenOptions) (DB, error)
type GenerateOptions ¶
type Generator ¶
type Generator interface {
Generate(opts *GenerateOptions) error
}
func NewGenerator ¶
type Mapper ¶
type Mapper interface {
// Read single row and map columns to destination.
// pointerOfStruct MUST BE a pointer of struct.
// It closes rows after mapping regardless error occurred.
// example:
// var user User
// err := m.Map(rows, &user)
Map(rows *sql.Rows, pointerOfStruct interface{}) error
// Read all rows and map columns for each destination.
// pointerOfSliceOfStruct MUST BE a pointer of slices of pointer of struct.
// It closes rows after mapping regardless error occurred.
// example:
// var users []*Users
// m.MapMany(rows, &users)
MapMany(rows *sql.Rows, pointerOfSliceOfStruct interface{}) error
}
type OpenOptions ¶
type Saver ¶
type Saver interface {
Insert(structPtr interface{}) (sql.Result, error)
QueryForInsert(structPtr interface{}) (*SaveQuery, error)
Update(table string, set map[string]interface{}, where Clause) (sql.Result, error)
QueryForUpdate(table string, set map[string]interface{}, where Clause) (*SaveQuery, error)
}
type SerialMapper ¶
type SerialMapper interface {
// Read joined rows and map columns for each destination serially.
// pointerOfStruct MUST BE a pointer of struct
// NOTE: It WON'T close rows automatically. Close rows manually.
// example:
// var user User
// var favorite UserFavorite
// err := m.Map(rows, &user, &favorite)
Map(rows *sql.Rows, pointersOfStruct ...interface{}) error
}
func NewSerialMapper ¶
func NewSerialMapper(s ColumnSplitter) SerialMapper
type Table ¶
func (*Table) HasNullField ¶
func (*Table) HasPrimaryKey ¶
func (*Table) HasTimeField ¶
func (*Table) PrimaryKeyFieldIndex ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.