Documentation
¶
Index ¶
- func MapRow(row SqlRows, pointerOfStruct any) error
- func MapRows(rows SqlRows, ptrOfSliceOfModelPtr any) error
- func ParseTags(tag string) (map[string]string, error)
- func ParseType(t string, nullable bool) (string, error)
- func Ptr[T any](t T) *T
- func QueryForBulkInsert[T Model](modelPtrs ...T) (q.Query, error)
- func QueryForInsert(modelPtr Model) (q.Query, *reflect.Value, error)
- func QueryForUpdateModel(updateStructPtr ModelUpdate, where q.Condition) (q.Query, error)
- func Transaction(db *sql.DB, ctx context.Context, opts *sql.TxOptions, ...) error
- func Where(str string, args ...any) q.Condition
- type Column
- type ColumnSplitter
- type DB
- type ErrRecordNotFound
- type Executor
- type Finder
- type GenerateOptions
- type Generator
- type Model
- type ModelUpdate
- type OpenFunc
- type OpenOptions
- type Parser
- type Saver
- type SerialMapper
- type SqlRows
- type StmtExecutor
- type Table
- type Tx
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MapRow ¶
MapRow reads data from single row and maps those columns into destination struct. pointerOfStruct MUST BE a pointer of struct. It closes rows after mapping regardless error occurred.
Example:
var user User err := exql.MapRow(rows, &user)
func MapRows ¶
MapRows reads all data from rows and maps those columns for each destination struct. pointerOfSliceOfStruct MUST BE a pointer of slice of pointer of struct. It closes rows after mapping regardless error occurred.
Example:
var users []*Users err := exql.MapRows(rows, &users)
func QueryForUpdateModel ¶
func Transaction ¶
Types ¶
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 ¶
func (*Column) UpdateField ¶
type ColumnSplitter ¶
ColumnSplitter is a function type for providing head column name for each destination struct in SerialMapper.
type DB ¶
type DB interface {
Saver
Finder
// DB returns *sql.DB object.
DB() *sql.DB
// SetDB sets *sql.DB object.
SetDB(db *sql.DB)
// Transaction begins a transaction and commits after the callback is called.
// If an error is returned from the callback, it is rolled back.
// Internally call tx.BeginTx(context.Background(), nil).
Transaction(callback func(tx Tx) error) error
// TransactionWithContext is same as Transaction().
// Internally call tx.BeginTx(ctx, opts).
TransactionWithContext(ctx context.Context, opts *sql.TxOptions, callback func(tx Tx) error) error
// Close calls db.Close().
Close() error
}
func Open ¶
func Open(opts *OpenOptions) (DB, error)
Open opens the connection to the database and makes exql.DB interface.
func OpenContext ¶
func OpenContext(ctx context.Context, opts *OpenOptions) (DB, error)
OpenContext opens the connection to the database and makes exql.DB interface. If something failed, it retries automatically until given retry strategies satisfied or aborts handshaking.
Example:
db, err := exql.Open(context.Background(), &exql.OpenOptions{
Url: "user:pass@tcp(127.0.0.1:3306)/database?charset=utf8mb4&parseTime=True&loc=Local",
MaxRetryCount: 3,
RetryInterval: 10, //sec
})
type ErrRecordNotFound ¶
type ErrRecordNotFound struct{}
Error returned when record not found
func (ErrRecordNotFound) Error ¶
func (e ErrRecordNotFound) Error() string
type Finder ¶
type Finder interface {
Find(q query.Query, destPtrOfStruct any) error
FindContext(ctx context.Context, q query.Query, destPtrOfStruct any) error
FindMany(q query.Query, destSlicePtrOfStruct any) error
FindManyContext(ctx context.Context, q query.Query, destSlicePtrOfStruct any) error
}
Finder is an interface to execute select query and map rows into the destination.
type GenerateOptions ¶
type Generator ¶
type Generator interface {
Generate(opts *GenerateOptions) error
}
func NewGenerator ¶
type ModelUpdate ¶
type ModelUpdate = iface.ModelUpdate
type OpenOptions ¶
type Saver ¶
type Saver interface {
Insert(structPtr Model) (sql.Result, error)
InsertContext(ctx context.Context, structPtr Model) (sql.Result, error)
Update(table string, set map[string]any, where q.Condition) (sql.Result, error)
UpdateModel(updaterStructPtr ModelUpdate, where q.Condition) (sql.Result, error)
UpdateContext(ctx context.Context, table string, set map[string]any, where q.Condition) (sql.Result, error)
UpdateModelContext(ctx context.Context, updaterStructPtr ModelUpdate, where q.Condition) (sql.Result, error)
Delete(table string, where q.Condition) (sql.Result, error)
DeleteContext(ctx context.Context, table string, where q.Condition) (sql.Result, error)
Exec(query q.Query) (sql.Result, error)
ExecContext(ctx context.Context, query q.Query) (sql.Result, error)
Query(query q.Query) (*sql.Rows, error)
QueryContext(ctx context.Context, query q.Query) (*sql.Rows, error)
QueryRow(query q.Query) (*sql.Row, error)
QueryRowContext(ctx context.Context, query q.Query) (*sql.Row, error)
}
type SerialMapper ¶
type SerialMapper interface {
// Map reads joined rows and maps columns for each destination serially.
// The second argument, pointerOfStruct, MUST BE a pointer of the struct.
//
// NOTE: DO NOT FORGET to close rows manually, as it WON'T do it automatically.
//
// Example:
//
// var user User
// var favorite UserFavorite
// defer rows.Close()
// err := m.Map(rows, &user, &favorite)
Map(rows SqlRows, pointersOfStruct ...any) error
}
SerialMapper is an interface for mapping a joined row into one or more destinations serially.
func NewSerialMapper ¶
func NewSerialMapper(s ColumnSplitter) SerialMapper
type StmtExecutor ¶
type StmtExecutor interface {
Executor
// Close calls all retained *sql.Stmt and clears the buffer.
// DON'T forget to call this on the manual use.
Close() error
}
StmtExecutor is the Executor that caches queries as *sql.Stmt. It uses the cached Stmt for the next execution if query is identical. They are held until Close() is called. This is useful for the case of executing the same query repeatedly in the for-loop. It may prevent errors caused by the db's connection pool.
Example:
stmtExecer := exql.NewStmtExecutor(tx.Tx()) defer stmtExecer.Close() stmtSaver := exql.NewSaver(stmtExecer)
func NewStmtExecutor ¶
func NewStmtExecutor(ex Executor) StmtExecutor
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
mocks
|
|
|
mock_iface
Package mock_iface is a generated GoMock package.
|
Package mock_iface is a generated GoMock package. |
|
mock_query
Package mock_query is a generated GoMock package.
|
Package mock_query is a generated GoMock package. |
|
This file is generated by exql.
|
This file is generated by exql. |
|
tool
|
|
|
modelgen
command
|
|
|
rdmegen
command
|