GithubHelp home page GithubHelp logo

sqlx-builder-go's Introduction

sqlx-builder

用于实现sqlx的链式操作

安装

go get github.com/laoqiu/sqlx-builder

初始化

import (
	sqlxb "github.com/laoqiu/sqlx-builder"
)
db, err := sqlxb.Connect()
if err != nil {
	return err
}
// 加载mapper
builder.LoadMapper(db, sqlxb.DefaultMapper)

支持的链式操作

dest := &Person{}
p := map[string]interface{}{
    "phone": "13012345678",
}
debug := true
query = sqlxb.Table("tablename").Join("table2", "table2.id = table1.t_id").
    Where("name like ?", "%name%").
    Where("address = ?", "test").
    Where("phone = :phone", p)
err := sqlxb.New(db, query, debug).First(dest)
if err != nil {
    log.Println(err) 
}

支持的函数及结构体

  • Builder
func New(*sqlx.DB, *Query, debug bool) *Builder
func NewTx(*sqlx.Tx, *Query, debug bool) *Builder
func (st *Builder) Insert(data interface{}) error
func (st *Builder) Update(data interface{}) error
func (st *Builder) Delete() error
func (st *Builder) Get(dest interface{}) (sql.Result, error)
func (st *Builder) All(dest interface{}) (sql.Result, error)
  • Query
func Table(tablename) *Query
func (q *Query) Distinct() *Query
func (q *Query) Select(...fields) *Query
func (q *Query) Join(table, condition, label) *Query
func (q *Query) LeftJoin(table, condition, label) *Query
func (q *Query) RightJoin(table, condition, label) *Query
func (q *Query) UnionJoin(table, condition, label) *Query
func (q *Query) Where(condition, ...args) *Query
func (q *Query) Limit(n) *Query
func (q *Query) Offset(n) *Query
  • func Connect
  • func LoadMapper

sqlx-builder-go's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.