A golang orm library

Recently open sourced gosql golang orm library with golang style syntax.

Elegant syntax, support batch insertion, easily nested conditions, handle various complex query SQL, such as: and , or combination
Full syntax support: for update lock, is null, exists subquery, etc. Basically all SQL syntax

The style is as follows:

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"),
)

Features

-Golang-style SQL generation
-Unlimited nesting query
-Reading and Writing Separation
-Delay connection creation
-ORM mapping structure
-Transactions transaction support
-Versatile versatile
-Clean Code
-supports bulk insert

github:

https://github.com/rushteam/gosql

3 Likes

The SQL builder style looks quite strange. How is the Go code in the example any easier to read then the SQL? The same can be said for the conditional expressions. Why not just write SQL?

Thanks for reading, usually when writing native SQL, you will find some problems:
The placeholder for the β€œin” condition needs to be determined according to the parameters
The number of where conditions is not easy to determine

DEMO:

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)
}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.