Documentation
¶
Index ¶
- type DB
- func (d *DB) Begin() (*Tx, error)
- func (d *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
- func (d *DB) CacheSize() int
- func (d *DB) CachingEnabled() bool
- func (d *DB) ClearCache() error
- func (d *DB) Close() error
- func (d *DB) Exec(query string, args ...interface{}) (sql.Result, error)
- func (d *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (d *DB) Prepare(query string) (*sql.Stmt, error)
- func (d *DB) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
- func (d *DB) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (d *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (d *DB) SetCaching(enabled bool) *DB
- type Tx
- func (t *Tx) Exec(query string, args ...interface{}) (sql.Result, error)
- func (t *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (t *Tx) Prepare(query string) (*sql.Stmt, error)
- func (t *Tx) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
- func (t *Tx) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (t *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
DB is a wrapper for sql.DB, providing an additional layer for caching prepared statements to optimize database interactions and improve performance.
func (*DB) Begin ¶
Begin starts a new SQL transaction and returns a Tx object with statement caching capabilities.
func (*DB) BeginTx ¶
BeginTx starts a new SQL transaction and returns a Tx object with statement caching capabilities.
func (*DB) CacheSize ¶
CacheSize returns the current number of prepared statements stored in the cache.
func (*DB) CachingEnabled ¶
CachingEnabled returns true if statements caching is enabled
func (*DB) ClearCache ¶
ClearCache will close all cached prepared statements and clear statements cache map
func (*DB) Exec ¶
Exec executes a query that doesn't return rows. Exec delegates call to ExecContext with contex.Background() as parameter.
func (*DB) ExecContext ¶
func (d *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext executes a query that doesn't return rows. If statement caching is enabled, ExecContext will first call PrepareContext to retrieve a prepared statement, and then execute a query using a prepared statement. If statement caching is disabled, this method delegates the call to the *sql.DB ExecContext method.
func (*DB) Prepare ¶
Prepare delegates call to PrepareContext using context.Background as a parameter.
func (*DB) PrepareContext ¶
PrepareContext returns database prepared statement for a query. When statement caching is enabled, it returns a cached prepared statement if available; otherwise, it creates a new prepared statement and adds it to the cache. Invoking this method directly is unnecessary, as wrapper methods like Exec/ExecContext and Query/QueryContext will call PrepareContext before executing a query on it. If statement caching is disabled, this method delegates the call to the *sql.DB PrepareContext method.
There's no need to manually close the returned statement; it operates within the transaction scope and will be closed automatically upon the completion of the transaction, whether it's committed or rolled back.
func (*DB) QueryContext ¶
func (d *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryContext executes a query that returns rows. If statement caching is enabled, QueryContext will first call PrepareContext to retrieve a prepared statement, and then execute a query using a prepared statement. If statement caching is disabled, this method delegates the call to the *sql.DB QueryContext method.
func (*DB) SetCaching ¶
SetCaching returns *DB wrapper with prepared statements caching enabled or disabled. This method should be called only once. It is not concurrency-safe.
type Tx ¶
Tx is a wrapper around *sql.Tx, adding prepared statement caching capability. Tx is not thread safe and should not be shared between goroutines.
func (*Tx) Exec ¶
Exec executes a query that doesn't return rows. Exec delegates call to ExecContext with contex.Background() as parameter.
func (*Tx) ExecContext ¶
func (t *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext executes a query that doesn't return rows. If statement caching is enabled, ExecContext will first call PrepareContext to retrieve a prepared statement, and then execute a query using a prepared statement. If statement caching is disabled, this method delegates the call to the *sql.Tx ExecContext method.
func (*Tx) Prepare ¶
Prepare delegates call to PrepareContext using context.Background as a parameter.
func (*Tx) PrepareContext ¶
PrepareContext returns database prepared statement for a query. When statement caching is enabled, it returns a cached prepared statement if available; otherwise, it creates a new prepared statement and adds it to the cache. Invoking this method directly is unnecessary, as wrapper methods like Exec/ExecContext and Query/QueryContext will call PrepareContext before executing a query on it. If statement caching is disabled, this method delegates the call to the *sql.Tx PrepareContext method.
There's no need to manually close the returned statement; it operates within the transaction scope and will be closed automatically upon the completion of the transaction, whether it's committed or rolled back.
func (*Tx) QueryContext ¶
func (t *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryContext executes a query that returns rows. If statement caching is enabled, QueryContext will first call PrepareContext to retrieve a prepared statement, and then execute a query using a prepared statement. If statement caching is disabled, this method delegates the call to the *sql.Tx QueryContext method.