gosql

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2020 License: MIT Imports: 13 Imported by: 0

README

gosql

GoTest GoDoc codecov Go Report Card LICENSE

gosql is a easy ORM library for Golang.

Feature

  • Golang-style SQL builder
  • Unlimited nesting query
  • Reading and Writing Separation
  • Delay connection creation
  • ORM mapping to struct
  • Support transaction
  • Versatile
  • Clean Code
  • Bulk Insert

Structure

  • db.go: Basic struct definition
  • pool.go: Manage DB pool
  • session.go: Session and Model
  • builder.go: Building SQL
  • scanner/*: scan struct

Why build this wheels

I have read almost all open source operation database library implemented in golang on github. But never get the optimal solution.

Such as these:

  1. gorm: Does not support read and write separation.

  2. gendry: Occupy special keywords and partially ugly syntax.

  3. sqlx: Mostly good, But the syntax is not simple enough, and does not support the separation of reading and writing.

This project refers to a large number of existing libs, refers to various documents, and uses golang style to achieve from scratch.

NOTE

NOTE: Only supports mysql driver.

Demo

Let's look a demo frist.

SELECT DISTINCT *
FROM `tbl1`.`t1`
    JOIN `tbl3` ON `a` = `b`
WHERE (`t1`.`status` = ?
    AND `name` = ?
    AND `nick` != ?
    AND `role1` IN (?, ?, ?, ?)
    AND `role2` NOT IN (?, ?, ?, ?)
    AND `card1` IN (?)
    AND `card2` NOT IN (?)
    AND (`age` > ?
        AND `age` < ?)
    AND v1 = 1
    AND v2 = ?
    AND `desc` LIKE ?
    AND `desc` NOT LIKE ?
    AND EXISTS (
        SELECT 1
    )
    AND NOT EXISTS (
        SELECT *
        FROM `tbl2`.`t2`
        WHERE `t2`.`id` = ?
    ))
GROUP BY `class`, `group`
HAVING `class` = ?
ORDER BY `score` DESC, `name` ASC, `age`
LIMIT 10, 30
FOR UPDATE
    s := gosql.NewSQLSegment()
    s.Flag("DISTINCT")
    s.Field("*")
    s.Table("tbl1.t1")
    s.Where("t1.status", "0")
    s.Where("name", "jack")
    s.Where("[!=]nick", "tom")
    s.Where("[in]role1", []string{"1", "2", "3", "4"})
    s.Where("[!in]role2", []string{"1", "2", "3", "4"})
    s.Where("[in]card1", 1)
    s.Where("[!in]card2", 1)
    s.Where(func(s *Clause) {
        s.Where("[>]age", "20")
        s.Where("[<]", "50")
    })
    s.Where("v1 = 1")
    s.Where("[#]v2 = ?", 2)
    s.Join("tbl3", "a", "=", "b")
    s.Having("class", "one")
    s.Where("[~]desc", "student")
    s.Where("[!~]desc", "teacher")
    s.Where("[exists]my_card", "select 1")
    s.Where("[!exists]my_card2", func(s *SQLSegments) {
        s.Table("tbl2.t2")
        s.Where("t2.id", 10000)
    })
    s.GroupBy("class","group")
    s.OrderBy("score desc", "name asc","age")
    s.Limit(30)
    s.Offset(10)
    s.ForUpdate()
    fmt.Println(s.BuildSelect())

Getting Started

package main

import (
    "fmt"

    _ "github.com/go-sql-driver/mysql"
    "github.com/rushteam/gosql"
)

type UserModel struct {
    ID   int    `db:"id"`
    Name string `db:"name"`
}

func (u *UserModel) TableName() string {
    return "my_user"
}

func main() {
    db := gosql.NewCluster(
        gosql.AddDb("mysql", "user:password@tcp(127.0.0.1:3306)/test?parseTime=true&readTimeout=3s&writeTimeout=3s&timeout=3s"),
    )
    user := &UserModel{}
    err := db.Fetch(user, gosql.Where("id", 1), gosql.Where("[like]name", "j%"))
    if err != nil {
        fmt.Println(err)
    }
    fmt.Println(user)
}

Doc

Debug Mode
//this code will be start at debug mode and the sql will be print
gosql.Debug = true
Struct Model

To define a Model struct, use the struct and tag syntax.

Simple define a model
type User struct {
    ID int64
    Age int
    Name string
    CreatedAt time.Time
}

Usually define a Struct can be used as a model, gosql will parse out the table name, field mapping relationship,etc.

table: user columns: id,age,name,created_at

Using tag syntax

Use structure tags to customize field mapping

type User struct {
    ID int64 `db:"uid,pk"`
    Age int `db:"age"`
    Name string `db:"fisrt_name"`
    CreatedAt time.Time `db:"created_at"`
}

table: user columns: uid,age,fisrt_name,created_at pk: uid

Define table name

Implement "TableName" method to specify the table name

type User struct {}
func (u *User) TableName() string {
    return "my_user"
}

table: my_user

Exec
INSERT

db.Insert(dst interface{}, opts ...Option) (Result, error)

user := &UserModel{}
user.Name = "jack"
ret,err := db.Insert(&user)

batch insert

users := []UserModel{}
u1 := UserModel{Name:"jack"}
u2 := UserModel{Name:"Tom"}
users = append(users,u1)
users = append(users,u2)
ret,err := db.Insert(users)
REPLACE

db.Replace(dst interface{}, opts ...Option) (Result, error)

user := &UserModel{}
user.Name = "jack"
ret,err := db.Replace(&user,gosql.Where("id",1))
UPDATE

Update(dst interface{}, opts ...Option) (Result, error)

user := &UserModel{}
user.Name = "jack Ma"
ret,err := db.Update(&user,gosql.Where("id",1))
DELETE

db.Delete(dst interface{}, opts ...Option) (Result, error)

user := &UserModel{}
ret,err := db.Delete(&user,gosql.Where("id",1))
//sql: delete from my_user where id = 1
QUERY
Get a record: db.Fetch(dst interface{}, opts ...Option) error
user := &UserModel{}
err := db.Fetch(user,
    gosql.Columns("id","name"),
    gosql.Where("id", 1),
    gosql.Where("[like]name", "j%"),
    gosql.OrWhere(func(s *Clause) {
        s.Where("[>=]score", "90")
        s.Where("[<=]age", "100")
    }),
    gosql.GroupBy("type"),
    gosql.OrderBy("score DESC"),
)
Get multiple records: db.FetchAll(dst interface{}, opts ...Option) error
var userList []UserModel
err := db.FetchAll(&userList,
    gosql.Columns("id","name"),
    gosql.Where("id", 1),
    gosql.Where("[like]name", "j%"),
    gosql.OrWhere(func(s *Clause) {
        s.Where("[>]score", "90")
        s.Where("[<]score", "100")
    }),
    gosql.GroupBy("type"),
    gosql.OrderBy("score DESC"),
    gosql.Offset(0),
    gosql.Limit(10),
)
OPTION
WHERE
  • gosql.Where("id",1)
gosql.Where("id",1)
//sql: id = 1
  • gosql.Where("[>]age",18)
gosql.Where("[>]age",18)
//sql: age > 18
  • gosql.Where("[in]id",[]int{1,2})
gosql.Where("[in]id",[]int{1,2})
//sql: id in (1,2)
  • gosql.Where("[!in]id",[]int{1,2})
gosql.Where("[!in]id",[]int{1,2})
//sql: id not in (1,2)
  • gosql.Where("[~]name","ja%")
gosql.Where("[~]name","ja%")
//sql: name like 'ja%'
  • gosql.Where("[!~]name","ja%")
gosql.Where("[!~]name","ja%")
//sql: name not like 'ja%'
symbol [?]
  • [=] equal
gosql.Where("[=]id",1)
//sql: id = 1
  • [!=] not equal
gosql.Where("[!=]id",1)
//sql: id != 1
  • [>] greater than
gosql.Where("[>]id",1)
//sql: id > 1
  • [>=] greater or equal
gosql.Where("[>=]id",1)
//sql: id >= 1
  • [<] less
gosql.Where("[<]id",1)
//sql: id < 1
  • [<=] less or equal
gosql.Where("[<=]id",1)
//sql: id <= 1
  • [in] in
gosql.Where("[in]id",[]int{1,2})
//sql: id in (1,2)
  • [!in] not in
gosql.Where("[!in]id",[]int{1,2})
//sql: id not in (1,2)
  • [is] is null
gosql.Where("[is]name",nil)
//sql: name is null
  • [!is] not is null
gosql.Where("[!is]name",nil)
//sql: id is not null
  • [exists] exists
gosql.Where("[exists]name","select 1")
//sql: name exists(select 1)
  • [!exists] not exists
gosql.Where("[!exists]name","select 1")
//sql: name not exists(select 1)
  • [#] sql
gosql.Where("[#]age=age-1")
//sql: age = age-1
Raw SQL: db.Query()
rows,err := db.Query("select * from my_user where id = ?",1)
//sql: select * from my_user where id = 1
select primary or replica
  • db.Primary() change to primary db
ret,err := db.Primary().Fetch(...)
  • db.Replica() change to replica
ret,err := db.Replica().Fetch(...)
Paging

Define a page function and return gosql.Option sturct

//Page  pn: per page num ,ps: page size
func Page(pn, ps int) gosql.Option {
	if pn < 1 {
		pn = 1
	}
	return func(s gosql.SQLSegments) gosql.SQLSegments {
		s.Limit(ps)
		s.Offset((pn - 1) * ps)
		return s
	}
}
func main() {
    user := &UserModel{}
    err := db.Fetch(user,
        Page(1,15),
    )
}

multi-database
gosql.NewCollect(
    gosql.NewCluster(
        gosql.AddDb("mysql", "user:password@tcp(127.0.0.1:3306)/test?parseTime=true&readTimeout=3s&writeTimeout=3s&timeout=3s"),
    ),
    "db1",
)
gosql.NewCollect(
    gosql.NewCluster(
        gosql.AddDb("mysql", "user:password@tcp(127.0.0.1:3306)/test?parseTime=true&readTimeout=3s&writeTimeout=3s&timeout=3s"),
    ),
    "db2",
)

db1 := gosql.Collect("db1")


db2 := gosql.Collect("db2")
builder of API
  • builder.New() start a builder
s := builder.New()
  • builder.Flag(f string) set a flag
s.Flag("test")
  • builder.Field(fields string) Specified columns

default value *

s.Field("*")
  • builder.Table(tbl string) Specified table name
s.Table("tbl.t1")
Where

builder.Where(key string, val inferface{})

  • Eq
s.Where("t1.status", "0")
//sql: t1.status = 0
  • Not Eq
s.Where("[!=]t1.status", "0")
//sql: t1.status != 0
  • In
s.Where("[in]field", []string{"a", "b", "c"})
//sql: t1.field in (a,b,c)
  • No In
s.Where("[!in]field", []string{"a", "b", "c"})
//sql: t1.status in (a,b,c)
Nested Where
  • s.Where(func(s *builder.Clause){}
s.Where("[!]t1.a",1).Where(func(s *builder.Clause){
    s.Where("t1.b",1)
    s.OrWhere("t1.c",1)
})
//sql: t1.a != 1  and (t1.b = 1 or t1.c = 1)
Other statements
  • Group By
s.GroupBy("class")
//sql: group by `class`
  • Order By
s.OrderBy("id desc", "age asc")
//sql: order by `id` desc, `age` asc
  • Limit
s.Limit(10)
//sql: limit 10
  • Offset
s.Offset(10)
//sql: offset 10

Contributing

When everybody adds fuel, the flames rise high.

Let's build our self library.

You will be a member of rushteam which is An open source organization

Thanks for you, Good Lucy.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Debug = false

Debug env

View Source
var ErrNoRows = sql.ErrNoRows

ErrNoRows sql ErrNoRows

Functions

func DeleteSQL

func DeleteSQL(opts ...Option) (string, []interface{})

DeleteSQL ..

func InsertSQL

func InsertSQL(opts ...Option) (string, []interface{})

InsertSQL ..

func NewCollect added in v0.1.1

func NewCollect(clst Cluster, name ...string)

NewCollect ..

func ReplaceSQL

func ReplaceSQL(opts ...Option) (string, []interface{})

ReplaceSQL ..

func SelectSQL

func SelectSQL(opts ...Option) (string, []interface{})

SelectSQL ..

func UpdateSQL

func UpdateSQL(opts ...Option) (string, []interface{})

UpdateSQL ..

Types

type Add

type Add int

Add ..

type Clause

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

Clause ...

func (*Clause) Build

func (p *Clause) Build(i int) (string, []interface{})

Build ...

func (*Clause) OrWhere

func (p *Clause) OrWhere(key interface{}, vals ...interface{}) *Clause

OrWhere ..

func (*Clause) Where

func (p *Clause) Where(key interface{}, vals ...interface{}) *Clause

Where ..

type Cluster

type Cluster interface {
	Executor(*Session, bool) (*Session, error)
	Begin() (*Session, error)
	Fetch(interface{}, ...Option) error
	FetchAll(interface{}, ...Option) error
	Update(interface{}, ...Option) (Result, error)
	Insert(interface{}, ...Option) (Result, error)
	Replace(interface{}, ...Option) (Result, error)
	Delete(interface{}, ...Option) (Result, error)
}

Cluster ..

func Collect added in v0.1.1

func Collect(name ...string) Cluster

Collect get a cluster by name

type DB

type DB interface {
	SetMaxIdleConns(int)
	SetMaxOpenConns(int)
	SetConnMaxLifetime(time.Duration)
	Stats() sql.DBStats
	PingContext(context.Context) error
	Ping() error
	Close() error
	BeginTx(context.Context, *sql.TxOptions) (*sql.Tx, error)
	Begin() (*sql.Tx, error)
	Driver() driver.Driver
	Conn(context.Context) (*sql.Conn, error)
}

DB ..

type DbOption

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

DbOption ..

func SetConnMaxLifetime

func SetConnMaxLifetime(d time.Duration) DbOption

SetConnMaxLifetime ..

func SetMaxIdleConns

func SetMaxIdleConns(n int) DbOption

SetMaxIdleConns ..

func SetMaxOpenConns

func SetMaxOpenConns(n int) DbOption

SetMaxOpenConns ..

type Error

type Error struct {
	Number  uint16
	Message string
}

Error ..

func (*Error) Error

func (e *Error) Error() string

type Executor

type Executor interface {
	PrepareContext(context.Context, string) (*sql.Stmt, error)
	Prepare(string) (*sql.Stmt, error)
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	Exec(string, ...interface{}) (sql.Result, error)
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
	Query(string, ...interface{}) (*sql.Rows, error)
	QueryRowContext(context.Context, string, ...interface{}) *sql.Row
	QueryRow(string, ...interface{}) *sql.Row
}

Executor is a Executor

type Option

type Option func(q SQLSegments) SQLSegments

Option is SQL segment part

func Columns

func Columns(fields ...string) Option

Columns for set columns

func CorssJoin

func CorssJoin(table string, conditionA, logic, conditionB string) Option

CorssJoin for corss join

func Flag

func Flag(flags ...string) Option

Flag for set flag

func ForUpdate

func ForUpdate() Option

ForUpdate ..

func GroupBy

func GroupBy(fields ...string) Option

GroupBy ..

func InnerJoin

func InnerJoin(table string, conditionA, logic, conditionB string) Option

InnerJoin for inner join

func Join

func Join(table string, conditionA, logic, conditionB string) Option

Join for join

func LeftJoin

func LeftJoin(table string, conditionA, logic, conditionB string) Option

LeftJoin ..

func Limit

func Limit(n int) Option

Limit ..

func Offset

func Offset(n int) Option

Offset ..

func OrWhere

func OrWhere(key interface{}, vals ...interface{}) Option

OrWhere ..

func OrderBy

func OrderBy(fields ...string) Option

OrderBy ..

func Params

func Params(vals ...map[string]interface{}) Option

Params ...

func Returning

func Returning() Option

Returning ..

func RightJoin

func RightJoin(table string, conditionA, logic, conditionB string) Option

RightJoin for right join

func Set

func Set(key string, val interface{}) Option

Set ..

func Table

func Table(name interface{}) Option

Table for set table

func Union

func Union(f func(*SQLSegments)) Option

Union for union sql

func Where

func Where(key interface{}, vals ...interface{}) Option

Where ..

type PoolCluster

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

PoolCluster impl Cluster

func NewCluster

func NewCluster(opts ...PoolClusterOpts) *PoolCluster

NewCluster start

func (*PoolCluster) Begin

func (c *PoolCluster) Begin() (*Session, error)

Begin a transaction

func (*PoolCluster) Delete

func (c *PoolCluster) Delete(dst interface{}, opts ...Option) (Result, error)

Delete delete record

func (*PoolCluster) Exec added in v0.1.1

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

Exec ..

func (*PoolCluster) ExecContext added in v0.1.1

func (c *PoolCluster) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

ExecContext ..

func (*PoolCluster) Executor added in v0.1.1

func (c *PoolCluster) Executor(s *Session, primary bool) (*Session, error)

Executor ..

func (*PoolCluster) Fetch

func (c *PoolCluster) Fetch(dst interface{}, opts ...Option) error

Fetch fetch record to model

func (*PoolCluster) FetchAll

func (c *PoolCluster) FetchAll(dst interface{}, opts ...Option) error

FetchAll fetch records to models

func (*PoolCluster) Insert

func (c *PoolCluster) Insert(dst interface{}, opts ...Option) (Result, error)

Insert insert from model

func (*PoolCluster) Primary added in v0.2.0

func (c *PoolCluster) Primary() (*Session, error)

Primary select primary db

func (*PoolCluster) Query added in v0.1.1

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

Query ..

func (*PoolCluster) QueryContext added in v0.1.1

func (c *PoolCluster) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

QueryContext ..

func (*PoolCluster) QueryRow added in v0.1.1

func (c *PoolCluster) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow ..

func (*PoolCluster) QueryRowContext added in v0.1.1

func (c *PoolCluster) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

QueryRowContext ..

func (*PoolCluster) Replace

func (c *PoolCluster) Replace(dst interface{}, opts ...Option) (Result, error)

Replace replace from model

func (*PoolCluster) Replica added in v0.2.0

func (c *PoolCluster) Replica(v uint64) (*Session, error)

Replica select replica db

func (*PoolCluster) Update

func (c *PoolCluster) Update(dst interface{}, opts ...Option) (Result, error)

Update update from model

type PoolClusterOpts

type PoolClusterOpts func(p *PoolCluster) *PoolCluster

PoolClusterOpts ..

func AddDb

func AddDb(driver, dsn string, opts ...DbOption) PoolClusterOpts

AddDb add a db

type Result

type Result sql.Result

Result sql Result

type SQLSegments

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

SQLSegments ...

func NewSQLSegment

func NewSQLSegment() *SQLSegments

NewSQLSegment ..

func (*SQLSegments) Args

func (s *SQLSegments) Args() []interface{}

Args for set some args

func (*SQLSegments) Build

func (s *SQLSegments) Build() (string, []interface{})

Build for build a sql with SQLSegments

func (*SQLSegments) BuildDelete

func (s *SQLSegments) BuildDelete() string

BuildDelete build a delete sql

func (*SQLSegments) BuildInsert

func (s *SQLSegments) BuildInsert() string

BuildInsert ...

func (*SQLSegments) BuildReplace

func (s *SQLSegments) BuildReplace() string

BuildReplace build a replace sql

func (*SQLSegments) BuildSelect

func (s *SQLSegments) BuildSelect() string

BuildSelect ...

func (*SQLSegments) BuildUpdate

func (s *SQLSegments) BuildUpdate() string

BuildUpdate build a update sql

func (*SQLSegments) CorssJoin

func (s *SQLSegments) CorssJoin(table string, conditionA, logic, conditionB string) *SQLSegments

CorssJoin SQLSegments

func (*SQLSegments) Delete

func (s *SQLSegments) Delete() *SQLSegments

Delete for a part of delete sql

func (*SQLSegments) Field

func (s *SQLSegments) Field(fields ...string) *SQLSegments

Field SQLSegments

func (*SQLSegments) Flag

func (s *SQLSegments) Flag(flags ...string) *SQLSegments

Flag SQLSegments

func (*SQLSegments) ForUpdate

func (s *SQLSegments) ForUpdate() *SQLSegments

ForUpdate SQLSegments

func (*SQLSegments) GroupBy

func (s *SQLSegments) GroupBy(fields ...string) *SQLSegments

GroupBy SQLSegments

func (*SQLSegments) Having

func (s *SQLSegments) Having(key interface{}, vals ...interface{}) *SQLSegments

Having ...

func (*SQLSegments) InnerJoin

func (s *SQLSegments) InnerJoin(table string, conditionA, logic, conditionB string) *SQLSegments

InnerJoin SQLSegments

func (*SQLSegments) Insert

func (s *SQLSegments) Insert(vals ...map[string]interface{}) *SQLSegments

Insert ...

func (*SQLSegments) IsEmptyWhereClause

func (s *SQLSegments) IsEmptyWhereClause() bool

IsEmptyWhereClause ...

func (*SQLSegments) Join

func (s *SQLSegments) Join(table string, conditionA, logic, conditionB string) *SQLSegments

Join SQLSegments

func (*SQLSegments) LeftJoin

func (s *SQLSegments) LeftJoin(table string, conditionA, logic, conditionB string) *SQLSegments

LeftJoin SQLSegments

func (*SQLSegments) Limit

func (s *SQLSegments) Limit(n int) *SQLSegments

Limit SQLSegments

func (*SQLSegments) Offset

func (s *SQLSegments) Offset(n int) *SQLSegments

Offset SQLSegments

func (*SQLSegments) OrWhere

func (s *SQLSegments) OrWhere(key interface{}, vals ...interface{}) *SQLSegments

OrWhere ..

func (*SQLSegments) OrderBy

func (s *SQLSegments) OrderBy(fields ...string) *SQLSegments

OrderBy SQLSegments

func (*SQLSegments) Params

func (s *SQLSegments) Params(vals ...map[string]interface{}) *SQLSegments

Params ...

func (*SQLSegments) Returning

func (s *SQLSegments) Returning() *SQLSegments

Returning SQLSegments

func (*SQLSegments) RightJoin

func (s *SQLSegments) RightJoin(table string, conditionA, logic, conditionB string) *SQLSegments

RightJoin SQLSegments

func (*SQLSegments) Table

func (s *SQLSegments) Table(name interface{}) *SQLSegments

Table SQLSegments

func (*SQLSegments) Union

func (s *SQLSegments) Union(f func(*SQLSegments)) *SQLSegments

Union ...

func (*SQLSegments) UnsafeUpdate

func (s *SQLSegments) UnsafeUpdate(vals map[string]interface{}) *SQLSegments

UnsafeUpdate 可以没有where条件更新 ,Update 更新必须指定where条件才能更新否则panic

func (*SQLSegments) Update

func (s *SQLSegments) Update(vals map[string]interface{}) *SQLSegments

Update ..

func (*SQLSegments) UpdateField

func (s *SQLSegments) UpdateField(key string, val interface{}) *SQLSegments

UpdateField for set a field when update sql

func (*SQLSegments) Where

func (s *SQLSegments) Where(key interface{}, vals ...interface{}) *SQLSegments

Where ..

type Session

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

Session ..

func (*Session) Commit

func (s *Session) Commit() error

Commit ..

func (*Session) Delete

func (s *Session) Delete(dst interface{}, opts ...Option) (Result, error)

Delete ..

func (*Session) Exec

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

Exec ..

func (*Session) ExecContext

func (s *Session) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

ExecContext ..

func (*Session) Executor

func (s *Session) Executor() (Executor, error)

Executor ..

func (*Session) Fetch

func (s *Session) Fetch(dst interface{}, opts ...Option) error

Fetch ..

func (*Session) FetchAll

func (s *Session) FetchAll(dst interface{}, opts ...Option) error

FetchAll ..

func (*Session) Insert

func (s *Session) Insert(dst interface{}, opts ...Option) (Result, error)

Insert ..

func (*Session) Query

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

Query ..

func (*Session) QueryContext

func (s *Session) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

QueryContext ..

func (*Session) QueryRow

func (s *Session) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow ..

func (*Session) QueryRowContext

func (s *Session) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

QueryRowContext ..

func (*Session) Replace

func (s *Session) Replace(dst interface{}, opts ...Option) (Result, error)

Replace ..

func (*Session) Rollback

func (s *Session) Rollback() error

Rollback ..

func (*Session) Update

func (s *Session) Update(dst interface{}, opts ...Option) (Result, error)

Update ..

type Sub

type Sub int

Sub ..

type TbName

type TbName struct {
	Name  string
	Alias string
}

TbName ..

type Tx

type Tx interface {
	StmtContext(context.Context, *sql.Stmt) *sql.Stmt
	Stmt(*sql.Stmt) *sql.Stmt
	Commit() error
	Rollback() error
}

Tx ..

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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