Documentation ¶
Index ¶
- Variables
- type Map
- func (m *Map) Add(name, query string) error
- func (m *Map) AddContext(x context.Context, name, query string) error
- func (m *Map) Batch(queries []string) error
- func (m *Map) BatchContext(x context.Context, queries []string) error
- func (m *Map) Close() error
- func (m *Map) Contains(name string) bool
- func (m *Map) Exec(name string, args ...interface{}) (sql.Result, error)
- func (m *Map) ExecContext(x context.Context, name string, args ...interface{}) (sql.Result, error)
- func (m *Map) Extend(data map[string]string) error
- func (m *Map) ExtendContext(x context.Context, data map[string]string) error
- func (m *Map) Get(name string) (*sql.Stmt, bool)
- func (m *Map) Len() int
- func (m *Map) Query(name string, args ...interface{}) (*sql.Rows, error)
- func (m *Map) QueryContext(x context.Context, name string, args ...interface{}) (*sql.Rows, error)
- func (m *Map) QueryRow(name string, args ...interface{}) (*sql.Row, bool)
- func (m *Map) QueryRowContext(x context.Context, name string, args ...interface{}) (*sql.Row, bool)
- func (m *Map) Remove(name string) bool
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidDB = &errval{s: "database cannot be nil"}
ErrInvalidDB is an error returned when the Database property of the Map is nil.
Functions ¶
This section is empty.
Types ¶
type Map ¶
Map is a struct that is used to track and manage multiple database *Stmt structs. Each statement can be mapped to a name that can be used again to recall or execute the statement.
This struct is safe for multiple co-current goroutine usage.
func New ¶
New is a shorthand function for "&Map{database: db}". Returns a new Map instance backed by the supplied database.
func (*Map) Add ¶
Add will prepare and add the specified query to the Map with the provided name.
This will only add the mapping if the 'Prepare' function is successful. Otherwise the prepare error will be returned.
This function does not allow for adding a mapping when one already exists. If a mapping with an overlapping name is attempted, an error will be returned before attempting to prepare the query.
func (*Map) AddContext ¶
AddContext will prepare and add the specified query to the Map with the provided name.
This will only add the mapping if the 'Prepare' function is successful. Otherwise the prepare error will be returned.
This function does not allow for adding a mapping when one already exists. If a mapping with an overlapping name is attempted, an error will be returned before attempting to prepare the query.
This function specifies a Context that can be used to interrupt and cancel the prepare calls.
func (*Map) Batch ¶
Batch is a function that can be used to perform execute statements in a specific order.
This function will execute all the statements in the provided string array and will stop and return any errors that occur.
The passed query results will not be returned or parsed.
func (*Map) BatchContext ¶
BatchContext is a function that can be used to perform execute statements in a specific order. This function will execute all the statements in the provided string array and will stop and return any errors that occur.
The passed query results will not be returned or parsed.
This function specifies a Context that can be used to interrupt and cancel the execute calls.
func (*Map) Close ¶
Close will attempt to close all the contained database statements. This will bail on any errors that occur.
Multiple calls to close can be used to make sure that all statements are closed successfully. Note: this will also attempt to close the connected database if all statement closures are successful.
func (*Map) Exec ¶
Exec will attempt to get the statement with the provided name and then attempt to call the 'Exec' function on the statement.
This provides the results of the Exec function.
func (*Map) ExecContext ¶
ExecContext will attempt to get the statement with the provided name and then attempt to call the 'Exec' function on the statement.
This provides the results of the Exec function.
This function specifies a Context that can be used to interrupt and cancel the Exec function.
func (*Map) Extend ¶
Extend will prepare and add all the specified queries in the provided map to the Map.
This will only add each mapping if the 'Prepare' function is successful. Otherwise the prepare error will be returned.
This function does not allow for adding a mapping when one already exists. If a mapping with an overlapping name is attempted, an error will be returned before attempting to prepare the query.
func (*Map) ExtendContext ¶
ExtendContext will prepare and add all the specified queries in the provided map to the Map.
This will only add each mapping if the 'Prepare' function is successful. Otherwise the prepare error will be returned.
This function does not allow for adding a mapping when one already exists. If a mapping with an overlapping name is attempted, an error will be returned before attempting to prepare the query.
This function specifies a Context that can be used to interrupt and cancel the prepare calls.
func (*Map) Get ¶
Get will attempt to return the statement that is associated with the provided name.
This function will return the statement and True if the mapping exists. Otherwise, the statement will be nil and the boolean will be False.
func (*Map) Query ¶
Query will attempt to get the statement with the provided name and then attempt to call the 'Query' function on the statement.
This provides the results of the Query function.
func (*Map) QueryContext ¶
QueryContext will attempt to get the statement with the provided name and then attempt to call the 'Query' function on the statement.
This provides the results of the Query function.
This function specifies a Context that can be used to interrupt and cancel the Query function.
func (*Map) QueryRow ¶
QueryRow will attempt to get the statement with the provided name and then attempt to call the 'QueryRow' function on the statement.
This function differs from the original 'QueryRow' statement as this provides a boolean to indicate if the provided named statement was found.
If the returned boolean is True, the result is not-nil and safe to use.
func (*Map) QueryRowContext ¶
QueryRowContext will attempt to get the statement with the provided name and then attempt to call the 'QueryRow' function on the statement.
This function differs from the original 'QueryRow' statement as this provides a boolean to indicate if the provided named statement was found.
If the returned boolean is True, the result is not-nil and safe to use.
This function specifies a Context that can be used to interrupt and cancel the Query function.