Documentation ¶
Overview ¶
Package gxsql handles idiosyncrasies of different SQL dialects through the use of templates.
This shall not encourage to inject external input into the text form of SQL statements! Instead gxsql helps to uniquely hanlde the robust assignment of named arguments to different conventions for SQL placeholders.
Additionally one can dynamically create SQL statements through the use of the underlying goxic template engine. If doing so, care hase to be taken to not introduce security risks.
E.g. to ge these two different statemens from one source
SELECT name, age FROM person WHERE id=? SELECT name, age FROM pim.person WHERE id=$1
one would start with a unified statement template that has a simple template placeholder :schema: and a parameter placeholder :$id:
SELECT name, age FROM :schema:person WHERE id=:$id:
Depending on the chosen ParamRewriter one can easily create different versions of the statement.
Index ¶
- func NewParser() *goxic.Parser
- func ParseString(s, rootName string, into map[string]*goxic.Template) error
- type Binder
- type IndexBinder
- type IndexRewriter
- type ParamRewriter
- type PositionBinder
- type PositionRewriter
- type Scanner
- type Statement
- func (stmt *Statement) Exec(db *sql.DB, args ...sql.NamedArg) (sql.Result, error)
- func (stmt *Statement) ExecTx(tx *sql.Tx, args ...sql.NamedArg) (sql.Result, error)
- func (stmt *Statement) MustRewrite(prw ParamRewriter, tmpl string, args map[string]goxic.Content)
- func (stmt *Statement) Query(db *sql.DB, args ...sql.NamedArg) (*sql.Rows, error)
- func (stmt *Statement) QueryRow(db *sql.DB, args ...sql.NamedArg) Scanner
- func (stmt *Statement) QueryRowTx(tx *sql.Tx, args ...sql.NamedArg) Scanner
- func (stmt *Statement) QueryTx(tx *sql.Tx, args ...sql.NamedArg) (*sql.Rows, error)
- func (stmt *Statement) Rewrite(prw ParamRewriter, tmpl string, args map[string]goxic.Content) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type IndexBinder ¶
type IndexBinder []string
func (IndexBinder) Bind ¶
func (ib IndexBinder) Bind(args ...sql.NamedArg) ([]interface{}, error)
type IndexRewriter ¶
type ParamRewriter ¶
type PositionBinder ¶
type PositionBinder []string
func (PositionBinder) Bind ¶
func (pb PositionBinder) Bind(args ...sql.NamedArg) ([]interface{}, error)