Skip to content

forgoer/torm

Repository files navigation

ThinkORM

ThinkORM is a simple and Powerful ORM for Go.

Build Status Go Report Card Go Report Card GoDoc Join the chat Latest Stable Version License

Installation

go get github.com/thinkoner/torm

Quick start

Get the database connection:
config := torm.Config{
		Driver: "mysql",
		Dsn:    "root:abc-123@tcp(127.0.0.1:3306)/test?charset=utf8&parseTime=true",
	}
db, _ := torm.Open(config)
Query Builder:
type User struct {
	Name      string `torm:"column:name"`
	Gender    string `torm:"column:gender"`
	Addr      string
	BirthDate string
	Balance   float64
	CreatedAt time.Time
	UpdatedAt time.Time
}

func (u *User) TableName() string {
	return "users"
}

var users []User
db.Table("users").
	Where("gender", "M").
	Where("name", "like", "%a%").
	WhereColumn("created_at", "!=", "updated_at").
	WhereIn("addr", []interface{}{"Columbia", "Alaska"}).
	WhereBetween("birth_date", []interface{}{"1990-01-01", "1999-12-31"}).
	Get(&users)

License

This project is licensed under the Apache 2.0 license.

Contact

If you have any issues or feature requests, please contact us. PR is welcomed.