Documentation
¶
Overview ¶
Example (BulkOperation) ¶
package main import ( "database/sql" "fmt" "log" "os" "strings" "github.com/kamichidu/goen" _ "github.com/kamichidu/goen/dialect/sqlite3" _ "github.com/mattn/go-sqlite3" ) func main() { db, err := sql.Open("sqlite3", "./sqlite.db") if err != nil { panic(err) } defer db.Close() ddl := []string{ `drop table if exists testing`, `create table testing (id integer primary key, name varchar(256))`, } if _, err := db.Exec(strings.Join(ddl, ";")); err != nil { panic(err) } dbc := goen.NewDBContext("sqlite3", db) // set patch compiler, it compiles patches to bulk dbc.Compiler = goen.BulkCompiler for i := 0; i < 3; i++ { dbc.Patch(goen.InsertPatch( "testing", []string{"name"}, []interface{}{fmt.Sprintf("name-%d", i)}, )) } dbc.DebugMode(true) dbc.Logger = log.New(os.Stdout, "", 0) if err := dbc.SaveChanges(); err != nil { panic(err) } }
Output: goen: "INSERT INTO testing (name) VALUES (?),(?),(?)" with [name-0 name-1 name-2]
Example (CachingPreparedStatements) ¶
package main import ( "database/sql" "fmt" "strings" "github.com/kamichidu/goen" _ "github.com/kamichidu/goen/dialect/sqlite3" _ "github.com/mattn/go-sqlite3" ) func main() { db, err := sql.Open("sqlite3", "./sqlite.db") if err != nil { panic(err) } defer db.Close() ddl := []string{ `drop table if exists testing`, `create table testing (id integer primary key, name varchar(256))`, } if _, err := db.Exec(strings.Join(ddl, ";")); err != nil { panic(err) } // goen.StmtCacher caches *sql.Stmt until closed. preparedQueryRunner := goen.NewStmtCacher(db) defer preparedQueryRunner.Close() dbc := goen.NewDBContext("sqlite3", db) // set preparedQueryRunner to dbc.QueryRunner. dbc.QueryRunner = preparedQueryRunner fmt.Printf("cached statements %v\n", preparedQueryRunner.StmtStats().CachedStmts) err = goen.TxScope(dbc.DB.Begin())(func(tx *sql.Tx) error { // txc also use preparedQueryRunner when dbc uses it. txc := dbc.UseTx(tx) txc.Patch(&goen.Patch{ Kind: goen.PatchInsert, TableName: "testing", Columns: []string{"name"}, Values: []interface{}{"kamichidu"}, }) return txc.SaveChanges() }) if err != nil { panic(err) } fmt.Printf("cached statements %v\n", preparedQueryRunner.StmtStats().CachedStmts) var count int if err := dbc.QueryRow(`select count(*) from testing`).Scan(&count); err != nil { panic(err) } fmt.Printf("%v records found\n", count) fmt.Printf("cached statements %v\n", preparedQueryRunner.StmtStats().CachedStmts) }
Output: cached statements 0 cached statements 1 1 records found cached statements 2
Example (QueryCount) ¶
package main import ( "database/sql" "fmt" "strings" "github.com/kamichidu/goen" _ "github.com/kamichidu/goen/dialect/sqlite3" _ "github.com/mattn/go-sqlite3" ) func main() { db, err := sql.Open("sqlite3", "./sqlite.db") if err != nil { panic(err) } defer db.Close() ddl := []string{ `drop table if exists testing`, `create table testing (id integer primary key, name varchar(256))`, } if _, err := db.Exec(strings.Join(ddl, ";")); err != nil { panic(err) } dbc := goen.NewDBContext("sqlite3", db) for i := 0; i < 3; i++ { dbc.Patch(goen.InsertPatch( "testing", []string{"name"}, []interface{}{fmt.Sprintf("name-%d", i)}, )) } if err := dbc.SaveChanges(); err != nil { panic(err) } row := dbc.QueryRow(`select count(*) from testing`) var count int64 if err := row.Scan(&count); err != nil { panic(err) } fmt.Printf("dbc founds %d records\n", count) var records []map[string]interface{} rows, err := dbc.Query(`select id, name from testing`) if err != nil { panic(err) } defer rows.Close() if err := dbc.Scan(rows, &records); err != nil { panic(err) } fmt.Print("records:\n") for _, record := range records { fmt.Printf("id=%d name=%q\n", record["id"], record["name"]) } }
Output: dbc founds 3 records records: id=1 name="name-0" id=2 name="name-1" id=3 name="name-2"
Example (Transaction) ¶
package main import ( "database/sql" "fmt" "strings" "github.com/kamichidu/goen" _ "github.com/kamichidu/goen/dialect/sqlite3" _ "github.com/mattn/go-sqlite3" ) func main() { db, err := sql.Open("sqlite3", "./sqlite.db") if err != nil { panic(err) } defer db.Close() ddl := []string{ `drop table if exists testing`, `create table testing (id integer primary key, name varchar(256))`, } if _, err := db.Exec(strings.Join(ddl, ";")); err != nil { panic(err) } dbc := goen.NewDBContext("sqlite3", db) tx, err := dbc.DB.Begin() if err != nil { panic(err) } txc := dbc.UseTx(tx) if txc.Tx != tx { panic("UseTx makes clones DBContext and set Tx with given value") } txc.Patch(&goen.Patch{ Kind: goen.PatchInsert, TableName: "testing", Columns: []string{"name"}, Values: []interface{}{"kamichidu"}, }) if err := txc.SaveChanges(); err != nil { panic(err) } func() { rows, err := dbc.Query(`select * from testing`) if err != nil { panic(err) } defer rows.Close() var records []map[string]interface{} if err := dbc.Scan(rows, &records); err != nil { panic(err) } fmt.Printf("dbc founds %d records when not committed yet\n", len(records)) }() func() { rows, err := txc.Query(`select * from testing`) if err != nil { panic(err) } defer rows.Close() var records []map[string]interface{} if err := txc.Scan(rows, &records); err != nil { panic(err) } fmt.Printf("txc founds %d records when not committed yet since it's same transaction\n", len(records)) }() if err := tx.Commit(); err != nil { panic(err) } func() { rows, err := dbc.Query(`select * from testing`) if err != nil { panic(err) } defer rows.Close() var records []map[string]interface{} if err := dbc.Scan(rows, &records); err != nil { panic(err) } fmt.Printf("dbc founds %d records after committed\n", len(records)) }() func() { _, err := txc.Query(`select * from testing`) if err == sql.ErrTxDone { fmt.Print("txc returns an error sql.ErrTxDone after committed\n") } }() }
Output: dbc founds 0 records when not committed yet txc founds 1 records when not committed yet since it's same transaction dbc founds 1 records after committed txc returns an error sql.ErrTxDone after committed
Index ¶
- func Register(name string, dialect dialect.Dialect)
- func TxScope(tx *sql.Tx, err error) txScope
- type CompilerOptions
- type DBContext
- func (dbc *DBContext) CompilePatch() *SqlizerList
- func (dbc *DBContext) DebugMode(enabled bool)
- func (dbc *DBContext) Dialect() dialect.Dialect
- func (dbc *DBContext) Include(v interface{}, sc *ScopeCache, loader IncludeLoader) error
- func (dbc *DBContext) IncludeContext(ctx context.Context, v interface{}, sc *ScopeCache, loader IncludeLoader) error
- func (dbc *DBContext) Patch(v *Patch)
- func (dbc *DBContext) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (dbc *DBContext) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (dbc *DBContext) QueryRow(query string, args ...interface{}) *sql.Row
- func (dbc *DBContext) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (dbc *DBContext) SaveChanges() error
- func (dbc *DBContext) SaveChangesContext(ctx context.Context) error
- func (dbc *DBContext) Scan(rows *sql.Rows, v interface{}) error
- func (dbc *DBContext) UseTx(tx *sql.Tx) *DBContext
- type IncludeBuffer
- type IncludeLoader
- type IncludeLoaderFunc
- type IncludeLoaderList
- type Logger
- type MapRowKey
- type MetaSchema
- func (m *MetaSchema) Compute()
- func (m *MetaSchema) DeletePatchOf(entity interface{}) *Patch
- func (m *MetaSchema) InsertPatchOf(entity interface{}) *Patch
- func (m *MetaSchema) KeyStringFromRowKey(rowKey RowKey) string
- func (m *MetaSchema) LoadOf(entity interface{}) *metaTable
- func (m *MetaSchema) PrimaryKeyOf(entity interface{}) RowKey
- func (m *MetaSchema) ReferenceKeysOf(entity interface{}) []RowKey
- func (m *MetaSchema) Register(entity interface{})
- func (m *MetaSchema) UpdatePatchOf(entity interface{}) *Patch
- type Patch
- type PatchCompiler
- type PatchCompilerFunc
- type PatchElement
- type PatchKind
- type PatchList
- func (l *PatchList) Back() *PatchElement
- func (l *PatchList) Front() *PatchElement
- func (l *PatchList) Init() *PatchList
- func (l *PatchList) InsertAfter(v *Patch, mark *PatchElement) *PatchElement
- func (l *PatchList) InsertBefore(v *Patch, mark *PatchElement) *PatchElement
- func (l *PatchList) Len() int
- func (l *PatchList) MoveAfter(e *PatchElement, mark *PatchElement)
- func (l *PatchList) MoveBefore(e *PatchElement, mark *PatchElement)
- func (l *PatchList) MoveToBack(e *PatchElement)
- func (l *PatchList) MoveToFront(e *PatchElement)
- func (l *PatchList) PushBack(v *Patch) *PatchElement
- func (l *PatchList) PushBackList(other *PatchList)
- func (l *PatchList) PushFront(v *Patch) *PatchElement
- func (l *PatchList) PushFrontList(other *PatchList)
- func (l *PatchList) Remove(e *PatchElement) *Patch
- type QueryRunner
- type RowKey
- type ScopeCache
- type SqlizerElement
- type SqlizerList
- func (l *SqlizerList) Back() *SqlizerElement
- func (l *SqlizerList) Front() *SqlizerElement
- func (l *SqlizerList) Init() *SqlizerList
- func (l *SqlizerList) InsertAfter(v squirrel.Sqlizer, mark *SqlizerElement) *SqlizerElement
- func (l *SqlizerList) InsertBefore(v squirrel.Sqlizer, mark *SqlizerElement) *SqlizerElement
- func (l *SqlizerList) Len() int
- func (l *SqlizerList) MoveAfter(e *SqlizerElement, mark *SqlizerElement)
- func (l *SqlizerList) MoveBefore(e *SqlizerElement, mark *SqlizerElement)
- func (l *SqlizerList) MoveToBack(e *SqlizerElement)
- func (l *SqlizerList) MoveToFront(e *SqlizerElement)
- func (l *SqlizerList) PushBack(v squirrel.Sqlizer) *SqlizerElement
- func (l *SqlizerList) PushBackList(other *SqlizerList)
- func (l *SqlizerList) PushFront(v squirrel.Sqlizer) *SqlizerElement
- func (l *SqlizerList) PushFrontList(other *SqlizerList)
- func (l *SqlizerList) Remove(e *SqlizerElement) squirrel.Sqlizer
- type StmtCacher
- func (pqr *StmtCacher) Close() error
- func (pqr *StmtCacher) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (pqr *StmtCacher) Prepare(query string) (*sql.Stmt, error)
- func (pqr *StmtCacher) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
- func (pqr *StmtCacher) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (pqr *StmtCacher) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (pqr *StmtCacher) StmtStats() StmtStats
- type StmtStats
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TxScope ¶
Example (Do) ¶
package main import ( "database/sql" "github.com/kamichidu/goen" _ "github.com/mattn/go-sqlite3" ) func main() { db, err := sql.Open("sqlite3", "./sqlite.db") if err != nil { panic(err) } defer db.Close() dbc := goen.NewDBContext("sqlite3", db) err = goen.TxScope(db.Begin()).Do(func(tx *sql.Tx) error { txc := dbc.UseTx(tx) // manipulate with txc txc.QueryRow("select 1") // return nil, will be called tx.Commit() by TxScope // otherwise, will be called tx.Rollback() return nil }) if err != nil { panic(err) } }
Output:
Example (FuncCall) ¶
package main import ( "database/sql" "github.com/kamichidu/goen" _ "github.com/mattn/go-sqlite3" ) func main() { db, err := sql.Open("sqlite3", "./sqlite.db") if err != nil { panic(err) } defer db.Close() dbc := goen.NewDBContext("sqlite3", db) err = goen.TxScope(db.Begin())(func(tx *sql.Tx) error { txc := dbc.UseTx(tx) // manipulate with txc txc.QueryRow("select 1") // return nil, will be called tx.Commit() by TxScope // otherwise, will be called tx.Rollback() return nil }) if err != nil { panic(err) } }
Output:
Types ¶
type CompilerOptions ¶
type CompilerOptions struct { StmtBuilder sqr.StatementBuilderType Patches *PatchList }
type DBContext ¶
type DBContext struct { // This field is readonly. // Sets via NewDBContext(). DB *sql.DB // This field is readonly. // Sets via UseTx(); or nil. Tx *sql.Tx // The patch compiler. // This is used when need to compile patch to query. Compiler PatchCompiler // The logger for debugging. // This is used when DebugMode(true). Logger Logger // The depth limit to avoid circular Include work. // When this value is positive, Include works N-times. // When this value is negative, Include works unlimited. // When this value is 0, Include never works. // Default is 10. MaxIncludeDepth int // The runner for each query. // This field is indented to hold one of *sql.DB, *sql.Tx or *StmtCacher. QueryRunner QueryRunner // contains filtered or unexported fields }
DBContext holds *sql.DB (and *sql.Tx) with contextual values. goen is intended to work with *sql.DB (and *sql.Tx) via DBContext.
func NewDBContext ¶
NewDBContext creates DBContext with given dialectName and db.
func (*DBContext) CompilePatch ¶
func (dbc *DBContext) CompilePatch() *SqlizerList
func (*DBContext) Include ¶
func (dbc *DBContext) Include(v interface{}, sc *ScopeCache, loader IncludeLoader) error
func (*DBContext) IncludeContext ¶
func (dbc *DBContext) IncludeContext(ctx context.Context, v interface{}, sc *ScopeCache, loader IncludeLoader) error
func (*DBContext) QueryContext ¶
func (*DBContext) QueryRowContext ¶
func (*DBContext) SaveChanges ¶
func (*DBContext) SaveChangesContext ¶
type IncludeBuffer ¶
func (*IncludeBuffer) AddRecords ¶
func (l *IncludeBuffer) AddRecords(records interface{})
type IncludeLoader ¶
type IncludeLoader interface {
Load(ctx context.Context, later *IncludeBuffer, sc *ScopeCache, records interface{}) error
}
type IncludeLoaderFunc ¶
type IncludeLoaderFunc func(context.Context, *IncludeBuffer, *ScopeCache, interface{}) error
func (IncludeLoaderFunc) Load ¶
func (fn IncludeLoaderFunc) Load(ctx context.Context, later *IncludeBuffer, sc *ScopeCache, records interface{}) error
type IncludeLoaderList ¶
type IncludeLoaderList []IncludeLoader
func (*IncludeLoaderList) Append ¶
func (list *IncludeLoaderList) Append(v ...IncludeLoader)
func (IncludeLoaderList) Load ¶
func (list IncludeLoaderList) Load(ctx context.Context, later *IncludeBuffer, sc *ScopeCache, records interface{}) error
type MetaSchema ¶
type MetaSchema struct {
// contains filtered or unexported fields
}
func (*MetaSchema) Compute ¶
func (m *MetaSchema) Compute()
func (*MetaSchema) DeletePatchOf ¶
func (m *MetaSchema) DeletePatchOf(entity interface{}) *Patch
func (*MetaSchema) InsertPatchOf ¶
func (m *MetaSchema) InsertPatchOf(entity interface{}) *Patch
func (*MetaSchema) KeyStringFromRowKey ¶
func (m *MetaSchema) KeyStringFromRowKey(rowKey RowKey) string
func (*MetaSchema) LoadOf ¶
func (m *MetaSchema) LoadOf(entity interface{}) *metaTable
func (*MetaSchema) PrimaryKeyOf ¶
func (m *MetaSchema) PrimaryKeyOf(entity interface{}) RowKey
func (*MetaSchema) ReferenceKeysOf ¶
func (m *MetaSchema) ReferenceKeysOf(entity interface{}) []RowKey
func (*MetaSchema) Register ¶
func (m *MetaSchema) Register(entity interface{})
func (*MetaSchema) UpdatePatchOf ¶
func (m *MetaSchema) UpdatePatchOf(entity interface{}) *Patch
type Patch ¶
type Patch struct { Kind PatchKind TableName string RowKey RowKey Columns []string Values []interface{} }
func DeletePatch ¶
func InsertPatch ¶
type PatchCompiler ¶
type PatchCompiler interface {
Compile(*CompilerOptions) *SqlizerList
}
var ( DefaultCompiler PatchCompiler = PatchCompilerFunc(compilePatch) BulkCompiler PatchCompiler = &bulkCompiler{} )
type PatchCompilerFunc ¶
type PatchCompilerFunc func(*CompilerOptions) *SqlizerList
func (PatchCompilerFunc) Compile ¶
func (fn PatchCompilerFunc) Compile(opts *CompilerOptions) (sqlizers *SqlizerList)
type PatchElement ¶
type PatchElement struct {
// contains filtered or unexported fields
}
PatchElement is typed version of list.Element
func (*PatchElement) GetValue ¶
func (e *PatchElement) GetValue() *Patch
GetValue gets the value stored with this element.
func (*PatchElement) Next ¶
func (e *PatchElement) Next() *PatchElement
Next returns the next list element or nil.
func (*PatchElement) Prev ¶
func (e *PatchElement) Prev() *PatchElement
Prev returns the previous list element or nil.
func (*PatchElement) SetValue ¶
func (e *PatchElement) SetValue(v *Patch)
SetValue sets value with this element.
type PatchList ¶
PatchList is typed version of list.List
func NewPatchList ¶
func NewPatchList() *PatchList
func (*PatchList) Back ¶
func (l *PatchList) Back() *PatchElement
Back is typed version of (*list.List).Back
func (*PatchList) Front ¶
func (l *PatchList) Front() *PatchElement
Front is typed version of (*list.List).Front
func (*PatchList) InsertAfter ¶
func (l *PatchList) InsertAfter(v *Patch, mark *PatchElement) *PatchElement
InsertAfter is typed version of (*list.List).InsertAfter
func (*PatchList) InsertBefore ¶
func (l *PatchList) InsertBefore(v *Patch, mark *PatchElement) *PatchElement
InsertBefore is typed version of (*list.List).InsertBefore
func (*PatchList) MoveAfter ¶
func (l *PatchList) MoveAfter(e *PatchElement, mark *PatchElement)
MoveAfter is typed version of (*list.List).MoveAfter
func (*PatchList) MoveBefore ¶
func (l *PatchList) MoveBefore(e *PatchElement, mark *PatchElement)
MoveBefore is typed version of (*list.List).MoveBefore
func (*PatchList) MoveToBack ¶
func (l *PatchList) MoveToBack(e *PatchElement)
MoveToBack is typed version of (*list.List).MoveToBack
func (*PatchList) MoveToFront ¶
func (l *PatchList) MoveToFront(e *PatchElement)
MoveToFront is typed version of (*list.List).MoveToFront
func (*PatchList) PushBack ¶
func (l *PatchList) PushBack(v *Patch) *PatchElement
PushBack is typed version of (*list.List).PushBack
func (*PatchList) PushBackList ¶
PushBackList is typed version of (*list.List).PushBackList
func (*PatchList) PushFront ¶
func (l *PatchList) PushFront(v *Patch) *PatchElement
PushFront is typed version of (*list.List).PushFront
func (*PatchList) PushFrontList ¶
PushFrontList is typed version of (*list.List).PushFrontList
func (*PatchList) Remove ¶
func (l *PatchList) Remove(e *PatchElement) *Patch
Remove is typed version of (*list.List).Remove
type QueryRunner ¶
type QueryRunner interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) QueryRowContext(context.Context, string, ...interface{}) *sql.Row QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error) }
QueryRunner ...
type ScopeCache ¶
type ScopeCache struct { Meta *MetaSchema // contains filtered or unexported fields }
func NewScopeCache ¶
func NewScopeCache(meta *MetaSchema) *ScopeCache
func (*ScopeCache) AddObject ¶
func (sc *ScopeCache) AddObject(v interface{})
func (*ScopeCache) GetObject ¶
func (sc *ScopeCache) GetObject(rowKey RowKey) interface{}
func (*ScopeCache) HasObject ¶
func (sc *ScopeCache) HasObject(rowKey RowKey) bool
func (*ScopeCache) RemoveObject ¶
func (sc *ScopeCache) RemoveObject(v interface{})
type SqlizerElement ¶
type SqlizerElement struct {
// contains filtered or unexported fields
}
SqlizerElement is typed version of list.Element
func (*SqlizerElement) GetValue ¶
func (e *SqlizerElement) GetValue() squirrel.Sqlizer
GetValue gets the value stored with this element.
func (*SqlizerElement) Next ¶
func (e *SqlizerElement) Next() *SqlizerElement
Next returns the next list element or nil.
func (*SqlizerElement) Prev ¶
func (e *SqlizerElement) Prev() *SqlizerElement
Prev returns the previous list element or nil.
func (*SqlizerElement) SetValue ¶
func (e *SqlizerElement) SetValue(v squirrel.Sqlizer)
SetValue sets value with this element.
type SqlizerList ¶
SqlizerList is typed version of list.List
func NewSqlizerList ¶
func NewSqlizerList() *SqlizerList
func (*SqlizerList) Back ¶
func (l *SqlizerList) Back() *SqlizerElement
Back is typed version of (*list.List).Back
func (*SqlizerList) Front ¶
func (l *SqlizerList) Front() *SqlizerElement
Front is typed version of (*list.List).Front
func (*SqlizerList) Init ¶
func (l *SqlizerList) Init() *SqlizerList
Init is typed version of (*list.List).Init
func (*SqlizerList) InsertAfter ¶
func (l *SqlizerList) InsertAfter(v squirrel.Sqlizer, mark *SqlizerElement) *SqlizerElement
InsertAfter is typed version of (*list.List).InsertAfter
func (*SqlizerList) InsertBefore ¶
func (l *SqlizerList) InsertBefore(v squirrel.Sqlizer, mark *SqlizerElement) *SqlizerElement
InsertBefore is typed version of (*list.List).InsertBefore
func (*SqlizerList) MoveAfter ¶
func (l *SqlizerList) MoveAfter(e *SqlizerElement, mark *SqlizerElement)
MoveAfter is typed version of (*list.List).MoveAfter
func (*SqlizerList) MoveBefore ¶
func (l *SqlizerList) MoveBefore(e *SqlizerElement, mark *SqlizerElement)
MoveBefore is typed version of (*list.List).MoveBefore
func (*SqlizerList) MoveToBack ¶
func (l *SqlizerList) MoveToBack(e *SqlizerElement)
MoveToBack is typed version of (*list.List).MoveToBack
func (*SqlizerList) MoveToFront ¶
func (l *SqlizerList) MoveToFront(e *SqlizerElement)
MoveToFront is typed version of (*list.List).MoveToFront
func (*SqlizerList) PushBack ¶
func (l *SqlizerList) PushBack(v squirrel.Sqlizer) *SqlizerElement
PushBack is typed version of (*list.List).PushBack
func (*SqlizerList) PushBackList ¶
func (l *SqlizerList) PushBackList(other *SqlizerList)
PushBackList is typed version of (*list.List).PushBackList
func (*SqlizerList) PushFront ¶
func (l *SqlizerList) PushFront(v squirrel.Sqlizer) *SqlizerElement
PushFront is typed version of (*list.List).PushFront
func (*SqlizerList) PushFrontList ¶
func (l *SqlizerList) PushFrontList(other *SqlizerList)
PushFrontList is typed version of (*list.List).PushFrontList
func (*SqlizerList) Remove ¶
func (l *SqlizerList) Remove(e *SqlizerElement) squirrel.Sqlizer
Remove is typed version of (*list.List).Remove
type StmtCacher ¶
type StmtCacher struct {
// contains filtered or unexported fields
}
StmtCacher implements QueryRunner. It caches prepared statements for executing or querying.
func NewStmtCacher ¶
func NewStmtCacher(prep sqr.PreparerContext) *StmtCacher
NewStmtCacher returns new StmtCacher with given prep.
func (*StmtCacher) Close ¶
func (pqr *StmtCacher) Close() error
Close closes and removes all cached prepared statements.
func (*StmtCacher) ExecContext ¶
func (pqr *StmtCacher) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext executes given query with args via prepared statement.
func (*StmtCacher) Prepare ¶
func (pqr *StmtCacher) Prepare(query string) (*sql.Stmt, error)
Prepare is only for implements squirrel.PreparerContext. DO NOT USE THIS.
func (*StmtCacher) PrepareContext ¶
PrepareContext returns new or cached prepared statement.
func (*StmtCacher) QueryContext ¶
func (pqr *StmtCacher) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryContext queries by given query with args via prepared statement.
func (*StmtCacher) QueryRowContext ¶
func (pqr *StmtCacher) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
QueryRowContext queries a row by given query with args via prepared statement.
func (*StmtCacher) StmtStats ¶
func (pqr *StmtCacher) StmtStats() StmtStats
StmtStats returns statistics values.