gosql 一款 golang style 语法的 golang ORM 库

最近开源了gosql 一款golang style语法的golang orm库.

优雅的语法,支持批量插入,轻松嵌套条件,处理各种复杂的查询sql,诸如: and 和or组合
全语法支持: for update锁,is null, exists 子查询等基本上所有sql语法

风格如下:

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")
    }),
    GroupBy("type"),
    OrderBy("score DESC"),
)

特点

  • Golang-style SQL builder go语言风格sql生成
  • Unlimited nesting query 查询条件无限嵌套
  • Reading and Writing Separation 读写分离
  • Delay connection creation 延迟创建连接
  • ORM maping to sturct ORM映射结构体
  • Transactions 事务支持
  • Versatile 功能多样的
  • Clean Code 简洁的代码
  • Bulk Insert 支持批量插入

仓库地址:

github.com/rushteam/gosql

讨论数量: 1

支持读写分离,完整的例子:

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)
}
3天前 评论

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!