kdb

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

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

Go to latest
Published: Aug 23, 2013 License: MIT Imports: 10 Imported by: 1

README

kdb

kdb is a package to wrap Go's database/sql

Version

Current release: version 0.3 (2013-08-16)

Document

godoc

Sorry for bad english, if you want to improve documents, please contact me.

Features

  • lightweight, flexible and fast
  • orm
  • suppoort Sql template
  • support Store procedure, and out parameter
  • support get schema of table and store procedure
  • support sql expression
  • ingore NULL when scan rows
  • test on sql server, mysql, olite, postgres, oracle

Requirements

Go 1.1+

Installation

go get github.com/sdming/kdb

Register a new driver

Need to call RegisterDialecter/RegisterCompiler to bind your sql driver to a kdb.Dialecter and kdb.Compiler.

example :

RegisterDialecter("mysql", MysqlDialecter{})
RegisterCompiler("mysql", MySql())

RegisterDialecter("postgres", PostgreSQLDialecter{})
RegisterCompiler("postgres", PostgreSQL())

Register a DSN

Call RegisterDSN to register a DSN, example:

kdb.RegisterDSN("demo", "postgres", "user=postgres password=sa dbname=postgres sslmode=disable client_encoding=UTF8")

Example

demo of how to query or execute sql in Go way:

func basic() {
	db := kdb.NewDB("demo")
	defer db.Close()

	var query string

	query = "select * from ttable where cint > $1"
	fmt.Println("\nQuery:", query)
	printRows(db.Query(query, 1))

	query = "update ttable set cdatetime=NOW() where cint > $1"
	fmt.Println("\nExec", query)
	printResult(db.Exec(query, 1))
}

demo of how to bind parameters to a map or struct

query = "select * from ttable where cint > {cint}"
fmt.Println("\nQueryText", query)
printRows(db.QueryText(query, kdb.Map(data)))

query = "update ttable set cdatetime=NOW() where cint > {cint}"
fmt.Println("\nExecText", query)
printResult(db.ExecText(query, kdb.Map(data)))

Template

demo of how to run a template sql.

func text() {
	db := kdb.NewDB("demo")
	defer db.Close()

	query := "select * from ttable where cint > {cint}"
	text := kdb.NewText(query).Set("cint", 1)
	fmt.Println("\nText query", query)
	printRows(db.QueryExp(text))

	query = "update ttable set cdatetime=NOW() where cint > {cint}"
	text = kdb.NewText(query).Set("cint", 42)
	fmt.Println("\nText exec", query)
	printResult(db.ExecExp(text))

}

Store Procedure

demo of how to run a store procedure.

func procedure() {
	db := kdb.NewDB("demo")
	fmt.Println("\nQueryFunc", "fn_query")
	printRows(db.QueryFunc("fn_query", kdb.Map(data)))
	db.Close()

	db = kdb.NewDB("demo")
	fmt.Println("\nExecFunc", "fn_exec")
	printRows(db.QueryFunc("fn_exec", kdb.Map(data)))
	db.Close()

	db = kdb.NewDB("demo")
	fmt.Println("\nProcedure", "fn_inout")
	sp := kdb.NewProcedure("fn_inout").
		Set("x", 3).
		SetDir("y", 5, ansi.DirInOut).
		SetDir("sum", nil, ansi.DirOut)
	printRows(db.QueryExp(sp))
	db.Close()
}

Select

demo of how to select from a table.

func selectTable() {
	db := kdb.NewDB("demo")
	defer db.Close()

	fmt.Println("\nSelectAll")
	printRows(db.SelectAll("ttable",
		"cint", kdb.GreaterThan, 1,
		"cfloat", kdb.LessThan, 123456,
		"cdatetime", "<>", time.Now(),
	))

	fmt.Println("\nSelectCount")
	fmt.Println(db.SelectCount("ttable"))

	fmt.Println("\nSelectExists")
	fmt.Println(db.SelectExists("ttable", "cint", kdb.GreaterThan, 12345))

	fmt.Println("\nQuery ttable")
	q := kdb.NewQuery("ttable", "")
	q.Select.
		Column("cbool", "cint").
		ColumnAs("cstring", "astring").
		Exp(kdb.Sql("cfloat-1"), "afloat").
		Avg("cnumeric", "aavg").
		Count("cnumeric", "acount").
		Max("cnumeric", "amax").
		Min("cnumeric", "amin").
		Sum("cnumeric", "asum")

	q.Where.
		OpenParentheses().
		IsNull("cbytes").
		Or().
		IsNotNull("cbytes").
		CloseParentheses()

	q.UseGroupBy().
		Column("cbool", "cint", "cstring").
		By(kdb.Sql("cfloat-1"))

	q.UseHaving().
		Count(kdb.GreaterThan, "cnumeric", 0).
		LessThan("cint", 12345)

	q.UseOrderBy().Asc("cbool", "cint").Desc("cstring")

	printRows(db.QueryExp(q))

}

Update

demo of how to update a table.

func updateTable() {
	db := kdb.NewDB("demo")
	defer db.Close()

	fmt.Println("\nUpdateColumn")
	fmt.Println(db.UpdateColumn("ttable", "cstring", "cstring_update", "cint", kdb.Equals, 42))

	fmt.Println("\nUpdate")
	fmt.Println(db.Update("ttable", kdb.Map(data), "cint", kdb.Equals, 42))

	fmt.Println("\nUpdate ttable")
	u := kdb.NewUpdate("ttable")
	u.Set("cstring", "cstring new").
		Set("cfloat", 6.28)
	u.Where.Equals("cint", 42)

	printResult(db.ExecExp(u))
}

Delete

demo of how to delete from a table.

func deleteTable() {
	db := kdb.NewDB("demo")
	defer db.Close()

	fmt.Println("\nDelete ttable by column")
	fmt.Println(db.DeleteByCol("ttable", "cint", 101))

	fmt.Println("\nDelete ttable by conditions")
	fmt.Println(db.Delete("ttable",
		"cint", kdb.Equals, 101,
		"cfloat", kdb.NotEquals, 3.14,
		"cstring", kdb.GreaterThan, "cstring",
		"cdatetime", "=", "2001-01-01",
	))

	fmt.Println("\nDelete ttable")
	del := kdb.NewDelete("ttable")
	del.Where.
		LessThan("cint", 10000).
		GreaterThan("cint", 101).
		NotEquals("cint", 12345).
		NotIn("cint", [5]int{5, 6, 7, 8, 9})
	printResult(db.ExecExp(del))

}

Insert

demo of how to insert into a table.

func insertTable() {
	db := kdb.NewDB("demo")
	defer db.Close()

	d1 := map[string]interface{}{
		"cbool":     true,
		"cint":      123,
		"cfloat":    1.23,
		"cnumeric":  12.30,
		"cstring":   "a string",
		"cdate":     "2000-01-23",
		"cdatetime": time.Now(),
	}

	fmt.Println("\nInsert")
	fmt.Println(db.Insert("ttable", kdb.Map(d1)))

	fmt.Println("\nInsert ttable")
	insert := kdb.NewInsert("ttable")
	insert.Set("cbool", 0).
		Set("cint", 12345).
		Set("cfloat", 12.345).
		Set("cnumeric", 1234.50).
		Set("cstring", "string insert").
		Set("cdate", "1979-01-02")

	printResult(db.ExecExp(insert))

}

Schema

demo of how to get schema of table\store procedure

func schema() {
	db := kdb.NewDB("demo")
	defer db.Close()

	fmt.Println("\nTable", "ttable")
	if table, err := db.Table("ttable"); err != nil {
		fmt.Println("Table", err)
	} else {
		fmt.Println(table)
	}

	fmt.Println("\nFunction", "fn_query")
	if fn, err := db.Function("fn_query"); err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(fn)
	}

	fmt.Println("\nFunction", "fn_exec")
	if fn, err := db.Function("fn_exec"); err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(fn)
	}

	fmt.Println("\nFunction", "fn_inout")
	if fn, err := db.Function("fn_inout"); err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(fn)
	}

	fmt.Println("\nFunction", "fn_notexists")
	if fn, err := db.Function("fn_notexists"); err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(fn)
	}

}

ReadRow(Scan)

ReadRow scan current row to a interface{}. kdb use NullInt64, NullBool... to scan values, it means it's safe to scan NULL .

data

CREATE TABLE ttypes (
	id 			int, 
	cbool 	int,
	cint 		int,
	cfloat 	float,
	cstring varchar(100)
);

insert ttypes(id,cbool,cint,cfloat,cstring) values(1, 1, 123, 3.14, 'string');
insert ttypes(id,cbool,cint,cfloat,cstring) values(2, null, null, null, null);

read row to a *T

var v int
query := fmt.Sprintf("select cint from ttypes where id = 1 ")
queryAndReadRow(db, query, &v)
fmt.Println("read to int:", v == 123)

read row to a []T

l := []int{0}
queryAndReadRow(db, query, l)
fmt.Println("read to []int:", l[0] == 123)

read row to a []*T

v = 0
lp := []*int{&v}
queryAndReadRow(db, query, lp)
fmt.Println("read to []*int:", v == 123)

read row to to a map[string]T

m := map[string]int{}
queryAndReadRow(db, query, m)
fmt.Println("read to map[string]int:", m["cint"] == 123)

read row to a map[string]T, with default value

mv := map[string]int{"cint": 0}
queryAndReadRow(db, query, mv)
fmt.Println("read to map[string]int:", mv["cint"] == 123)

read row to a map[string]*T

v = 0
mp := map[string]*int{"cint": &v}
queryAndReadRow(db, query, mp)
fmt.Println("read to map[string]*int:", v == 123)

read row (null) to *T

v = 321
query = "select cint from ttypes where id = 2"
queryAndReadRow(db, query, &v)
fmt.Println("read null to int:", v == 321)

read row (null) to []T

l = []int{321}
queryAndReadRow(db, query, l)
fmt.Println("read null to []int:", l[0] == 321)

read row (null) to []*T

lp = []*int{&v}
queryAndReadRow(db, query, l)
fmt.Println("read null to []int:", v == 321)

read row (null) to map[string]T

m = map[string]int{}
queryAndReadRow(db, query, m)
fmt.Println("read null to map[string]int:", m["cint"] == 0)

read row (null) to map[string]T, with default value

mv = map[string]int{"cint": 321}
queryAndReadRow(db, query, mv)
fmt.Println("read null to map[string]int:", mv["cint"] == 321)

read row (null) to map[string]*T

v = 321
mp = map[string]*int{"cint": &v}
queryAndReadRow(db, query, mp)
fmt.Println("read null to map[string]int:", v == 321)

Read

Read copy rows to a slice []T.

read rows to []T

var v []int
query := "select cint from ttypes where id in (1,2) order by id "
queryAndRead(db, query, &v)
fmt.Println("read rows to []int:", v[0] == 123, v[1] == 0)

read rows to []map[string]T

m := make([]map[string]int, 0)
queryAndRead(db, query, &m)
fmt.Println("read rows to []map[string]int:", m[0]["cint"] == 123, m[1]["cint"] == 0)

read rows to [][]T

l := make([][]int, 0)
queryAndRead(db, query, &l)
fmt.Println("read rows to [][]int:", l[0][0] == 123, l[1][0] == 0)

Map rows to a struct

When use Read/ReadRow to copy rows to a struct, by default kdb map columns to struct fields with name, for example, copy column "foo" to field named "foo", you can use tags to change.

tags demo:

type InfoTag struct {
	Id     int     "kdb:{pk}"
	Bool   bool    "kdb:{name=cbool}"
	Int    int     "kdb:{name=cint}"
	Float  float32 "kdb:{name=cfloat}"
	String string  "kdb:{name=cstring}"
}

type Info struct {
	Id      int
	CBool   bool
	CInt    int
	CFloat  float32
	CString string
}

map rows to []T

var v []Info
query := "select * from ttypes where id in (1,2) order by id "
queryAndRead(db, query, &v)
fmt.Println("map rows to []Info", v[0], v[1])

map rows to []*T

var vptr []*Info
queryAndRead(db, query, &vptr)
fmt.Println("map rows to []*Info", *(vptr[0]), *(vptr[1]))

map rows to []T, use tags

var vtag []InfoTag
queryAndRead(db, query, &vtag)
fmt.Println("map rows to []InfoTag", vtag[0], vtag[1])

More examples

*mysql
*postgres
*mssql
*sqlite
*oracle
*read
*orm

Driver

*Mysql: https://github.com/Go-SQL-Driver/MySQL
*PostgreSQL: https://github.com/bmizerany/pq
*lodbc: https://github.com/LukeMauldin/lodbc
*SQLite: https://github.com/changkong/go-sqlite3s
*Oracle: https://github.com/mattn/go-oci8

TODO

  • ORM

License

MIT

Documentation

Index

Constants

View Source
const (
	// Opened means conection opened
	Opened state = 3

	// Closed means connection closed
	Closed state = 9
)
View Source
const (
	// LogNone means doesn't log
	LogNone int = 0

	// LogDebug means log err & debug information
	LogDebug int = 1

	// LogError means log err
	LogError int = 3
)

Variables

View Source
var ErrNoResult = errors.New("rows no result")

ErrNoResult means rows doesn't have result

View Source
var ExplictSchema = true

ExplictSchema is true mean must use schema when insert/update

View Source
var LogLevel int = 0

LogLevel

View Source
var Logger *log.Logger

Logger

Functions

func CompileTemplate

func CompileTemplate(template string) (string, []string, error)

CompileTemplate parse template, return formated template, parameter names

func DumpResult

func DumpResult(result sql.Result) string

DumpResult dump sql.Result

func DumpRows

func DumpRows(rows *sql.Rows) string

DumpRows dump *sql.Rows

func FormatSqlValue

func FormatSqlValue(dbType ansi.DbType, v interface{}) string

FormatSqlValue format v to native sql according dbType

func Read

func Read(rows *sql.Rows, dest interface{}) error

Read iterate rows and scan value to dest. dest can be *[]T, *[]map, *[]sliece, *[]struct.

func ReadRow

func ReadRow(rows *sql.Rows, dest interface{}) error

ReadRow scan current row value to dest. dest can be *T, []T, map[string]T

func ReadRowScan

func ReadRowScan(rows *sql.Rows, dest ...interface{}) error

func RegisterCompiler

func RegisterCompiler(driver string, compiler Compiler)

RegisterCompiler makes a compiler available by the provided driver name.

func RegisterDSN

func RegisterDSN(name, driver, source string)

RegisterDSN register a DSN

func RegisterDialecter

func RegisterDialecter(driver string, dialecter Dialecter)

RegisterDialecter makes a dialecter available by the provided driver name.

func RegisterSchemaer

func RegisterSchemaer(driver string, schemaer Schemaer)

RegisterSchemaer makes a schemaer available by the provided driver name.

func SafeSql

func SafeSql(v string) string

SafeSql return a sql that without inject

Types

type Aggregate

type Aggregate struct {
	Name Func
	Exp  Expression
}

Aggregate is sql aggregate Func

func NewAggregate

func NewAggregate(name Func, exp Expression) *Aggregate

NewAggregate return *Aggregate

func (*Aggregate) Node

func (a *Aggregate) Node() NodeType

Node return Node

func (*Aggregate) String

func (a *Aggregate) String() string

String

type AnsiDialecter

type AnsiDialecter struct {
}

AnsiDialecter is ansi sql dialect

func (AnsiDialecter) ColumnsSql

func (ansi AnsiDialecter) ColumnsSql(name string) string

ColumnsSql return sql to query table columns schema

func (AnsiDialecter) DbType

func (ad AnsiDialecter) DbType(nativeType string) ansi.DbType

func (AnsiDialecter) FunctionSql

func (ad AnsiDialecter) FunctionSql(s string) string

FunctionSql return ""

func (AnsiDialecter) Name

func (ad AnsiDialecter) Name() string

Name return "ansi"

func (AnsiDialecter) ParameterPlaceHolder

func (ad AnsiDialecter) ParameterPlaceHolder() string

ParameterPlaceHolder return ?

func (AnsiDialecter) ParametersSql

func (ad AnsiDialecter) ParametersSql(name string) string

ParametersSql return sql to query procedure paramters schema

func (AnsiDialecter) Quote

func (ad AnsiDialecter) Quote(s string) string

Quote quote s as "s"

func (AnsiDialecter) QuoteString

func (ad AnsiDialecter) QuoteString(s string) string

QuoteString quote s as sql native string

func (AnsiDialecter) SplitStatement

func (ad AnsiDialecter) SplitStatement() string

SplitStatement return ;

func (AnsiDialecter) SupportIndexedParameter

func (ad AnsiDialecter) SupportIndexedParameter() bool

SupportIndexedParameter return false

func (AnsiDialecter) SupportNamedParameter

func (ad AnsiDialecter) SupportNamedParameter() bool

SupportNamedParameter return false

func (AnsiDialecter) TableSql

func (ansi AnsiDialecter) TableSql(name string) string

TableSql return ""

type Column

type Column string

Column is an column, like, table.coumn, column, table.*, *

func (Column) Node

func (c Column) Node() NodeType

Node return NodeColumn

func (Column) Split

func (c Column) Split() (table string, column string)

Split split column and return table and column

func (Column) String

func (c Column) String() string

String

type Compiler

type Compiler interface {
	Compile(source string, exp Expression) (query string, args []interface{}, err error)
}

Compiler is a interface that compile expression to native sql & args

func GetCompiler

func GetCompiler(driver string) (Compiler, error)

GetCompiler return a a compiler by driver name

func NewSqlDriver

func NewSqlDriver(dialecter Dialecter) Compiler

NewSqlDriver return a SqlDriver

type Condition

type Condition struct {
	Right Expression
	Left  Expression
	Op    Operator
}

Condition is condition in where or having

func (*Condition) Node

func (c *Condition) Node() NodeType

Node return NodeCondition

func (*Condition) String

func (c *Condition) String() string

String

type Conditions

type Conditions struct {
	Conditions []Expression
	// contains filtered or unexported fields
}

Conditions is collection of condition

func (*Conditions) And

func (c *Conditions) And() *Conditions

And append logic operation And

func (*Conditions) CloseParentheses

func (c *Conditions) CloseParentheses() *Conditions

CloseParentheses append a ')'

func (*Conditions) Compare

func (c *Conditions) Compare(op Operator, column string, value interface{}) *Conditions

Compare append compare operation

func (*Conditions) Condition

func (c *Conditions) Condition(op Operator, left, right Expression) *Conditions

Condition append a condition

func (*Conditions) Equals

func (c *Conditions) Equals(column string, value interface{}) *Conditions

GreaterThan append = operation

func (*Conditions) Exists

func (c *Conditions) Exists(exp Expression) *Conditions

Exists append operation Exists

func (*Conditions) GreaterOrEquals

func (c *Conditions) GreaterOrEquals(column string, value interface{}) *Conditions

GreaterOrEquals append >= operation

func (*Conditions) GreaterThan

func (c *Conditions) GreaterThan(column string, value interface{}) *Conditions

GreaterThan append > operation

func (*Conditions) In

func (c *Conditions) In(column string, value interface{}) *Conditions

In append in(...) operation

func (*Conditions) IsNotNull

func (c *Conditions) IsNotNull(column string) *Conditions

IsNotNull append is not null operation

func (*Conditions) IsNull

func (c *Conditions) IsNull(column string) *Conditions

IsNull append is null operation

func (*Conditions) LessOrEquals

func (c *Conditions) LessOrEquals(column string, value interface{}) *Conditions

LessOrEquals append <= operation

func (*Conditions) LessThan

func (c *Conditions) LessThan(column string, value interface{}) *Conditions

LessThan append < operation

func (*Conditions) Like

func (c *Conditions) Like(column string, value string) *Conditions

Like append Like operation

func (*Conditions) NotEquals

func (c *Conditions) NotEquals(column string, value interface{}) *Conditions

NotEquals append <> operation

func (*Conditions) NotExists

func (c *Conditions) NotExists(exp Expression) *Conditions

NotExists append operation NotExists

func (*Conditions) NotIn

func (c *Conditions) NotIn(column string, value interface{}) *Conditions

NotIn append not in(...) operation

func (*Conditions) NotLike

func (c *Conditions) NotLike(column string, value string) *Conditions

NotLike append NotLike operation

func (*Conditions) OpenParentheses

func (c *Conditions) OpenParentheses() *Conditions

OpenParentheses append a '('

func (*Conditions) Or

func (c *Conditions) Or() *Conditions

Or append logic operation Or

func (*Conditions) Sql

func (c *Conditions) Sql(sqlStr string) *Conditions

Sql append raw sql

func (*Conditions) String

func (c *Conditions) String() string

String

type DB

type DB struct {
	DSN *DSN
	// contains filtered or unexported fields
}

DB is wrap of *sql.DB

func NewDB

func NewDB(name string) *DB

NewDB return *DB, initialize DSN with provided name

func (*DB) Close

func (db *DB) Close() error

Close close database connection

func (*DB) Compile

func (db *DB) Compile(exp Expression) (sql string, args []interface{}, err error)

Compile compile expression to native sql

func (*DB) DB

func (db *DB) DB() *sql.DB

DB return internal *sql.DB

func (*DB) Delete

func (db *DB) Delete(table string, conditions ...interface{}) (sql.Result, error)

Delete delete table by conditions, conditions format is column, operator, value, ...

func (*DB) DeleteByCol

func (db *DB) DeleteByCol(table string, column string, value interface{}) (sql.Result, error)

DeleteByCol delete table with condition column = value

func (*DB) Exec

func (db *DB) Exec(query string, args ...interface{}) (sql.Result, error)

Exec executes a query that return sql.Result

func (*DB) ExecExp

func (db *DB) ExecExp(exp Expression) (sql.Result, error)

ExecExp execute a expression

func (*DB) ExecFunc

func (db *DB) ExecFunc(name string, args Getter) (sql.Result, error)

ExecFunc exec a store procedure

func (*DB) ExecText

func (db *DB) ExecText(query string, args Getter) (sql.Result, error)

ExecText exec a sql text template

func (*DB) Function

func (db *DB) Function(name string) (fn *ansi.DbFunction, err error)

Function return schema of store procedure

func (*DB) Insert

func (db *DB) Insert(table string, data Getter) (sql.Result, error)

Insert insert data to table

func (*DB) Open

func (db *DB) Open() error

Open open a database conection

func (*DB) Query

func (db *DB) Query(query string, args ...interface{}) (*sql.Rows, error)

Query executes a query that returns *sql.Rows

func (*DB) QueryExp

func (db *DB) QueryExp(exp Expression) (*sql.Rows, error)

QueryExp query a expression

func (*DB) QueryFunc

func (db *DB) QueryFunc(name string, args Getter) (*sql.Rows, error)

QueryFunc query a store procedure

func (*DB) QueryText

func (db *DB) QueryText(template string, args Getter) (*sql.Rows, error)

QueryText query a sql text templete

func (*DB) SelectAll

func (db *DB) SelectAll(table string, conditions ...interface{}) (*sql.Rows, error)

SelectAll return table.* by conditions, conditions format is column, operator, value, ...

func (*DB) SelectCount

func (db *DB) SelectCount(table string, conditions ...interface{}) (count int64, err error)

SelectCount query select count(*) from [table] where conditions...

func (*DB) SelectExists

func (db *DB) SelectExists(table string, conditions ...interface{}) (bool, error)

SelectExists return true if exists conditions

func (*DB) Table

func (db *DB) Table(name string) (table *ansi.DbTable, err error)

Table return schema of table,view

func (*DB) Update

func (db *DB) Update(table string, data Getter, conditions ...interface{}) (sql.Result, error)

Update update a table to data with conditions...

func (*DB) UpdateColumn

func (db *DB) UpdateColumn(table string, column string, value interface{}, conditions ...interface{}) (int64, error)

UpdateColumn exec table.column = value where conditions...

type DSN

type DSN struct {
	// Name is name of data source
	Name string

	// Driver is driver name
	Driver string

	// Source is driver-specific data source name
	Source string
}

DSN is data souce config

func (*DSN) String

func (dsn *DSN) String() string

String

type Delete

type Delete struct {
	//Table is the table to delete
	Table *Table

	// From is from clause
	From *From

	// Where is where clause
	Where *Where

	// OrderBy is order by clause
	OrderBy *OrderBy

	// Count is limit count
	Count int
}

Delete is sql delete clause

func NewDelete

func NewDelete(table string) *Delete

NewDelete return a *Delete with provided table

func (*Delete) Limit

func (d *Delete) Limit(count int) *Delete

Limit set rows count to delete

func (*Delete) Node

func (d *Delete) Node() NodeType

Node return NodeDelete

func (*Delete) String

func (d *Delete) String() string

String

func (*Delete) UseFrom

func (d *Delete) UseFrom(table, alias string) *From

UseFrom new a *From and set to d.From

func (*Delete) UseOrderBy

func (d *Delete) UseOrderBy() *OrderBy

UseOrderBy new a *OrderBy and set to d.OrderBy

type Dialecter

type Dialecter interface {
	// Name return mysql,postgres,oracle,mssql,sqlite,...
	Name() string

	// SupportNamedParameter, like @para1
	SupportNamedParameter() bool

	// SupportIndexedParameter, like $1
	SupportIndexedParameter() bool

	// ParameterPlaceHolder, like ?, $, @
	ParameterPlaceHolder() string

	// QuoteString quote s as sql native string
	QuoteString(s string) string

	// Quote quote object name, like 'table', [table]
	Quote(string) string

	// TableSql return sql to query table schema of name
	TableSql(name string) string

	// ColumnsSql return sql to query table columns schema
	ColumnsSql(name string) string

	// FunctionSql return sql to query function schema of name
	FunctionSql(name string) string

	// ParametersSql return sql to query procedure paramters schema
	ParametersSql(name string) string

	// DbType convert native data type to ansi.DbType
	DbType(nativeType string) ansi.DbType

	// SplitStatement return string to split sql statement; return ; generally
	SplitStatement() string
}

Dialecter is interface of sql dialect

func DefaultDialecter

func DefaultDialecter() Dialecter

DefaultDialecter return AnsiDialecter

func GetDialecter

func GetDialecter(driver string) (Dialecter, error)

GetDialecter return a a dialecter by driver name

type Driver

type Driver interface {
	Compiler
}

func DefaultSQL

func DefaultSQL() Driver

DefaultSQL return a default sql driver

func MSSQL

func MSSQL() Driver

MSSQL return ms sql server driver

func MySql

func MySql() Driver

MySql return mysql driver

func Oracle

func Oracle() Driver

Oracle return oracle driver

func PostgreSQL

func PostgreSQL() Driver

PostgreSQL return postgre sql driver

func SQLite

func SQLite() Driver

SQLite return sqlite driver

type Expression

type Expression interface {
	Node() NodeType
}

Expression is interface of sql expression

type Field

type Field struct {
	Exp   Expression
	Alias string
}

Field is each field in sql select clause

func (*Field) String

func (f *Field) String() string

String

type From

type From struct {
	Table  *Table
	Tables []*Table
	Joins  []*Join
}

From is sql from clause

func NewFrom

func NewFrom(table, alias string) *From

NewFrom return *From

func (*From) CrossJoin

func (f *From) CrossJoin(toTable, toTableAlias string) *Join

Join append cross join to *From

func (*From) FindTable

func (f *From) FindTable(name string) *Table

FindTable return table from *From according name

func (*From) InnerJoin

func (f *From) InnerJoin(toTable, toTableAlias string) *Join

Join append inner join to *From

func (*From) Join

func (f *From) Join(join *Join) *From

Join append *Join to *From

func (*From) LeftJoin

func (f *From) LeftJoin(toTable, toTableAlias string) *Join

Join append left join to *From

func (*From) Node

func (f *From) Node() NodeType

Node return NodeFrom

func (*From) RightJoin

func (f *From) RightJoin(toTable, toTableAlias string) *Join

Join append right join to *From

func (*From) String

func (f *From) String() string

String

func (*From) ThenFrom

func (f *From) ThenFrom(table, alias string) *From

ThenFrom append a table to from

type Func

type Func string

Func is sql function

const (
	Count       Func = ansi.Count
	Sum         Func = ansi.Sum
	Avg         Func = ansi.Avg
	Min         Func = ansi.Min
	Max         Func = ansi.Max
	CurrentTime Func = "currenttime"
)

func (Func) Node

func (f Func) Node() NodeType

Node return NodeFunc

func (Func) String

func (f Func) String() string

String

type GEntity

type GEntity struct {
	Data interface{}
	// contains filtered or unexported fields
}

GEntity wrap a struct, provide interface Getter and Iterater

func Entity

func Entity(data interface{}, filters ...string) *GEntity

Entity wrap a struct, provide interface Getter and Iterater

func (*GEntity) Fields

func (e *GEntity) Fields() []string

Fields return filted field names

func (*GEntity) Get

func (e *GEntity) Get(name string) (interface{}, bool)

Get return field value by name

func (GEntity) String

func (e GEntity) String() string

String

type Getter

type Getter interface {
	// Get return inner field value by name, return [nil, false] if name doesn't exist
	Get(name string) (interface{}, bool)
}

Getter is wrap of Get(name string) (interface{}, bool)

type GroupBy

type GroupBy struct {
	Fields []Expression
}

GroupBy is sql group by clause

func NewGroupBy

func NewGroupBy() *GroupBy

NewGroupBy return *GroupBy

func (*GroupBy) By

func (g *GroupBy) By(exp Expression) *GroupBy

By append a expression

func (*GroupBy) Column

func (g *GroupBy) Column(columns ...string) *GroupBy

Column append columns

func (*GroupBy) Node

func (g *GroupBy) Node() NodeType

Node return Node()

func (*GroupBy) String

func (g *GroupBy) String() string

String

type Having

type Having struct {
	*Conditions
}

Having is sql having clause

func NewHaving

func NewHaving() *Having

NewHaving return *Having

func (*Having) Avg

func (h *Having) Avg(op Operator, column string, value interface{}) *Having

Avg append avg(...)

func (*Having) Count

func (h *Having) Count(op Operator, column string, value interface{}) *Having

Count append count(...)

func (*Having) Max

func (h *Having) Max(op Operator, column string, value interface{}) *Having

Max append max(...)

func (*Having) Min

func (h *Having) Min(op Operator, column string, value interface{}) *Having

Min append min(...)

func (*Having) Node

func (h *Having) Node() NodeType

Node return NodeHaving

func (*Having) String

func (h *Having) String() string

String

func (*Having) Sum

func (h *Having) Sum(op Operator, column string, value interface{}) *Having

Sum append sum(...)

type Insert

type Insert struct {
	// Table is table to insert
	Table *Table

	// Sets is set[column=value]
	Sets []*Set
}

Insert is sql "insert into x values(...)" clause

func NewInsert

func NewInsert(table string) *Insert

NewInsert return *Insert with provided table

func (*Insert) Append

func (ist *Insert) Append(a *Set)

Append Append an *Set

func (*Insert) Node

func (ist *Insert) Node() NodeType

Node return NodeInsert

func (*Insert) Set

func (ist *Insert) Set(column string, value interface{}) *Insert

Set is shortcut of Append

func (*Insert) String

func (ist *Insert) String() string

String

type Iterater

type Iterater interface {
	// Fields return all field name
	Fields() []string
}

Iterater iterat fields

type Join

type Join struct {
	JoinType JoinType
	Left     *Table
	Right    *Table
	*Conditions
}

Join is sql join clause

func NewJoin

func NewJoin(joinType JoinType, left, leftAlias, right, rightAlias string) *Join

NewJoin means [left] as [leftAlias] join [right] as [rightAlias]

func NewJoinTable

func NewJoinTable(joinType JoinType, left, right *Table) *Join

NewJoinTable means [left] join [right]

func (*Join) Node

func (j *Join) Node() NodeType

Node return NodeJoin

func (*Join) On

func (j *Join) On(leftColumn, rightColumn string)

On means on leftColumn = rightColumn

func (*Join) On2

func (j *Join) On2(leftColumn1, rightColumn1, leftColumn2, rightColumn2 string)

On means on leftColumn1 = rightColumn1 and leftColumn2 = rightColumn2

func (*Join) String

func (j *Join) String() string

String

type JoinType

type JoinType string

JoinType is type of sql table join

const (
	CrossJoin JoinType = ansi.CrossJoin
	InnerJoin JoinType = ansi.InnerJoin
	LeftJoin  JoinType = ansi.LeftJoin
	RightJoin JoinType = ansi.RightJoin
)

func (JoinType) String

func (j JoinType) String() string

String

func (JoinType) ToSql

func (j JoinType) ToSql() string

ToSql return vative sql of JoinType(left join, right join...)

type Map

type Map map[string]interface{}

Map is alias of map[string]interface{}

func (Map) Fields

func (m Map) Fields() []string

Fields return all map keys

func (Map) Get

func (m Map) Get(name string) (interface{}, bool)

Get return map element by name

type MssqlDialecter

type MssqlDialecter struct {
	AnsiDialecter
}

MssqlDialecter is ms sql server dialect

func (MssqlDialecter) ColumnsSql

func (mssql MssqlDialecter) ColumnsSql(name string) string

ColumnsSql return sql to query table columns schema

func (MssqlDialecter) FunctionSql

func (mssql MssqlDialecter) FunctionSql(name string) string

FunctionSql return sql to query procedure schema

func (MssqlDialecter) Name

func (mssql MssqlDialecter) Name() string

Name return "mssql"

func (MssqlDialecter) ParametersSql

func (mssql MssqlDialecter) ParametersSql(name string) string

ParametersSql return sql to query procedure paramters schema

func (MssqlDialecter) Quote

func (mssql MssqlDialecter) Quote(s string) string

Quote quote s as [s]

func (MssqlDialecter) TableSql

func (mssql MssqlDialecter) TableSql(name string) string

TableSql return sql to query table schema

type MysqlDialecter

type MysqlDialecter struct {
	AnsiDialecter
}

MysqlDialecter is Mysql dialect

func (MysqlDialecter) ColumnsSql

func (mysql MysqlDialecter) ColumnsSql(name string) string

ColumnsSql return sql to query table columns schema

func (MysqlDialecter) FunctionSql

func (mysql MysqlDialecter) FunctionSql(name string) string

FunctionSql return sql to query procedure schema

func (MysqlDialecter) Name

func (mysql MysqlDialecter) Name() string

Name return "mysql"

func (MysqlDialecter) ParametersSql

func (mysql MysqlDialecter) ParametersSql(name string) string

ParametersSql return sql to query procedure paramters schema

func (MysqlDialecter) Quote

func (mysql MysqlDialecter) Quote(s string) string

Quote quote s as 's'

func (MysqlDialecter) QuoteString

func (mysql MysqlDialecter) QuoteString(s string) string

QuoteString quote s as sql native string

func (MysqlDialecter) TableSql

func (mysql MysqlDialecter) TableSql(name string) string

TableSql return sql to query table schema

type NodeType

type NodeType int

NodeType

const (
	NodeZero      NodeType = 0
	NodeText      NodeType = 1
	NodeProcedure NodeType = 2
	NodeInsert    NodeType = 3
	NodeQuery     NodeType = 4
	NodeUpdate    NodeType = 5
	NodeDelete    NodeType = 6

	NodeNull  NodeType = 11
	NodeValue NodeType = 12
	NodeSql   NodeType = 13

	NodeTable     NodeType = 31
	NodeColumn    NodeType = 32
	NodeAlias     NodeType = 33
	NodeCondition NodeType = 34
	NodeSet       NodeType = 35
	NodeAggregate NodeType = 36

	NodeSelect  NodeType = 41
	NodeFrom    NodeType = 42
	NodeJoin    NodeType = 43
	NodeWhere   NodeType = 44
	NodeGroupBy NodeType = 45
	NodeHaving  NodeType = 46
	NodeOrderBy NodeType = 47
	NodeOutput  NodeType = 48

	NodeOperator  = 61
	NodeFunc      = 62
	NodeParameter = 63
)

func (NodeType) String

func (n NodeType) String() string

String

type Null

type Null string

Null is null in database

const DbNull Null = ansi.Null

DbNull mean null in database

func (Null) Node

func (n Null) Node() NodeType

Node return NodeNull

func (Null) String

func (n Null) String() string

String

func (Null) ToSql

func (n Null) ToSql() string

ToSql return null

type Operator

type Operator string

Operator is operator in sql

const (
	IsNull           Operator = ansi.IsNull
	IsNotNull        Operator = ansi.IsNotNull
	LessThan         Operator = ansi.LessThan
	LessOrEquals     Operator = ansi.LessOrEquals
	GreaterThan      Operator = ansi.GreaterThan
	GreaterOrEquals  Operator = ansi.GreaterOrEquals
	Equals           Operator = ansi.Equals
	NotEquals        Operator = ansi.NotEquals
	Like             Operator = ansi.Like
	NotLike          Operator = ansi.NotLike
	In               Operator = ansi.In
	NotIn            Operator = ansi.NotIn
	Exists           Operator = ansi.Exists
	NotExists        Operator = ansi.NotExists
	All              Operator = ansi.All
	Some             Operator = ansi.Some
	Any              Operator = ansi.Any
	And              Operator = ansi.And
	Or               Operator = ansi.Or
	OpenParentheses  Operator = ansi.OpenParentheses
	CloseParentheses Operator = ansi.CloseParentheses
)

func (Operator) Node

func (op Operator) Node() NodeType

Node return NodeOperator

func (Operator) String

func (op Operator) String() string

String

func (Operator) ToSql

func (op Operator) ToSql() string

ToSql return native sql of operator(>,<,=,<>,...)

type OracleSQLDialecter

type OracleSQLDialecter struct {
	AnsiDialecter
}

OracleSQLDialecter is oracle dialect

func (OracleSQLDialecter) ColumnsSql

func (oracle OracleSQLDialecter) ColumnsSql(name string) string

Columns return sql to query table columns schema

func (OracleSQLDialecter) FunctionSql

func (oracle OracleSQLDialecter) FunctionSql(name string) string

Function return sql to query procedure schema

func (OracleSQLDialecter) Name

func (oracle OracleSQLDialecter) Name() string

Name return "oracle"

func (OracleSQLDialecter) ParameterPlaceHolder

func (oracle OracleSQLDialecter) ParameterPlaceHolder() string

ParameterPlaceHolder return :

func (OracleSQLDialecter) ParametersSql

func (oracle OracleSQLDialecter) ParametersSql(name string) string

Parameters return sql to query procedure paramters schema

func (OracleSQLDialecter) Quote

func (oracle OracleSQLDialecter) Quote(s string) string

Quote doesn't quote identifier

func (OracleSQLDialecter) SplitStatement

func (oracle OracleSQLDialecter) SplitStatement() string

SplitStatement return nothing

func (OracleSQLDialecter) SupportIndexedParameter

func (oracle OracleSQLDialecter) SupportIndexedParameter() bool

SupportIndexedParameter regturn true

func (OracleSQLDialecter) SupportNamedParameter

func (oracle OracleSQLDialecter) SupportNamedParameter() bool

SupportNamedParameter return true

func (OracleSQLDialecter) TableSql

func (oracle OracleSQLDialecter) TableSql(name string) string

Table return sql to query table schema

type OrderBy

type OrderBy struct {
	Fields []*OrderByField
}

OrderBy is sql order by clause

func NewOrderBy

func NewOrderBy() *OrderBy

NewOrderBy return *OrderBy

func (*OrderBy) Asc

func (od *OrderBy) Asc(columns ...string) *OrderBy

Asc append a column to order by as asc

func (*OrderBy) By

func (od *OrderBy) By(direction SortDir, exp Expression) *OrderBy

By append a orderby field with direction

func (*OrderBy) Desc

func (od *OrderBy) Desc(columns ...string) *OrderBy

Desc append a column to order by as desc

func (*OrderBy) Node

func (od *OrderBy) Node() NodeType

Node return NodeOrderBy

func (*OrderBy) String

func (od *OrderBy) String() string

String

type OrderByField

type OrderByField struct {
	Exp       Expression
	Direction SortDir
}

OrderByField is each field in sql order by clause

func (*OrderByField) String

func (oi *OrderByField) String() string

String

type Parameter

type Parameter struct {
	// Name is parameter name, some driver don't support named parameter
	Name string

	// Value is value of this parameter
	Value interface{}

	// Dir is direction, in,out, inout or return
	Dir ansi.Dir
}

Parameter is parameter of sql statement or store procedure

func (*Parameter) IsIn

func (p *Parameter) IsIn() bool

IsIn return true if parameter is input/inputoutput parameter

func (*Parameter) IsOut

func (p *Parameter) IsOut() bool

IsOut return true if parameter is output/inputoutput parameter

func (*Parameter) Node

func (p *Parameter) Node() NodeType

Node return NodeParameter

func (*Parameter) String

func (p *Parameter) String() string

String

type PostgreSQLDialecter

type PostgreSQLDialecter struct {
	AnsiDialecter
}

PostgreSQLDialecter is PostgreSQL dialect

func (PostgreSQLDialecter) ColumnsSql

func (pgsql PostgreSQLDialecter) ColumnsSql(name string) string

Columns return sql to query table columns schema

func (PostgreSQLDialecter) FunctionSql

func (pgsql PostgreSQLDialecter) FunctionSql(name string) string

Function return sql to query procedure schema

func (PostgreSQLDialecter) Name

func (pgsql PostgreSQLDialecter) Name() string

Name return "postgres"

func (PostgreSQLDialecter) ParameterPlaceHolder

func (pgsql PostgreSQLDialecter) ParameterPlaceHolder() string

ParameterPlaceHolder return $

func (PostgreSQLDialecter) ParametersSql

func (pgsql PostgreSQLDialecter) ParametersSql(name string) string

Parameters return sql to query procedure paramters schema

func (PostgreSQLDialecter) Quote

func (pgsql PostgreSQLDialecter) Quote(s string) string

Quote quote s as 's'

func (PostgreSQLDialecter) QuoteString

func (pgsql PostgreSQLDialecter) QuoteString(s string) string

QuoteString quote s as sql native string

func (PostgreSQLDialecter) SupportIndexedParameter

func (pgsql PostgreSQLDialecter) SupportIndexedParameter() bool

SupportIndexedParameter regturn true

func (PostgreSQLDialecter) TableSql

func (pgsql PostgreSQLDialecter) TableSql(name string) string

Table return sql to query table schema

type Procedure

type Procedure struct {
	// Name is name of store procedure ot function
	Name string

	// Parameters is parameters of store procedure
	Parameters []*Parameter
}

Procedure is sql store procedure

func NewProcedure

func NewProcedure(name string) *Procedure

NewProcedure return a *Procedure with provided name

func (*Procedure) FindParameter

func (pc *Procedure) FindParameter(name string) (*Parameter, bool)

FindParameter return a parameter by name

func (*Procedure) HasOutParameter

func (t *Procedure) HasOutParameter() bool

HasOutParameter return true if any parameter is output/inputoutput

func (*Procedure) Node

func (pc *Procedure) Node() NodeType

Node return NodeProcedure

func (*Procedure) Parameter

func (pc *Procedure) Parameter(p *Parameter)

Parameter append a paramter

func (*Procedure) ReturnParameterName

func (pc *Procedure) ReturnParameterName() string

ReturnParameterName return parameter name if parameter is ansi.DirReturn

func (*Procedure) Set

func (pc *Procedure) Set(name string, value interface{}) *Procedure

Set is shortcut of Parameter

func (*Procedure) SetDir

func (pc *Procedure) SetDir(name string, value interface{}, dir ansi.Dir) *Procedure

SetDir append a Parameter

func (*Procedure) String

func (pc *Procedure) String() string

String

type Query

type Query struct {
	Select     *Select
	From       *From
	Where      *Where
	GroupBy    *GroupBy
	Having     *Having
	OrderBy    *OrderBy
	IsDistinct bool
	Offset     int
	Count      int
}

Query is sql query clause

func NewQuery

func NewQuery(table, alias string) *Query

NewQuery return *Query

func (*Query) Distinct

func (q *Query) Distinct() *Query

Distinct set IsDistinct = true

func (*Query) Limit

func (q *Query) Limit(offset, count int) *Query

Limit set offset and count

func (*Query) Node

func (q *Query) Node() NodeType

Node return NodeQuery

func (*Query) String

func (q *Query) String() string

String

func (*Query) UseGroupBy

func (q *Query) UseGroupBy() *GroupBy

UseGroupBy initialize q.GroupBy then return it

func (*Query) UseHaving

func (q *Query) UseHaving() *Having

UseHaving initialize q.Having then return it

func (*Query) UseOrderBy

func (q *Query) UseOrderBy() *OrderBy

UseOrderBy initialize q.OrderBy then return it

type RawSqler

type RawSqler interface {
	// ToSql return native sql
	ToSql() string
}

RawSqler is wrap of ToSql() string

type Schemaer

type Schemaer interface {
	// Table return schema of table,view
	Table(db *sql.DB, name string) (*ansi.DbTable, error)

	// Function return schema of store procedure,function
	Function(db *sql.DB, name string) (*ansi.DbFunction, error)
}

Schemaer is a interface that get schema of table,view,function

func GetSchemaer

func GetSchemaer(driver string) (Schemaer, error)

GetSchemaer return a a schemaer by driver name

type Select

type Select struct {
	Fields []*Field
}

Select is sql select clause

func NewSelect

func NewSelect() *Select

NewSelect return *Select

func (*Select) Aggregate

func (s *Select) Aggregate(name Func, exp Expression, alias string) *Select

Aggregate append a aggregate function

func (*Select) All

func (s *Select) All() *Select

All append *

func (*Select) Avg

func (s *Select) Avg(column string, alias string) *Select

Avg append avg(...)

func (*Select) Column

func (s *Select) Column(columns ...string) *Select

Column append columns to select list

func (*Select) ColumnAs

func (s *Select) ColumnAs(column, alias string) *Select

ColumnAs append [column] as [alias] to select list

func (*Select) Count

func (s *Select) Count(column string, alias string) *Select

Count append count(...)

func (*Select) Exp

func (s *Select) Exp(exp Expression, alias string) *Select

Exp append a expression

func (*Select) Max

func (s *Select) Max(column string, alias string) *Select

Max append max(...)

func (*Select) Min

func (s *Select) Min(column string, alias string) *Select

Min append min(...)

func (*Select) Node

func (s *Select) Node() NodeType

Node return NodeSelect

func (*Select) String

func (s *Select) String() string

String

func (*Select) Sum

func (s *Select) Sum(column string, alias string) *Select

Sum append sum(...)

type Set

type Set struct {
	Column Column
	Value  Expression
}

Set is set clause in update or insert

func (*Set) Node

func (a *Set) Node() NodeType

Node return NodeSet

func (*Set) String

func (a *Set) String() string

String

type SortDir

type SortDir string

SortDir is direction of orderby

const (
	Asc  SortDir = ansi.Asc
	Desc SortDir = ansi.Desc
)

func (SortDir) String

func (sd SortDir) String() string

String

func (SortDir) ToSql

func (sd SortDir) ToSql() string

ToSql return native sql of SortDir(asc/desc)

type Sql

type Sql string

Sql is sql statement

func (Sql) Node

func (s Sql) Node() NodeType

Node return NodeSql

func (Sql) String

func (s Sql) String() string

String

func (Sql) ToSql

func (s Sql) ToSql() string

ToSql return Sql

type SqlDriver

type SqlDriver struct {
	Dialecter Dialecter
}

SqlDriver is ansi sql compiler

func (*SqlDriver) Compile

func (c *SqlDriver) Compile(source string, exp Expression) (query string, args []interface{}, err error)

Compile compile expression to ansi sql

type SqliteDialecter

type SqliteDialecter struct {
	AnsiDialecter
}

SqliteDialecter is sqlite dialect

func (SqliteDialecter) Function

func (sqlite SqliteDialecter) Function(db *sql.DB, name string) (*ansi.DbFunction, error)

Function return schema of store procedure,function

func (SqliteDialecter) Name

func (sqlite SqliteDialecter) Name() string

Name return "mssql"

func (SqliteDialecter) Table

func (sqlite SqliteDialecter) Table(db *sql.DB, name string) (table *ansi.DbTable, err error)

Table return schema of table,view

type StmtCompiler

type StmtCompiler struct {
	// Dialecter is a provided Dialecter
	Dialecter Dialecter
	// contains filtered or unexported fields
}

StmtCompiler can compile Update, Insert, Delete, Query

func NewStmtCompiler

func NewStmtCompiler(dialecter Dialecter) *StmtCompiler

NewStmtCompiler return *StmtCompiler with provided Dialecter

func (*StmtCompiler) Compile

func (sc *StmtCompiler) Compile(exp Expression, source string) (query string, args []interface{}, err error)

Compile compile expression to ansi sql

type Table

type Table struct {
	Name  string
	Alias string
}

Table is tables in sql from clasuse

func (*Table) Node

func (t *Table) Node() NodeType

Node return NodeTable

func (*Table) String

func (t *Table) String() string

String

type Text

type Text struct {
	// Sql is raw sql statement
	Sql string

	// Parameters is parameters of Sql
	Parameters []*Parameter
}

Text is sql statement

func NewText

func NewText(sql string) *Text

NewText return a *Text with provided sql statement

func (*Text) FindParameter

func (t *Text) FindParameter(name string) (*Parameter, bool)

FindParameter return a paramter by name

func (*Text) Node

func (t *Text) Node() NodeType

Node return NodeText

func (*Text) Parameter

func (t *Text) Parameter(p *Parameter)

Parameter append a paramter

func (*Text) Set

func (t *Text) Set(name string, value interface{}) *Text

Set is shortcut of Parameter

func (*Text) String

func (t *Text) String() string

String

type Update

type Update struct {
	//T able is table to update
	Table *Table

	// Sets is set[column=value]
	Sets []*Set

	// Where is where clause
	Where *Where

	// OrderBy is order by clause
	OrderBy *OrderBy

	// Count is limit count
	Count int
}

Update is sql update clause

func NewUpdate

func NewUpdate(table string) *Update

func (*Update) Append

func (u *Update) Append(a *Set)

Append Append an *Set

func (*Update) Limit

func (u *Update) Limit(count int) *Update

Limit set rows count to update

func (*Update) Node

func (u *Update) Node() NodeType

Node return NodeUpdate

func (*Update) Set

func (u *Update) Set(column string, value interface{}) *Update

Set is shortcut of Append

func (*Update) String

func (u *Update) String() string

String

type Value

type Value struct {
	// Value is embed value
	Value interface{}
}

Value is raw value

func (*Value) Node

func (v *Value) Node() NodeType

Node return NodeValue

func (*Value) String

func (v *Value) String() string

String

type Where

type Where struct {
	*Conditions
}

Where is sql where clause

func NewWhere

func NewWhere() *Where

NewWhere return *Where

func (*Where) Node

func (w *Where) Node() NodeType

Node return NodeWhere

func (*Where) String

func (w *Where) String() string

String

Directories

Path Synopsis
ansi package is keywords, datatyp, schema of ansi sql
ansi package is keywords, datatyp, schema of ansi sql
example of mysql
example of mysql

Jump to

Keyboard shortcuts

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