Giter Club home page Giter Club logo

sqlo's Introduction

sqlo:一个简单的支持mysql sql拼接的工具包,支持链式调用

   var engine Engine
   
   func init() {
   	engine, _ = Connect("root:123@tcp(127.0.0.1)/demo?charset=utf8&parseTime=True&loc=Local")
   
   }
   
   func TestCount(t *testing.T) {
   
   	//select a,b from wx where name=? and age = ? order by id desc limit 0 ,10
   	sql := engine.
   		Select("a", "b").From("wx").Alias("w").
   		Where("id").
   		And("name", "age").
   		OrderBy("id desc").Limit(0, 10).
   		String()
   	t.Log(sql)
   	//两种执行sql的方式
   	//sqlo封装的query
   	engine.Query(sql,"aaa","bbb")
   	//database/sql原生的query
   	engine.DB().Query(sql,"aaa","bbb")
   }
   
   func TestDb_Delete(t *testing.T) {
   	sql := engine.
   		Delete("wx").
   		Where("id").
   		And("name").
   		String()
   	t.Log(sql)
   }
   
   func TestDb_Update(t *testing.T) {
   	sql := engine.Update("wx").Fields("a", "b").Where("c").String()
   	t.Log(sql)
   }
   func TestDb_Insert(t *testing.T) {
   	sql := engine.Insert("wx").
   		Cols("a", "b").
   		String()
   	t.Log(sql)
   }
   
   func TestDb_Like(t *testing.T) {
   	sql := engine.Select("a", "b").From("wx").Where("id").Like("name").String()
   	t.Log(sql)
   }
   
   // SELECT name, COUNT(*) FROM   employee_tbl GROUP BY name;
   func TestDb_GroupBy(t *testing.T) {
   	sql := engine.Select("id").Count("name").From("wx").GroupBy("name", "id").String()
   	t.Log(sql)
   }
   
   /**
   	SELECT a.runoob_id, a.runoob_author, b.runoob_count FROM runoob_tbl a
   INNER JOIN tcount_tbl b ON a.runoob_author = b.runoob_author;
   */
   func TestDb_InnerJoin(t *testing.T) {
   	sql := engine.Select("a.runoob_id", "a.runoob_author", "b.runoob_count").
   		From(" runoob_tbl a").
   		InnerJoin("tcount_tbl b").On("a.runoob_author=").And("a=", "b=").String()
   	t.Log(sql)
   }

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.