builder

package module
Version: v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2019 License: BSD-3-Clause Imports: 11 Imported by: 203

README

SQL builder

GitCI.cn codecov

Package builder is a lightweight and fast SQL builder for Go and XORM.

Make sure you have installed Go 1.8+ and then:

go get github.com/go-xorm/builder

Insert

sql, args, err := builder.Insert(Eq{"c": 1, "d": 2}).Into("table1").ToSQL()

// INSERT INTO table1 SELECT * FROM table2
sql, err := builder.Insert().Into("table1").Select().From("table2").ToBoundSQL()

// INSERT INTO table1 (a, b) SELECT b, c FROM table2
sql, err = builder.Insert("a, b").Into("table1").Select("b, c").From("table2").ToBoundSQL()

Select

// Simple Query
sql, args, err := Select("c, d").From("table1").Where(Eq{"a": 1}).ToSQL()
// With join
sql, args, err = Select("c, d").From("table1").LeftJoin("table2", Eq{"table1.id": 1}.And(Lt{"table2.id": 3})).
		RightJoin("table3", "table2.id = table3.tid").Where(Eq{"a": 1}).ToSQL()
// From sub query
sql, args, err := Select("sub.id").From(Select("c").From("table1").Where(Eq{"a": 1}), "sub").Where(Eq{"b": 1}).ToSQL()
// From union query
sql, args, err = Select("sub.id").From(
	Select("id").From("table1").Where(Eq{"a": 1}).Union("all", Select("id").From("table1").Where(Eq{"a": 2})),"sub").
	Where(Eq{"b": 1}).ToSQL()
// With order by
sql, args, err = Select("a", "b", "c").From("table1").Where(Eq{"f1": "v1", "f2": "v2"}).
		OrderBy("a ASC").ToSQL()
// With limit.
// Be careful! You should set up specific dialect for builder before performing a query with LIMIT
sql, args, err = Dialect(MYSQL).Select("a", "b", "c").From("table1").OrderBy("a ASC").
		Limit(5, 10).ToSQL()

Update

sql, args, err := Update(Eq{"a": 2}).From("table1").Where(Eq{"a": 1}).ToSQL()

Delete

sql, args, err := Delete(Eq{"a": 1}).From("table1").ToSQL()

Union

sql, args, err := Select("*").From("a").Where(Eq{"status": "1"}).
		Union("all", Select("*").From("a").Where(Eq{"status": "2"})).
		Union("distinct", Select("*").From("a").Where(Eq{"status": "3"})).
		Union("", Select("*").From("a").Where(Eq{"status": "4"})).
		ToSQL()

Conditions

  • Eq is a redefine of a map, you can give one or more conditions to Eq
import . "github.com/go-xorm/builder"

sql, args, _ := ToSQL(Eq{"a":1})
// a=? [1]
sql, args, _ := ToSQL(Eq{"b":"c"}.And(Eq{"c": 0}))
// b=? AND c=? ["c", 0]
sql, args, _ := ToSQL(Eq{"b":"c", "c":0})
// b=? AND c=? ["c", 0]
sql, args, _ := ToSQL(Eq{"b":"c"}.Or(Eq{"b":"d"}))
// b=? OR b=? ["c", "d"]
sql, args, _ := ToSQL(Eq{"b": []string{"c", "d"}})
// b IN (?,?) ["c", "d"]
sql, args, _ := ToSQL(Eq{"b": 1, "c":[]int{2, 3}})
// b=? AND c IN (?,?) [1, 2, 3]
  • Neq is the same to Eq
import . "github.com/go-xorm/builder"

sql, args, _ := ToSQL(Neq{"a":1})
// a<>? [1]
sql, args, _ := ToSQL(Neq{"b":"c"}.And(Neq{"c": 0}))
// b<>? AND c<>? ["c", 0]
sql, args, _ := ToSQL(Neq{"b":"c", "c":0})
// b<>? AND c<>? ["c", 0]
sql, args, _ := ToSQL(Neq{"b":"c"}.Or(Neq{"b":"d"}))
// b<>? OR b<>? ["c", "d"]
sql, args, _ := ToSQL(Neq{"b": []string{"c", "d"}})
// b NOT IN (?,?) ["c", "d"]
sql, args, _ := ToSQL(Neq{"b": 1, "c":[]int{2, 3}})
// b<>? AND c NOT IN (?,?) [1, 2, 3]
  • Gt, Gte, Lt, Lte
import . "github.com/go-xorm/builder"

sql, args, _ := ToSQL(Gt{"a", 1}.And(Gte{"b", 2}))
// a>? AND b>=? [1, 2]
sql, args, _ := ToSQL(Lt{"a", 1}.Or(Lte{"b", 2}))
// a<? OR b<=? [1, 2]
  • Like
import . "github.com/go-xorm/builder"

sql, args, _ := ToSQL(Like{"a", "c"})
// a LIKE ? [%c%]
  • Expr you can customerize your sql with Expr
import . "github.com/go-xorm/builder"

sql, args, _ := ToSQL(Expr("a = ? ", 1))
// a = ? [1]
sql, args, _ := ToSQL(Eq{"a": Expr("select id from table where c = ?", 1)})
// a=(select id from table where c = ?) [1]
  • In and NotIn
import . "github.com/go-xorm/builder"

sql, args, _ := ToSQL(In("a", 1, 2, 3))
// a IN (?,?,?) [1,2,3]
sql, args, _ := ToSQL(In("a", []int{1, 2, 3}))
// a IN (?,?,?) [1,2,3]
sql, args, _ := ToSQL(In("a", Expr("select id from b where c = ?", 1))))
// a IN (select id from b where c = ?) [1]
  • IsNull and NotNull
import . "github.com/go-xorm/builder"

sql, args, _ := ToSQL(IsNull{"a"})
// a IS NULL []
sql, args, _ := ToSQL(NotNull{"b"})
	// b IS NOT NULL []
  • And(conds ...Cond), And can connect one or more condtions via And
import . "github.com/go-xorm/builder"

sql, args, _ := ToSQL(And(Eq{"a":1}, Like{"b", "c"}, Neq{"d", 2}))
// a=? AND b LIKE ? AND d<>? [1, %c%, 2]
  • Or(conds ...Cond), Or can connect one or more conditions via Or
import . "github.com/go-xorm/builder"

sql, args, _ := ToSQL(Or(Eq{"a":1}, Like{"b", "c"}, Neq{"d", 2}))
// a=? OR b LIKE ? OR d<>? [1, %c%, 2]
sql, args, _ := ToSQL(Or(Eq{"a":1}, And(Like{"b", "c"}, Neq{"d", 2})))
// a=? OR (b LIKE ? AND d<>?) [1, %c%, 2]
  • Between
import . "github.com/go-xorm/builder"

sql, args, _ := ToSQL(Between{"a", 1, 2})
// a BETWEEN 1 AND 2
  • Define yourself conditions

Since Cond is an interface.

type Cond interface {
	WriteTo(Writer) error
	And(...Cond) Cond
	Or(...Cond) Cond
	IsValid() bool
}

You can define yourself conditions and compose with other Cond.

Documentation

Overview

Package builder is a simple and powerful sql builder for Go.

Make sure you have installed Go 1.1+ and then:

go get github.com/go-xorm/builder

WARNNING: Currently, only query conditions are supported. Below is the supported conditions.

1. Eq is a redefine of a map, you can give one or more conditions to Eq

import . "github.com/go-xorm/builder"

sql, args, _ := ToSQL(Eq{"a":1})
// a=? [1]
sql, args, _ := ToSQL(Eq{"b":"c"}.And(Eq{"c": 0}))
// b=? AND c=? ["c", 0]
sql, args, _ := ToSQL(Eq{"b":"c", "c":0})
// b=? AND c=? ["c", 0]
sql, args, _ := ToSQL(Eq{"b":"c"}.Or(Eq{"b":"d"}))
// b=? OR b=? ["c", "d"]
sql, args, _ := ToSQL(Eq{"b": []string{"c", "d"}})
// b IN (?,?) ["c", "d"]
sql, args, _ := ToSQL(Eq{"b": 1, "c":[]int{2, 3}})
// b=? AND c IN (?,?) [1, 2, 3]

2. Neq is the same to Eq

import . "github.com/go-xorm/builder"

sql, args, _ := ToSQL(Neq{"a":1})
// a<>? [1]
sql, args, _ := ToSQL(Neq{"b":"c"}.And(Neq{"c": 0}))
// b<>? AND c<>? ["c", 0]
sql, args, _ := ToSQL(Neq{"b":"c", "c":0})
// b<>? AND c<>? ["c", 0]
sql, args, _ := ToSQL(Neq{"b":"c"}.Or(Neq{"b":"d"}))
// b<>? OR b<>? ["c", "d"]
sql, args, _ := ToSQL(Neq{"b": []string{"c", "d"}})
// b NOT IN (?,?) ["c", "d"]
sql, args, _ := ToSQL(Neq{"b": 1, "c":[]int{2, 3}})
// b<>? AND c NOT IN (?,?) [1, 2, 3]

3. Gt, Gte, Lt, Lte

import . "github.com/go-xorm/builder"

sql, args, _ := ToSQL(Gt{"a", 1}.And(Gte{"b", 2}))
// a>? AND b>=? [1, 2]
sql, args, _ := ToSQL(Lt{"a", 1}.Or(Lte{"b", 2}))
// a<? OR b<=? [1, 2]

4. Like

import . "github.com/go-xorm/builder"

sql, args, _ := ToSQL(Like{"a", "c"})
// a LIKE ? [%c%]

5. Expr you can customerize your sql with Expr

import . "github.com/go-xorm/builder"

sql, args, _ := ToSQL(Expr("a = ? ", 1))
// a = ? [1]
sql, args, _ := ToSQL(Eq{"a": Expr("select id from table where c = ?", 1)})
// a=(select id from table where c = ?) [1]

6. In and NotIn

import . "github.com/go-xorm/builder"

sql, args, _ := ToSQL(In("a", 1, 2, 3))
// a IN (?,?,?) [1,2,3]
sql, args, _ := ToSQL(In("a", []int{1, 2, 3}))
// a IN (?,?,?) [1,2,3]
sql, args, _ := ToSQL(In("a", Expr("select id from b where c = ?", 1))))
// a IN (select id from b where c = ?) [1]

7. IsNull and NotNull

import . "github.com/go-xorm/builder"

sql, args, _ := ToSQL(IsNull{"a"})
// a IS NULL []
sql, args, _ := ToSQL(NotNull{"b"})
 // b IS NOT NULL []

8. And(conds ...Cond), And can connect one or more condtions via AND

import . "github.com/go-xorm/builder"

sql, args, _ := ToSQL(And(Eq{"a":1}, Like{"b", "c"}, Neq{"d", 2}))
// a=? AND b LIKE ? AND d<>? [1, %c%, 2]

9. Or(conds ...Cond), Or can connect one or more conditions via Or

import . "github.com/go-xorm/builder"

sql, args, _ := ToSQL(Or(Eq{"a":1}, Like{"b", "c"}, Neq{"d", 2}))
// a=? OR b LIKE ? OR d<>? [1, %c%, 2]
sql, args, _ := ToSQL(Or(Eq{"a":1}, And(Like{"b", "c"}, Neq{"d", 2})))
// a=? OR (b LIKE ? AND d<>?) [1, %c%, 2]

10. Between

import . "github.com/go-xorm/builder"

sql, args, _ := ToSQL(Between("a", 1, 2))
// a BETWEEN 1 AND 2

11. define yourself conditions Since Cond is a interface, you can define yourself conditions and compare with them

Index

Constants

View Source
const (
	POSTGRES = "postgres"
	SQLITE   = "sqlite3"
	MYSQL    = "mysql"
	MSSQL    = "mssql"
	ORACLE   = "oracle"
)

Variables

View Source
var (
	// ErrNotSupportType not supported SQL type error
	ErrNotSupportType = errors.New("Not supported SQL type")
	// ErrNoNotInConditions no NOT IN params error
	ErrNoNotInConditions = errors.New("No NOT IN conditions")
	// ErrNoInConditions no IN params error
	ErrNoInConditions = errors.New("No IN conditions")
	// ErrNeedMoreArguments need more arguments
	ErrNeedMoreArguments = errors.New("Need more sql arguments")
	// ErrNoTableName no table name
	ErrNoTableName = errors.New("No table indicated")
	// ErrNoColumnToInsert no column to update
	ErrNoColumnToUpdate = errors.New("No column(s) to update")
	// ErrNoColumnToInsert no column to update
	ErrNoColumnToInsert = errors.New("No column(s) to insert")
	// ErrNotSupportDialectType not supported dialect type error
	ErrNotSupportDialectType = errors.New("Not supported dialect type")
	// ErrNotUnexpectedUnionConditions using union in a wrong way
	ErrNotUnexpectedUnionConditions = errors.New("Unexpected conditional fields in UNION query")
	// ErrUnsupportedUnionMembers unexpected members in UNION query
	ErrUnsupportedUnionMembers = errors.New("Unexpected members in UNION query")
	// ErrUnexpectedSubQuery Unexpected sub-query in SELECT query
	ErrUnexpectedSubQuery = errors.New("Unexpected sub-query in SELECT query")
	// ErrDialectNotSetUp dialect is not setup yet
	ErrDialectNotSetUp = errors.New("Dialect is not setup yet, try to use `Dialect(dbType)` at first")
	// ErrInvalidLimitation offset or limit is not correct
	ErrInvalidLimitation = errors.New("Offset or limit is not correct")
	// ErrUnnamedDerivedTable Every derived table must have its own alias
	ErrUnnamedDerivedTable = errors.New("Every derived table must have its own alias")
	// ErrInconsistentDialect Inconsistent dialect in same builder
	ErrInconsistentDialect = errors.New("Inconsistent dialect in same builder")
)

Functions

func ConvertPlaceholder added in v0.3.0

func ConvertPlaceholder(sql, prefix string) (string, error)

ConvertPlaceholder replaces ? to $1, $2 ... or :1, :2 ... according prefix

func ConvertToBoundSQL added in v0.3.1

func ConvertToBoundSQL(sql string, args []interface{}) (string, error)

ConvertToBoundSQL will convert SQL and args to a bound SQL

func ToBoundSQL added in v0.3.1

func ToBoundSQL(cond interface{}) (string, error)

ToBoundSQL convert a builder or conditions to parameters bound SQL

func ToSQL

func ToSQL(cond interface{}) (string, []interface{}, error)

ToSQL convert a builder or conditions to SQL and args

func WriteMap

func WriteMap(w Writer, data map[string]interface{}, op string) error

WriteMap writes conditions' SQL to Writer, op could be =, <>, >, <, <=, >= and etc.

Types

type Between

type Between struct {
	Col     string
	LessVal interface{}
	MoreVal interface{}
}

Between implmentes between condition

func (Between) And

func (between Between) And(conds ...Cond) Cond

And implments And with other conditions

func (Between) IsValid

func (between Between) IsValid() bool

IsValid tests if the condition is valid

func (Between) Or

func (between Between) Or(conds ...Cond) Cond

Or implments Or with other conditions

func (Between) WriteTo

func (between Between) WriteTo(w Writer) error

WriteTo write data to Writer

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder describes a SQL statement

func Delete

func Delete(conds ...Cond) *Builder

Delete creates a delete Builder

func Dialect added in v0.3.1

func Dialect(dialect string) *Builder

Dialect sets the db dialect of Builder.

func Insert

func Insert(eq ...interface{}) *Builder

Insert creates an insert Builder

func MsSQL added in v0.3.2

func MsSQL() *Builder

MsSQL is shortcut of Dialect(MsSQL)

func MySQL added in v0.3.2

func MySQL() *Builder

MySQL is shortcut of Dialect(MySQL)

func Oracle added in v0.3.2

func Oracle() *Builder

Oracle is shortcut of Dialect(Oracle)

func Postgres added in v0.3.2

func Postgres() *Builder

Postgres is shortcut of Dialect(Postgres)

func SQLite added in v0.3.2

func SQLite() *Builder

SQLite is shortcut of Dialect(SQLITE)

func Select

func Select(cols ...string) *Builder

Select creates a select Builder

func Update

func Update(updates ...Eq) *Builder

Update creates an update Builder

func (*Builder) And

func (b *Builder) And(cond Cond) *Builder

And sets AND condition

func (*Builder) CrossJoin

func (b *Builder) CrossJoin(joinTable string, joinCond interface{}) *Builder

CrossJoin sets cross join SQL

func (*Builder) Delete

func (b *Builder) Delete(conds ...Cond) *Builder

Delete sets delete SQL

func (*Builder) From

func (b *Builder) From(subject interface{}, alias ...string) *Builder

From sets from subject(can be a table name in string or a builder pointer) and its alias

func (*Builder) FullJoin

func (b *Builder) FullJoin(joinTable string, joinCond interface{}) *Builder

FullJoin sets full join SQL

func (*Builder) GroupBy added in v0.2.1

func (b *Builder) GroupBy(groupby string) *Builder

GroupBy groupby SQL

func (*Builder) Having added in v0.2.1

func (b *Builder) Having(having string) *Builder

Having having SQL

func (*Builder) InnerJoin

func (b *Builder) InnerJoin(joinTable string, joinCond interface{}) *Builder

InnerJoin sets inner join

func (*Builder) Insert

func (b *Builder) Insert(eq ...interface{}) *Builder

Insert sets insert SQL

func (*Builder) Into

func (b *Builder) Into(tableName string) *Builder

Into sets insert table name

func (*Builder) Join

func (b *Builder) Join(joinType, joinTable string, joinCond interface{}) *Builder

Join sets join table and conditions

func (*Builder) LeftJoin

func (b *Builder) LeftJoin(joinTable string, joinCond interface{}) *Builder

LeftJoin sets left join SQL

func (*Builder) Limit added in v0.3.1

func (b *Builder) Limit(limitN int, offset ...int) *Builder

Limit sets limitN condition

func (*Builder) Or

func (b *Builder) Or(cond Cond) *Builder

Or sets OR condition

func (*Builder) OrderBy added in v0.2.1

func (b *Builder) OrderBy(orderBy string) *Builder

OrderBy orderBy SQL

func (*Builder) RightJoin

func (b *Builder) RightJoin(joinTable string, joinCond interface{}) *Builder

RightJoin sets right join SQL

func (*Builder) Select

func (b *Builder) Select(cols ...string) *Builder

Select sets select SQL

func (*Builder) TableName added in v0.2.1

func (b *Builder) TableName() string

TableName returns the table name

func (*Builder) ToBoundSQL added in v0.3.1

func (b *Builder) ToBoundSQL() (string, error)

ToBoundSQL

func (*Builder) ToSQL

func (b *Builder) ToSQL() (string, []interface{}, error)

ToSQL convert a builder to SQL and args

func (*Builder) Union added in v0.3.1

func (b *Builder) Union(unionTp string, unionCond *Builder) *Builder

Union sets union conditions

func (*Builder) Update

func (b *Builder) Update(updates ...Eq) *Builder

Update sets update SQL

func (*Builder) Where

func (b *Builder) Where(cond Cond) *Builder

Where sets where SQL

func (*Builder) WriteTo

func (b *Builder) WriteTo(w Writer) error

WriteTo implements Writer interface

type BytesWriter

type BytesWriter struct {
	// contains filtered or unexported fields
}

BytesWriter implments Writer and save SQL in bytes.Buffer

func NewWriter

func NewWriter() *BytesWriter

NewWriter creates a new string writer

func (*BytesWriter) Append

func (s *BytesWriter) Append(args ...interface{})

Append appends args to Writer

func (*BytesWriter) Write

func (s *BytesWriter) Write(buf []byte) (int, error)

Write writes data to Writer

type Cond

type Cond interface {
	WriteTo(Writer) error
	And(...Cond) Cond
	Or(...Cond) Cond
	IsValid() bool
}

Cond defines an interface

func And

func And(conds ...Cond) Cond

And generates AND conditions

func Expr

func Expr(sql string, args ...interface{}) Cond

Expr generate customerize SQL

func In

func In(col string, values ...interface{}) Cond

In generates IN condition

func NewCond

func NewCond() Cond

NewCond creates an empty condition

func NotIn

func NotIn(col string, values ...interface{}) Cond

NotIn generate NOT IN condition

func Or

func Or(conds ...Cond) Cond

Or sets OR conditions

type Decr

type Decr int

Decr implements a type used by Eq

type Eq

type Eq map[string]interface{}

Eq defines equals conditions

func (Eq) And

func (eq Eq) And(conds ...Cond) Cond

And implements And with other conditions

func (Eq) IsValid

func (eq Eq) IsValid() bool

IsValid tests if this Eq is valid

func (Eq) Or

func (eq Eq) Or(conds ...Cond) Cond

Or implements Or with other conditions

func (Eq) WriteTo

func (eq Eq) WriteTo(w Writer) error

WriteTo writes SQL to Writer

type Gt

type Gt map[string]interface{}

Gt defines > condition

func (Gt) And

func (gt Gt) And(conds ...Cond) Cond

And implements And with other conditions

func (Gt) IsValid

func (gt Gt) IsValid() bool

IsValid tests if this Eq is valid

func (Gt) Or

func (gt Gt) Or(conds ...Cond) Cond

Or implements Or with other conditions

func (Gt) WriteTo

func (gt Gt) WriteTo(w Writer) error

WriteTo write SQL to Writer

type Gte

type Gte map[string]interface{}

Gte defines >= condition

func (Gte) And

func (gte Gte) And(conds ...Cond) Cond

And implements And with other conditions

func (Gte) IsValid

func (gte Gte) IsValid() bool

IsValid tests if this Eq is valid

func (Gte) Or

func (gte Gte) Or(conds ...Cond) Cond

Or implements Or with other conditions

func (Gte) WriteTo

func (gte Gte) WriteTo(w Writer) error

WriteTo write SQL to Writer

type Incr

type Incr int

Incr implements a type used by Eq

type IsNull

type IsNull [1]string

IsNull defines IS NULL condition

func (IsNull) And

func (isNull IsNull) And(conds ...Cond) Cond

And implements And with other conditions

func (IsNull) IsValid

func (isNull IsNull) IsValid() bool

IsValid tests if this condition is valid

func (IsNull) Or

func (isNull IsNull) Or(conds ...Cond) Cond

Or implements Or with other conditions

func (IsNull) WriteTo

func (isNull IsNull) WriteTo(w Writer) error

WriteTo write SQL to Writer

type Like

type Like [2]string

Like defines like condition

func (Like) And

func (like Like) And(conds ...Cond) Cond

And implements And with other conditions

func (Like) IsValid

func (like Like) IsValid() bool

IsValid tests if this condition is valid

func (Like) Or

func (like Like) Or(conds ...Cond) Cond

Or implements Or with other conditions

func (Like) WriteTo

func (like Like) WriteTo(w Writer) error

WriteTo write SQL to Writer

type Lt

type Lt map[string]interface{}

Lt defines < condition

func (Lt) And

func (lt Lt) And(conds ...Cond) Cond

And implements And with other conditions

func (Lt) IsValid

func (lt Lt) IsValid() bool

IsValid tests if this Eq is valid

func (Lt) Or

func (lt Lt) Or(conds ...Cond) Cond

Or implements Or with other conditions

func (Lt) WriteTo

func (lt Lt) WriteTo(w Writer) error

WriteTo write SQL to Writer

type Lte

type Lte map[string]interface{}

Lte defines <= condition

func (Lte) And

func (lte Lte) And(conds ...Cond) Cond

And implements And with other conditions

func (Lte) IsValid

func (lte Lte) IsValid() bool

IsValid tests if this Eq is valid

func (Lte) Or

func (lte Lte) Or(conds ...Cond) Cond

Or implements Or with other conditions

func (Lte) WriteTo

func (lte Lte) WriteTo(w Writer) error

WriteTo write SQL to Writer

type Neq

type Neq map[string]interface{}

Neq defines not equal conditions

func (Neq) And

func (neq Neq) And(conds ...Cond) Cond

And implements And with other conditions

func (Neq) IsValid

func (neq Neq) IsValid() bool

IsValid tests if this condition is valid

func (Neq) Or

func (neq Neq) Or(conds ...Cond) Cond

Or implements Or with other conditions

func (Neq) WriteTo

func (neq Neq) WriteTo(w Writer) error

WriteTo writes SQL to Writer

type Not

type Not [1]Cond

Not defines NOT condition

func (Not) And

func (not Not) And(conds ...Cond) Cond

And implements And with other conditions

func (Not) IsValid

func (not Not) IsValid() bool

IsValid tests if this condition is valid

func (Not) Or

func (not Not) Or(conds ...Cond) Cond

Or implements Or with other conditions

func (Not) WriteTo

func (not Not) WriteTo(w Writer) error

WriteTo writes SQL to Writer

type NotNull

type NotNull [1]string

NotNull defines NOT NULL condition

func (NotNull) And

func (notNull NotNull) And(conds ...Cond) Cond

And implements And with other conditions

func (NotNull) IsValid

func (notNull NotNull) IsValid() bool

IsValid tests if this condition is valid

func (NotNull) Or

func (notNull NotNull) Or(conds ...Cond) Cond

Or implements Or with other conditions

func (NotNull) WriteTo

func (notNull NotNull) WriteTo(w Writer) error

WriteTo write SQL to Writer

type StringBuilder added in v0.3.0

type StringBuilder struct {
	// contains filtered or unexported fields
}

A StringBuilder is used to efficiently build a string using Write methods. It minimizes memory copying. The zero value is ready to use. Do not copy a non-zero Builder.

func (*StringBuilder) Grow added in v0.3.0

func (b *StringBuilder) Grow(n int)

Grow grows b's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to b without another allocation. If n is negative, Grow panics.

func (*StringBuilder) Len added in v0.3.0

func (b *StringBuilder) Len() int

Len returns the number of accumulated bytes; b.Len() == len(b.String()).

func (*StringBuilder) Reset added in v0.3.0

func (b *StringBuilder) Reset()

Reset resets the Builder to be empty.

func (*StringBuilder) String added in v0.3.0

func (b *StringBuilder) String() string

String returns the accumulated string.

func (*StringBuilder) Write added in v0.3.0

func (b *StringBuilder) Write(p []byte) (int, error)

Write appends the contents of p to b's buffer. Write always returns len(p), nil.

func (*StringBuilder) WriteByte added in v0.3.0

func (b *StringBuilder) WriteByte(c byte) error

WriteByte appends the byte c to b's buffer. The returned error is always nil.

func (*StringBuilder) WriteRune added in v0.3.0

func (b *StringBuilder) WriteRune(r rune) (int, error)

WriteRune appends the UTF-8 encoding of Unicode code point r to b's buffer. It returns the length of r and a nil error.

func (*StringBuilder) WriteString added in v0.3.0

func (b *StringBuilder) WriteString(s string) (int, error)

WriteString appends the contents of s to b's buffer. It returns the length of s and a nil error.

type Writer

type Writer interface {
	io.Writer
	Append(...interface{})
}

Writer defines the interface

Jump to

Keyboard shortcuts

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