Code Monkey home page Code Monkey logo

go-dao's Introduction

go-dao

一个Go语言的ORM简单库, 主要功能就是通过反射Struct的属性推导出sql语句.

类似的库有: sqlx ,但是它是把查询结果集*Row 装配成[]Sturct, sql语句还是需要手写

Example

db, _ := dao.Open("sqlite3", dbFile)

tom := User{1, "tom", "tom123"}
jake := User{2, "jake", "jake123"}
db.Save(tom)
db.Save(jake)

var list []User
err = db.List(&list)

fmt.Printf("%#v\n", list)
//Output: []dao.User{dao.User{Id:0x1, Name:"tom", Pwd:"tom123"}, dao.User{Id:0x2, Name:"jake", Pwd:"jake123"}}

tom.Name = "tom99"
db.Update(tom,"where id=?",1)

err = db.List(&list)
fmt.Printf("%#v\n", list)
//Output: []dao.User{dao.User{Id:0x1, Name:"tom99", Pwd:"tom123"}, dao.User{Id:0x2, Name:"jake", Pwd:"jake123"}}

Benchmark

# 分析Struct不用cache的速度
BenchmarkParseStruct-2            500000              3102 ns/op
# 使用cache
BenchmarkParseStructUseCache-2  10000000               142 ns/op

# 原生手写sql的速度
BenchmarkInsertReference-2          5000            417416 ns/op
# 框架库
BenchmarkInsert-2                   5000            429126 ns/op

go-dao's People

Contributors

pangliang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.