Code Monkey home page Code Monkey logo

orm's Introduction

dao

import "github.com/afocus/dao"


func main(){
    c, _ := dao.Create("root:123456@(127.0.0.1:3306)/test?charset=utf8")
    s:=c.NewSession(context.Background())




    // insert 插入


    var u User // or map[string]string
    s.Table("user").Insert(&u)


    // 实现mysql insert on duplicate key update
    // 当存在时更新Cols指定的字段
    s.Table("user").Cols("name","age").Insert(&u)



    // 查询
    s.Table("user").Get(&u)
    // select * from user limit 1
    s.Table("user").Select("name","age").Where("id > ?",100).Get(&u)
    // select name, arge from user where (id > 100) limit 1

    var ulist []User
    s.Table("user").Where("age>?",20).And("sex = 1").OrderBy("age desc").Limit(10).Find(&ulist)
    // select * from user where (age > 20) and (sex = 1) order by age desc limit 1o

    s.Table("user").Limit(10,20).Find(&ulist)
    // select * from user limit 10,20

    s.Query("select * from user where id > ?", 100).Find(&ulist)

    s.Table("user").Count()
    // select count(1) from user




    //













}

orm's People

Contributors

bluefishbone avatar afocus avatar jack-laoniu avatar

Watchers

James Cloos avatar

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.