Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/daodao97/fly
One easy-to-use go db library
https://github.com/daodao97/fly
go golang orm sql
Last synced: about 2 months ago
JSON representation
One easy-to-use go db library
- Host: GitHub
- URL: https://github.com/daodao97/fly
- Owner: daodao97
- Created: 2022-03-18T12:48:02.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-07-26T06:58:49.000Z (over 1 year ago)
- Last Synced: 2024-06-19T09:12:22.208Z (6 months ago)
- Topics: go, golang, orm, sql
- Language: Go
- Homepage: https://daodao97.github.io/fly
- Size: 49.8 KB
- Stars: 81
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FLY
![](https://img.shields.io/badge/build-passing-brightgreen)
![](https://img.shields.io/badge/coverage-%2066.2%25-red)
![](https://img.shields.io/badge/license-MIT-blue)One easy-to-use go db library [简体中文](./README_zh.md), [Document](https://daodao97.github.io/fly)
- data hook, Easy transition db data
- sql builder, Not need handwritten SQL
- hasOne/hasMany, Convenient get linked data
- validator, Flexible verification policies
- extensible, Easy extend custom hook/sql/validator
- cacheEnable, Support for custom cache implementations# usages
more example please check out [model_test.go](./model_test.go)
```go
package mainimport (
"fmt""github.com/daodao97/fly"
_ "github.com/go-sql-driver/mysql"
)func init() {
err := fly.Init(map[string]*fly.Config{
"default": {DSN: "root@tcp(127.0.0.1:3306)/fly_test?&parseTime=true"},
})
if err != nil {
panic(err)
}
}func main() {
m := fly.New(
"user",
fly.ColumnHook(fly.CommaInt("role_id"), fly.Json("profile")),
)var err error
_, err = m.Insert(map[string]interface{}{
"name": "Seiya",
"profile": map[string]interface{}{
"hobby": "Pegasus Ryuseiken",
},
})var result []*User
err = m.Select(fly.WhereGt("id", 1)).Binding(&result)var result1 *User
err = m.SelectOne(fly.WhereEq("id", 1)).Binding(&result1)count, err := m.Count()
fmt.Println("count", count)_, err = m.Update(User{
ID: 1,
Name: "星矢",
Profile: &Profile{
Hobby: "天马流行拳",
},
RoleIds: []int{2, 3},
})_, err = m.Delete(fly.WhereEq("id", 1))
fmt.Println(err)
}type User struct {
ID int64 `db:"id"`
Name string `db:"name"`
Status int64 `db:"status"`
Profile *Profile `db:"profile"`
IsDeleted int `db:"is_deleted"`
RoleIds []int `db:"role_ids"`
Score int `db:"score"`
}type Profile struct {
Hobby string `json:"hobby"`
}
```