English | ä¸æ–‡
Miniorm is a lightful and fast orm framework.The API mainly refers to Gorm and Xorm, and the purpose is to provide users with a more easy and free framework.
This project began as a way to learn Golang. Don't use in any production environment.
- Easy API supported
- More freedom SQL API supported
- Table CRUD and primary key settings
- Record CRUD
- Transaction
- Hooks
- Support for chain calls
- ...
Import miniorm in the applicaton
go get -u github.com/nc-77/miniorm
package main
import (
"fmt"
"github.com/nc-77/miniorm"
_ "github.com/go-sql-driver/mysql"
)
type User struct {
Id uint `miniorm:"PRIMARY KEY"`
Name string
Age int
IsValid bool
}
func main(){
db, err := miniorm.Open("mysql", "root:123456@tcp(localhost)/test")
if err != nil {
panic(err)
}
// Create Table
db.CreateTable(User{})
// Records
users := []User{{Id: 1, Name: "nic", Age: 11, IsValid: true}, {Id: 2, Name: "nc-77", Age: 22, IsValid: true}, {Id: 3, Name: "nc-77", Age: 11, IsValid: false}}
// Create
db.Create(users[0], users[1], users[2])
db.CreateMany(users)
// Find all records
result := db.Find(&foundUsers)
fmt.Println(result.RowsAffected)
// Find specific records
db.Where("IsValid = ?", false).Limit(1).Find(&foundUsers)
db.Where("IsValid = ? and Age = ?", true, 22).First(&foundUser)
...
return
}
Please see example.go for more imformation
- More API supported
- More Database supported
- More complete documentation and notes