orm

package
v0.0.0-...-30f4346 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2015 License: Apache-2.0 Imports: 12 Imported by: 0

README

beego orm

Build Status

A powerful orm framework for go.

It is heavily influenced by Django ORM, SQLAlchemy.

Support Database:

Passed all test, but need more feedback.

Features:

  • full go type support
  • easy for usage, simple CRUD operation
  • auto join with relation table
  • cross DataBase compatible query
  • Raw SQL query / mapper without orm model
  • full test keep stable and strong

more features please read the docs

Install:

go get github.com/astaxie/beego/orm

Changelog

  • 2013-08-19: support table auto create
  • 2013-08-13: update test for database types
  • 2013-08-13: go type support, such as int8, uint8, byte, rune
  • 2013-08-13: date / datetime timezone support very well

Quick Start

Simple Usage
package main

import (
	"fmt"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql" // import your used driver
)

// Model Struct
type User struct {
	Id   int    `orm:"auto"`
	Name string `orm:"size(100)"`
}

func init() {
	// register model
	orm.RegisterModel(new(User))

	// set default database
	orm.RegisterDataBase("default", "mysql", "root:root@/my_db?charset=utf8", 30)
}

func main() {
	o := orm.NewOrm()

	user := User{Name: "slene"}

	// insert
	id, err := o.Insert(&user)

	// update
	user.Name = "astaxie"
	num, err := o.Update(&user)

	// read one
	u := User{Id: user.Id}
	err = o.Read(&u)

	// delete
	num, err = o.Delete(&u)	
}
Next with relation
type Post struct {
	Id    int    `orm:"auto"`
	Title string `orm:"size(100)"`
	User  *User  `orm:"rel(fk)"`
}

var posts []*Post
qs := o.QueryTable("post")
num, err := qs.Filter("User__Name", "slene").All(&posts)
Use Raw sql

If you don't like ORM,use Raw SQL to query / mapping without ORM setting

var maps []Params
num, err := o.Raw("SELECT id FROM user WHERE name = ?", "slene").Values(&maps)
if num > 0 {
	fmt.Println(maps[0]["id"])
}
Transaction
o.Begin()
...
user := User{Name: "slene"}
id, err := o.Insert(&user)
if err == nil {
	o.Commit()
} else {
	o.Rollback()
}

Debug Log Queries

In development env, you can simple use

func main() {
	orm.Debug = true
...

enable log queries.

output include all queries, such as exec / prepare / transaction.

like this:

[ORM] - 2013-08-09 13:18:16 - [Queries/default] - [    db.Exec /     0.4ms] - [INSERT INTO `user` (`name`) VALUES (?)] - `slene`
...

note: not recommend use this in product env.

Docs

more details and examples in docs and test

documents

Documentation

Overview

Package orm provide ORM for MySQL/PostgreSQL/sqlite Simple Usage

package main

import (
	"fmt"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql" // import your used driver
)

// Model Struct
type User struct {
	Id   int    `orm:"auto"`
	Name string `orm:"size(100)"`
}

func init() {
	orm.RegisterDataBase("default", "mysql", "root:root@/my_db?charset=utf8", 30)
}

func main() {
	o := orm.NewOrm()
	user := User{Name: "slene"}
	// insert
	id, err := o.Insert(&user)
	// update
	user.Name = "astaxie"
	num, err := o.Update(&user)
	// read one
	u := User{Id: user.Id}
	err = o.Read(&u)
	// delete
	num, err = o.Delete(&u)
}

more docs: http://beego.me/docs/mvc/model/overview.md

Index

Constants

View Source
const (
	TypeBooleanField = 1 << iota
	TypeCharField
	TypeTextField
	TypeDateField
	TypeDateTimeField
	TypeBitField
	TypeSmallIntegerField
	TypeIntegerField
	TypeBigIntegerField
	TypePositiveBitField
	TypePositiveSmallIntegerField
	TypePositiveIntegerField
	TypePositiveBigIntegerField
	TypeFloatField
	TypeDecimalField
	RelForeignKey
	RelOneToOne
	RelManyToMany
	RelReverseOne
	RelReverseMany
)

Define the Type enum

View Source
const (
	IsIntegerField        = ^-TypePositiveBigIntegerField >> 4 << 5
	IsPostiveIntegerField = ^-TypePositiveBigIntegerField >> 8 << 9
	IsRelField            = ^-RelReverseMany >> 14 << 15
	IsFieldType           = ^-RelReverseMany<<1 + 1
)

Define some logic enum

View Source
const (
	ColAdd operator = iota
	ColMinus
	ColMultiply
	ColExcept
)

define Col operations

View Source
const CommaSpace = ", "

CommaSpace is the seperation

View Source
const (
	DebugQueries = iota
)

DebugQueries define the debug

View Source
const (
	ExprSep = "__"
)

ExprSep define the expression seperation

Variables

View Source
var (
	Debug            = false
	DebugLog         = NewLog(os.Stderr)
	DefaultRowsLimit = 1000
	DefaultRelsDepth = 2
	DefaultTimeLoc   = time.Local
	ErrTxHasBegan    = errors.New("<Ormer.Begin> transaction already begin")
	ErrTxDone        = errors.New("<Ormer.Commit/Rollback> transaction not begin")
	ErrMultiRows     = errors.New("<QuerySeter> return multi rows")
	ErrNoRows        = errors.New("<QuerySeter> no row found")
	ErrStmtClosed    = errors.New("<QuerySeter> stmt already closed")
	ErrArgs          = errors.New("<Ormer> args error may be empty")
	ErrNotImplement  = errors.New("have not implement")
)

Define common vars

View Source
var (
	// ErrMissPK missing pk error
	ErrMissPK = errors.New("missed pk value")
)

Functions

func AddAliasWthDB

func AddAliasWthDB(aliasName, driverName string, db *sql.DB) error

AddAliasWthDB add a aliasName for the drivename

func BootStrap

func BootStrap()

BootStrap bootrap models. make all model parsed and can not add more models

func ColValue

func ColValue(opt operator, value interface{}) interface{}

ColValue do the field raw changes. e.g Nums = Nums + 10. usage:

Params{
	"Nums": ColValue(Col_Add, 10),
}

func GetDB

func GetDB(aliasNames ...string) (*sql.DB, error)

GetDB Get *sql.DB from registered database by db alias name. Use "default" as alias name if you not set.

func RegisterDataBase

func RegisterDataBase(aliasName, driverName, dataSource string, params ...int) error

RegisterDataBase Setting the database connect params. Use the database driver self dataSource args.

func RegisterDriver

func RegisterDriver(driverName string, typ DriverType) error

RegisterDriver Register a database driver use specify driver name, this can be definition the driver is which database type.

func RegisterModel

func RegisterModel(models ...interface{})

RegisterModel register models

func RegisterModelWithPrefix

func RegisterModelWithPrefix(prefix string, models ...interface{})

RegisterModelWithPrefix register models with a prefix

func ResetModelCache

func ResetModelCache()

ResetModelCache Clean model cache. Then you can re-RegisterModel. Common use this api for test case.

func RunCommand

func RunCommand()

RunCommand listen for orm command and then run it if command arguments passed.

func RunSyncdb

func RunSyncdb(name string, force bool, verbose bool) error

RunSyncdb run syncdb command line. name means table's alias name. default is "default". force means run next sql if the current is error. verbose means show all info when running command or not.

func SetDataBaseTZ

func SetDataBaseTZ(aliasName string, tz *time.Location) error

SetDataBaseTZ Change the database default used timezone

func SetMaxIdleConns

func SetMaxIdleConns(aliasName string, maxIdleConns int)

SetMaxIdleConns Change the max idle conns for *sql.DB, use specify database alias name

func SetMaxOpenConns

func SetMaxOpenConns(aliasName string, maxOpenConns int)

SetMaxOpenConns Change the max open conns for *sql.DB, use specify database alias name

func ToInt64

func ToInt64(value interface{}) (d int64)

ToInt64 interface to int64

func ToStr

func ToStr(value interface{}, args ...int) (s string)

ToStr interface to string

Types

type BigIntegerField

type BigIntegerField int64

BigIntegerField -9223372036854775808 to 9223372036854775807.

func (*BigIntegerField) FieldType

func (e *BigIntegerField) FieldType() int

FieldType return enum type

func (*BigIntegerField) RawValue

func (e *BigIntegerField) RawValue() interface{}

RawValue return BigIntegerField value

func (*BigIntegerField) Set

func (e *BigIntegerField) Set(d int64)

Set the BigIntegerField value

func (*BigIntegerField) SetRaw

func (e *BigIntegerField) SetRaw(value interface{}) error

SetRaw convert interface int64/string to int64

func (*BigIntegerField) String

func (e *BigIntegerField) String() string

String convert BigIntegerField to string

func (BigIntegerField) Value

func (e BigIntegerField) Value() int64

Value return int64

type BooleanField

type BooleanField bool

BooleanField A true/false field.

func (*BooleanField) FieldType

func (e *BooleanField) FieldType() int

FieldType return BooleanField the type

func (*BooleanField) RawValue

func (e *BooleanField) RawValue() interface{}

RawValue return the current value

func (*BooleanField) Set

func (e *BooleanField) Set(d bool)

Set will set the BooleanField

func (*BooleanField) SetRaw

func (e *BooleanField) SetRaw(value interface{}) error

SetRaw set the interface to bool

func (*BooleanField) String

func (e *BooleanField) String() string

String format the Bool to string

func (BooleanField) Value

func (e BooleanField) Value() bool

Value return the BooleanField

type CharField

type CharField string

CharField A string field required values tag: size The size is enforced at the database level and in models’s validation. eg: `orm:"size(120)"`

func (*CharField) FieldType

func (e *CharField) FieldType() int

FieldType return the enum type

func (*CharField) RawValue

func (e *CharField) RawValue() interface{}

RawValue return the CharField value

func (*CharField) Set

func (e *CharField) Set(d string)

Set CharField value

func (*CharField) SetRaw

func (e *CharField) SetRaw(value interface{}) error

SetRaw set the interface to string

func (*CharField) String

func (e *CharField) String() string

String return the CharField

func (CharField) Value

func (e CharField) Value() string

Value return the CharField's Value

type Condition

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

Condition struct. work for WHERE conditions.

func NewCondition

func NewCondition() *Condition

NewCondition return new condition struct

func (Condition) And

func (c Condition) And(expr string, args ...interface{}) *Condition

And add expression to condition

func (*Condition) AndCond

func (c *Condition) AndCond(cond *Condition) *Condition

AndCond combine a condition to current condition

func (Condition) AndNot

func (c Condition) AndNot(expr string, args ...interface{}) *Condition

AndNot add NOT expression to condition

func (*Condition) IsEmpty

func (c *Condition) IsEmpty() bool

IsEmpty check the condition arguments are empty or not.

func (Condition) Or

func (c Condition) Or(expr string, args ...interface{}) *Condition

Or add OR expression to condition

func (*Condition) OrCond

func (c *Condition) OrCond(cond *Condition) *Condition

OrCond combine a OR condition to current condition

func (Condition) OrNot

func (c Condition) OrNot(expr string, args ...interface{}) *Condition

OrNot add OR NOT expression to condition

type DateField

type DateField time.Time

DateField A date, represented in go by a time.Time instance. only date values like 2006-01-02 Has a few extra, optional attr tag:

auto_now: Automatically set the field to now every time the object is saved. Useful for “last-modified” timestamps. Note that the current date is always used; it’s not just a default value that you can override.

auto_now_add: Automatically set the field to now when the object is first created. Useful for creation of timestamps. Note that the current date is always used; it’s not just a default value that you can override.

eg: `orm:"auto_now"` or `orm:"auto_now_add"`

func (*DateField) FieldType

func (e *DateField) FieldType() int

FieldType return enum type Date

func (*DateField) RawValue

func (e *DateField) RawValue() interface{}

RawValue return Date value

func (*DateField) Set

func (e *DateField) Set(d time.Time)

Set set the DateField's value

func (*DateField) SetRaw

func (e *DateField) SetRaw(value interface{}) error

SetRaw convert the interface to time.Time. Allow string and time.Time

func (*DateField) String

func (e *DateField) String() string

String convert datatime to string

func (DateField) Value

func (e DateField) Value() time.Time

Value return the time.Time

type DateTimeField

type DateTimeField time.Time

DateTimeField A date, represented in go by a time.Time instance. datetime values like 2006-01-02 15:04:05 Takes the same extra arguments as DateField.

func (*DateTimeField) FieldType

func (e *DateTimeField) FieldType() int

FieldType return the enum TypeDateTimeField

func (*DateTimeField) RawValue

func (e *DateTimeField) RawValue() interface{}

RawValue return the datatime value

func (*DateTimeField) Set

func (e *DateTimeField) Set(d time.Time)

Set set the time.Time to datatime

func (*DateTimeField) SetRaw

func (e *DateTimeField) SetRaw(value interface{}) error

SetRaw convert the string or time.Time to DateTimeField

func (*DateTimeField) String

func (e *DateTimeField) String() string

String return the time's String

func (DateTimeField) Value

func (e DateTimeField) Value() time.Time

Value return the datatime value

type Driver

type Driver interface {
	Name() string
	Type() DriverType
}

Driver define database driver

type DriverType

type DriverType int

DriverType database driver constant int.

const (
	DRMySQL    DriverType // mysql
	DRSqlite              // sqlite
	DROracle              // oracle
	DRPostgres            // pgsql
	DRTiDB                // TiDB
)

Enum the Database driver

type Fielder

type Fielder interface {
	String() string
	FieldType() int
	SetRaw(interface{}) error
	RawValue() interface{}
}

Fielder define field info

type FloatField

type FloatField float64

FloatField A floating-point number represented in go by a float32 value.

func (*FloatField) FieldType

func (e *FloatField) FieldType() int

FieldType return the enum type

func (*FloatField) RawValue

func (e *FloatField) RawValue() interface{}

RawValue return the FloatField value

func (*FloatField) Set

func (e *FloatField) Set(d float64)

Set the Float64

func (*FloatField) SetRaw

func (e *FloatField) SetRaw(value interface{}) error

SetRaw converter interface Float64 float32 or string to FloatField

func (*FloatField) String

func (e *FloatField) String() string

String return the string

func (FloatField) Value

func (e FloatField) Value() float64

Value return the FloatField value

type Inserter

type Inserter interface {
	Insert(interface{}) (int64, error)
	Close() error
}

Inserter insert prepared statement

type IntegerField

type IntegerField int32

IntegerField -2147483648 to 2147483647

func (*IntegerField) FieldType

func (e *IntegerField) FieldType() int

FieldType return the enum type

func (*IntegerField) RawValue

func (e *IntegerField) RawValue() interface{}

RawValue return IntegerField value

func (*IntegerField) Set

func (e *IntegerField) Set(d int32)

Set IntegerField value

func (*IntegerField) SetRaw

func (e *IntegerField) SetRaw(value interface{}) error

SetRaw convert interface int32/string to int32

func (*IntegerField) String

func (e *IntegerField) String() string

String convert Int32 to string

func (IntegerField) Value

func (e IntegerField) Value() int32

Value return the int32

type Log

type Log struct {
	*log.Logger
}

Log implement the log.Logger

func NewLog

func NewLog(out io.Writer) *Log

NewLog set io.Writer to create a Logger.

type MySQLQueryBuilder

type MySQLQueryBuilder struct {
	Tokens []string
}

MySQLQueryBuilder is the SQL build

func (*MySQLQueryBuilder) And

func (qb *MySQLQueryBuilder) And(cond string) QueryBuilder

And join the and cond

func (*MySQLQueryBuilder) Asc

func (qb *MySQLQueryBuilder) Asc() QueryBuilder

Asc join the asc

func (*MySQLQueryBuilder) Delete

func (qb *MySQLQueryBuilder) Delete(tables ...string) QueryBuilder

Delete join the Delete tables

func (*MySQLQueryBuilder) Desc

func (qb *MySQLQueryBuilder) Desc() QueryBuilder

Desc join the desc

func (*MySQLQueryBuilder) From

func (qb *MySQLQueryBuilder) From(tables ...string) QueryBuilder

From join the tables

func (*MySQLQueryBuilder) GroupBy

func (qb *MySQLQueryBuilder) GroupBy(fields ...string) QueryBuilder

GroupBy join the Group by fields

func (*MySQLQueryBuilder) Having

func (qb *MySQLQueryBuilder) Having(cond string) QueryBuilder

Having join the Having cond

func (*MySQLQueryBuilder) In

func (qb *MySQLQueryBuilder) In(vals ...string) QueryBuilder

In join the IN (vals)

func (*MySQLQueryBuilder) InnerJoin

func (qb *MySQLQueryBuilder) InnerJoin(table string) QueryBuilder

InnerJoin INNER JOIN the table

func (*MySQLQueryBuilder) InsertInto

func (qb *MySQLQueryBuilder) InsertInto(table string, fields ...string) QueryBuilder

InsertInto join the insert SQL

func (*MySQLQueryBuilder) LeftJoin

func (qb *MySQLQueryBuilder) LeftJoin(table string) QueryBuilder

LeftJoin LEFT JOIN the table

func (*MySQLQueryBuilder) Limit

func (qb *MySQLQueryBuilder) Limit(limit int) QueryBuilder

Limit join the limit num

func (*MySQLQueryBuilder) Offset

func (qb *MySQLQueryBuilder) Offset(offset int) QueryBuilder

Offset join the offset num

func (*MySQLQueryBuilder) On

func (qb *MySQLQueryBuilder) On(cond string) QueryBuilder

On join with on cond

func (*MySQLQueryBuilder) Or

func (qb *MySQLQueryBuilder) Or(cond string) QueryBuilder

Or join the or cond

func (*MySQLQueryBuilder) OrderBy

func (qb *MySQLQueryBuilder) OrderBy(fields ...string) QueryBuilder

OrderBy join the Order by fields

func (*MySQLQueryBuilder) RightJoin

func (qb *MySQLQueryBuilder) RightJoin(table string) QueryBuilder

RightJoin RIGHT JOIN the table

func (*MySQLQueryBuilder) Select

func (qb *MySQLQueryBuilder) Select(fields ...string) QueryBuilder

Select will join the fields

func (*MySQLQueryBuilder) Set

func (qb *MySQLQueryBuilder) Set(kv ...string) QueryBuilder

Set join the set kv

func (*MySQLQueryBuilder) String

func (qb *MySQLQueryBuilder) String() string

String join all Tokens

func (*MySQLQueryBuilder) Subquery

func (qb *MySQLQueryBuilder) Subquery(sub string, alias string) string

Subquery join the sub as alias

func (*MySQLQueryBuilder) Update

func (qb *MySQLQueryBuilder) Update(tables ...string) QueryBuilder

Update join the update table

func (*MySQLQueryBuilder) Values

func (qb *MySQLQueryBuilder) Values(vals ...string) QueryBuilder

Values join the Values(vals)

func (*MySQLQueryBuilder) Where

func (qb *MySQLQueryBuilder) Where(cond string) QueryBuilder

Where join the Where cond

type Ormer

type Ormer interface {
	Read(interface{}, ...string) error
	ReadOrCreate(interface{}, string, ...string) (bool, int64, error)
	Insert(interface{}) (int64, error)
	InsertMulti(int, interface{}) (int64, error)
	Update(interface{}, ...string) (int64, error)
	Delete(interface{}) (int64, error)
	LoadRelated(interface{}, string, ...interface{}) (int64, error)
	QueryM2M(interface{}, string) QueryM2Mer
	QueryTable(interface{}) QuerySeter
	Using(string) error
	Begin() error
	Commit() error
	Rollback() error
	Raw(string, ...interface{}) RawSeter
	Driver() Driver
}

Ormer define the orm interface

func NewOrm

func NewOrm() Ormer

NewOrm create new orm

func NewOrmWithDB

func NewOrmWithDB(driverName, aliasName string, db *sql.DB) (Ormer, error)

NewOrmWithDB create a new ormer object with specify *sql.DB for query

type Params

type Params map[string]interface{}

Params stores the Params

type ParamsList

type ParamsList []interface{}

ParamsList stores paramslist

type PositiveBigIntegerField

type PositiveBigIntegerField uint64

PositiveBigIntegerField 0 to 18446744073709551615

func (*PositiveBigIntegerField) FieldType

func (e *PositiveBigIntegerField) FieldType() int

FieldType return enum type

func (*PositiveBigIntegerField) RawValue

func (e *PositiveBigIntegerField) RawValue() interface{}

RawValue return PositiveBigIntegerField value

func (*PositiveBigIntegerField) Set

func (e *PositiveBigIntegerField) Set(d uint64)

Set PositiveBigIntegerField value

func (*PositiveBigIntegerField) SetRaw

func (e *PositiveBigIntegerField) SetRaw(value interface{}) error

SetRaw convert interface uint64/string to Uint64

func (*PositiveBigIntegerField) String

func (e *PositiveBigIntegerField) String() string

String convert PositiveBigIntegerField to string

func (PositiveBigIntegerField) Value

func (e PositiveBigIntegerField) Value() uint64

Value return uint64

type PositiveIntegerField

type PositiveIntegerField uint32

PositiveIntegerField 0 to 4294967295

func (*PositiveIntegerField) FieldType

func (e *PositiveIntegerField) FieldType() int

FieldType return enum type

func (*PositiveIntegerField) RawValue

func (e *PositiveIntegerField) RawValue() interface{}

RawValue return the PositiveIntegerField Value

func (*PositiveIntegerField) Set

func (e *PositiveIntegerField) Set(d uint32)

Set the PositiveIntegerField value

func (*PositiveIntegerField) SetRaw

func (e *PositiveIntegerField) SetRaw(value interface{}) error

SetRaw convert interface uint32/string to Uint32

func (*PositiveIntegerField) String

func (e *PositiveIntegerField) String() string

String convert PositiveIntegerField to string

func (PositiveIntegerField) Value

func (e PositiveIntegerField) Value() uint32

Value return PositiveIntegerField value. Uint32

type PositiveSmallIntegerField

type PositiveSmallIntegerField uint16

PositiveSmallIntegerField 0 to 65535

func (*PositiveSmallIntegerField) FieldType

func (e *PositiveSmallIntegerField) FieldType() int

FieldType return enum type

func (*PositiveSmallIntegerField) RawValue

func (e *PositiveSmallIntegerField) RawValue() interface{}

RawValue returns PositiveSmallIntegerField value

func (*PositiveSmallIntegerField) Set

Set PositiveSmallIntegerField value

func (*PositiveSmallIntegerField) SetRaw

func (e *PositiveSmallIntegerField) SetRaw(value interface{}) error

SetRaw convert Interface uint16/string to uint16

func (*PositiveSmallIntegerField) String

func (e *PositiveSmallIntegerField) String() string

String convert uint16 to string

func (PositiveSmallIntegerField) Value

Value return uint16

type QueryBuilder

type QueryBuilder interface {
	Select(fields ...string) QueryBuilder
	From(tables ...string) QueryBuilder
	InnerJoin(table string) QueryBuilder
	LeftJoin(table string) QueryBuilder
	RightJoin(table string) QueryBuilder
	On(cond string) QueryBuilder
	Where(cond string) QueryBuilder
	And(cond string) QueryBuilder
	Or(cond string) QueryBuilder
	In(vals ...string) QueryBuilder
	OrderBy(fields ...string) QueryBuilder
	Asc() QueryBuilder
	Desc() QueryBuilder
	Limit(limit int) QueryBuilder
	Offset(offset int) QueryBuilder
	GroupBy(fields ...string) QueryBuilder
	Having(cond string) QueryBuilder
	Update(tables ...string) QueryBuilder
	Set(kv ...string) QueryBuilder
	Delete(tables ...string) QueryBuilder
	InsertInto(table string, fields ...string) QueryBuilder
	Values(vals ...string) QueryBuilder
	Subquery(sub string, alias string) string
	String() string
}

QueryBuilder is the Query builder interface

func NewQueryBuilder

func NewQueryBuilder(driver string) (qb QueryBuilder, err error)

NewQueryBuilder return the QueryBuilder

type QueryM2Mer

type QueryM2Mer interface {
	Add(...interface{}) (int64, error)
	Remove(...interface{}) (int64, error)
	Exist(interface{}) bool
	Clear() (int64, error)
	Count() (int64, error)
}

QueryM2Mer model to model query struct

type QuerySeter

type QuerySeter interface {
	Filter(string, ...interface{}) QuerySeter
	Exclude(string, ...interface{}) QuerySeter
	SetCond(*Condition) QuerySeter
	Limit(interface{}, ...interface{}) QuerySeter
	Offset(interface{}) QuerySeter
	GroupBy(...string) QuerySeter
	OrderBy(...string) QuerySeter
	Distinct() QuerySeter
	RelatedSel(...interface{}) QuerySeter
	Count() (int64, error)
	Exist() bool
	Update(Params) (int64, error)
	Delete() (int64, error)
	PrepareInsert() (Inserter, error)
	All(interface{}, ...string) (int64, error)
	One(interface{}, ...string) error
	Values(*[]Params, ...string) (int64, error)
	ValuesList(*[]ParamsList, ...string) (int64, error)
	ValuesFlat(*ParamsList, string) (int64, error)
	RowsToMap(*Params, string, string) (int64, error)
	RowsToStruct(interface{}, string, string) (int64, error)
}

QuerySeter query seter

type RawPreparer

type RawPreparer interface {
	Exec(...interface{}) (sql.Result, error)
	Close() error
}

RawPreparer raw query statement

type RawSeter

type RawSeter interface {
	Exec() (sql.Result, error)
	QueryRow(...interface{}) error
	QueryRows(...interface{}) (int64, error)
	SetArgs(...interface{}) RawSeter
	Values(*[]Params, ...string) (int64, error)
	ValuesList(*[]ParamsList, ...string) (int64, error)
	ValuesFlat(*ParamsList, ...string) (int64, error)
	RowsToMap(*Params, string, string) (int64, error)
	RowsToStruct(interface{}, string, string) (int64, error)
	Prepare() (RawPreparer, error)
}

RawSeter raw query seter

type SmallIntegerField

type SmallIntegerField int16

SmallIntegerField -32768 to 32767

func (*SmallIntegerField) FieldType

func (e *SmallIntegerField) FieldType() int

FieldType return enum type SmallIntegerField

func (*SmallIntegerField) RawValue

func (e *SmallIntegerField) RawValue() interface{}

RawValue return smallint value

func (*SmallIntegerField) Set

func (e *SmallIntegerField) Set(d int16)

Set the SmallIntegerField value

func (*SmallIntegerField) SetRaw

func (e *SmallIntegerField) SetRaw(value interface{}) error

SetRaw convert interface int16/string to int16

func (*SmallIntegerField) String

func (e *SmallIntegerField) String() string

String convert smallint to string

func (SmallIntegerField) Value

func (e SmallIntegerField) Value() int16

Value return int16 value

type StrTo

type StrTo string

StrTo is the target string

func (StrTo) Bool

func (f StrTo) Bool() (bool, error)

Bool string to bool

func (*StrTo) Clear

func (f *StrTo) Clear()

Clear string

func (StrTo) Exist

func (f StrTo) Exist() bool

Exist check string exist

func (StrTo) Float32

func (f StrTo) Float32() (float32, error)

Float32 string to float32

func (StrTo) Float64

func (f StrTo) Float64() (float64, error)

Float64 string to float64

func (StrTo) Int

func (f StrTo) Int() (int, error)

Int string to int

func (StrTo) Int16

func (f StrTo) Int16() (int16, error)

Int16 string to int16

func (StrTo) Int32

func (f StrTo) Int32() (int32, error)

Int32 string to int32

func (StrTo) Int64

func (f StrTo) Int64() (int64, error)

Int64 string to int64

func (StrTo) Int8

func (f StrTo) Int8() (int8, error)

Int8 string to int8

func (*StrTo) Set

func (f *StrTo) Set(v string)

Set string

func (StrTo) String

func (f StrTo) String() string

String string to string

func (StrTo) Uint

func (f StrTo) Uint() (uint, error)

Uint string to uint

func (StrTo) Uint16

func (f StrTo) Uint16() (uint16, error)

Uint16 string to uint16

func (StrTo) Uint32

func (f StrTo) Uint32() (uint32, error)

Uint32 string to uint31

func (StrTo) Uint64

func (f StrTo) Uint64() (uint64, error)

Uint64 string to uint64

func (StrTo) Uint8

func (f StrTo) Uint8() (uint8, error)

Uint8 string to uint8

type TextField

type TextField string

TextField A large text field.

func (*TextField) FieldType

func (e *TextField) FieldType() int

FieldType return enum type

func (*TextField) RawValue

func (e *TextField) RawValue() interface{}

RawValue return TextField value

func (*TextField) Set

func (e *TextField) Set(d string)

Set the TextField value

func (*TextField) SetRaw

func (e *TextField) SetRaw(value interface{}) error

SetRaw convert interface string to string

func (*TextField) String

func (e *TextField) String() string

String convert TextField to string

func (TextField) Value

func (e TextField) Value() string

Value return TextField value

type TiDBQueryBuilder

type TiDBQueryBuilder struct {
	Tokens []string
}

TiDBQueryBuilder is the SQL build

func (*TiDBQueryBuilder) And

func (qb *TiDBQueryBuilder) And(cond string) QueryBuilder

And join the and cond

func (*TiDBQueryBuilder) Asc

func (qb *TiDBQueryBuilder) Asc() QueryBuilder

Asc join the asc

func (*TiDBQueryBuilder) Delete

func (qb *TiDBQueryBuilder) Delete(tables ...string) QueryBuilder

Delete join the Delete tables

func (*TiDBQueryBuilder) Desc

func (qb *TiDBQueryBuilder) Desc() QueryBuilder

Desc join the desc

func (*TiDBQueryBuilder) From

func (qb *TiDBQueryBuilder) From(tables ...string) QueryBuilder

From join the tables

func (*TiDBQueryBuilder) GroupBy

func (qb *TiDBQueryBuilder) GroupBy(fields ...string) QueryBuilder

GroupBy join the Group by fields

func (*TiDBQueryBuilder) Having

func (qb *TiDBQueryBuilder) Having(cond string) QueryBuilder

Having join the Having cond

func (*TiDBQueryBuilder) In

func (qb *TiDBQueryBuilder) In(vals ...string) QueryBuilder

In join the IN (vals)

func (*TiDBQueryBuilder) InnerJoin

func (qb *TiDBQueryBuilder) InnerJoin(table string) QueryBuilder

InnerJoin INNER JOIN the table

func (*TiDBQueryBuilder) InsertInto

func (qb *TiDBQueryBuilder) InsertInto(table string, fields ...string) QueryBuilder

InsertInto join the insert SQL

func (*TiDBQueryBuilder) LeftJoin

func (qb *TiDBQueryBuilder) LeftJoin(table string) QueryBuilder

LeftJoin LEFT JOIN the table

func (*TiDBQueryBuilder) Limit

func (qb *TiDBQueryBuilder) Limit(limit int) QueryBuilder

Limit join the limit num

func (*TiDBQueryBuilder) Offset

func (qb *TiDBQueryBuilder) Offset(offset int) QueryBuilder

Offset join the offset num

func (*TiDBQueryBuilder) On

func (qb *TiDBQueryBuilder) On(cond string) QueryBuilder

On join with on cond

func (*TiDBQueryBuilder) Or

func (qb *TiDBQueryBuilder) Or(cond string) QueryBuilder

Or join the or cond

func (*TiDBQueryBuilder) OrderBy

func (qb *TiDBQueryBuilder) OrderBy(fields ...string) QueryBuilder

OrderBy join the Order by fields

func (*TiDBQueryBuilder) RightJoin

func (qb *TiDBQueryBuilder) RightJoin(table string) QueryBuilder

RightJoin RIGHT JOIN the table

func (*TiDBQueryBuilder) Select

func (qb *TiDBQueryBuilder) Select(fields ...string) QueryBuilder

Select will join the fields

func (*TiDBQueryBuilder) Set

func (qb *TiDBQueryBuilder) Set(kv ...string) QueryBuilder

Set join the set kv

func (*TiDBQueryBuilder) String

func (qb *TiDBQueryBuilder) String() string

String join all Tokens

func (*TiDBQueryBuilder) Subquery

func (qb *TiDBQueryBuilder) Subquery(sub string, alias string) string

Subquery join the sub as alias

func (*TiDBQueryBuilder) Update

func (qb *TiDBQueryBuilder) Update(tables ...string) QueryBuilder

Update join the update table

func (*TiDBQueryBuilder) Values

func (qb *TiDBQueryBuilder) Values(vals ...string) QueryBuilder

Values join the Values(vals)

func (*TiDBQueryBuilder) Where

func (qb *TiDBQueryBuilder) Where(cond string) QueryBuilder

Where join the Where cond

Jump to

Keyboard shortcuts

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