gxsql

package module
v0.0.0-...-8306030 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2020 License: GPL-3.0 Imports: 6 Imported by: 1

README

goxic-sql

GoDoc

import "git.fractalqb.de/fractalqb/goxic-sql"

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewParser

func NewParser() *goxic.Parser

func ParseString

func ParseString(s, rootName string, into map[string]*goxic.Template) error

Types

type Binder

type Binder interface {
	Bind(args ...sql.NamedArg) ([]interface{}, error)
}

func MustRewrite

func MustRewrite(prw ParamRewriter, tmpl string, args map[string]goxic.Content) (string, Binder)

func Rewrite

func Rewrite(prw ParamRewriter, tmpl string, args map[string]goxic.Content) (string, Binder, error)

type IndexBinder

type IndexBinder []string

func (IndexBinder) Bind

func (ib IndexBinder) Bind(args ...sql.NamedArg) ([]interface{}, error)

type IndexRewriter

type IndexRewriter struct {
	Format string
	Start  int
}

func (IndexRewriter) Rewrite

func (iw IndexRewriter) Rewrite(t *goxic.Template) (
	ft *goxic.Template,
	b Binder,
	err error,
)

type ParamRewriter

type ParamRewriter interface {
	Rewrite(t *goxic.Template) (*goxic.Template, Binder, error)
}

type PositionBinder

type PositionBinder []string

func (PositionBinder) Bind

func (pb PositionBinder) Bind(args ...sql.NamedArg) ([]interface{}, error)

type PositionRewriter

type PositionRewriter string

func (PositionRewriter) Rewrite

func (pw PositionRewriter) Rewrite(t *goxic.Template) (
	ft *goxic.Template,
	b Binder,
	err error,
)

type Scanner

type Scanner interface {
	Scan(dest ...interface{}) error
}

type Statement

type Statement struct {
	SQL  string
	Args Binder
	Log  func(method, sql string, args []interface{})
}

func (*Statement) Exec

func (stmt *Statement) Exec(db *sql.DB, args ...sql.NamedArg) (sql.Result, error)

func (*Statement) ExecTx

func (stmt *Statement) ExecTx(tx *sql.Tx, args ...sql.NamedArg) (sql.Result, error)

func (*Statement) MustRewrite

func (stmt *Statement) MustRewrite(prw ParamRewriter, tmpl string, args map[string]goxic.Content)

func (*Statement) Query

func (stmt *Statement) Query(db *sql.DB, args ...sql.NamedArg) (*sql.Rows, error)

func (*Statement) QueryRow

func (stmt *Statement) QueryRow(db *sql.DB, args ...sql.NamedArg) Scanner

func (*Statement) QueryRowTx

func (stmt *Statement) QueryRowTx(tx *sql.Tx, args ...sql.NamedArg) Scanner

func (*Statement) QueryTx

func (stmt *Statement) QueryTx(tx *sql.Tx, args ...sql.NamedArg) (*sql.Rows, error)

func (*Statement) Rewrite

func (stmt *Statement) Rewrite(prw ParamRewriter, tmpl string, args map[string]goxic.Content) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL