RawMap
This commit is contained in:
parent
d2f2f75f61
commit
2bcd0eb0d9
50
README.md
50
README.md
@ -1,40 +1,28 @@
|
|||||||
# GORM
|
# AuOrm
|
||||||
|
基于gorm 实现对原生查询的[]map[string]string{}返回
|
||||||
|
|
||||||
The fantastic ORM library for Golang, aims to be developer friendly.
|
- 支持增删改查
|
||||||
|
- 支持事物操作
|
||||||
|
|
||||||
[](https://goreportcard.com/report/github.com/jinzhu/gorm)
|
Installation
|
||||||
[](https://app.wercker.com/project/byKey/8596cace912c9947dd9c8542ecc8cb8b)
|
------------
|
||||||
[](https://gitter.im/jinzhu/gorm?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
||||||
[](https://opencollective.com/gorm)
|
|
||||||
[](https://opencollective.com/gorm)
|
|
||||||
[](http://opensource.org/licenses/MIT)
|
|
||||||
[](https://godoc.org/github.com/jinzhu/gorm)
|
|
||||||
|
|
||||||
## Overview
|
Use go get.
|
||||||
|
|
||||||
* Full-Featured ORM (almost)
|
go get github.com/Jetereting/gorm
|
||||||
* Associations (Has One, Has Many, Belongs To, Many To Many, Polymorphism)
|
|
||||||
* Hooks (Before/After Create/Save/Update/Delete/Find)
|
|
||||||
* Preloading (eager loading)
|
|
||||||
* Transactions
|
|
||||||
* Composite Primary Key
|
|
||||||
* SQL Builder
|
|
||||||
* Auto Migrations
|
|
||||||
* Logger
|
|
||||||
* Extendable, write Plugins based on GORM callbacks
|
|
||||||
* Every feature comes with tests
|
|
||||||
* Developer Friendly
|
|
||||||
|
|
||||||
## Getting Started
|
Then import the validator package into your own code.
|
||||||
|
|
||||||
* GORM Guides [http://gorm.io](http://gorm.io)
|
import "github.com/Jetereting/gorm"
|
||||||
|
|
||||||
## Contributing
|
示例:
|
||||||
|
```golang
|
||||||
|
datas, e := DB.RawMap("select * from users where user_id=?", 123)
|
||||||
|
if e != nil {
|
||||||
|
fmt.Println("err:", e)
|
||||||
|
}
|
||||||
|
fmt.Println("datas:", datas)
|
||||||
|
```
|
||||||
|
|
||||||
[You can help to deliver a better GORM, check out things you can do](http://gorm.io/contribute.html)
|
更多示例参照: [Au-ORM 测试](https://github.com/Jetereting/gorm/master/gorm_test.go)
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
© Jinzhu, 2013~time.Now
|
|
||||||
|
|
||||||
Released under the [MIT License](https://github.com/jinzhu/gorm/blob/master/License)
|
|
||||||
|
66
gorm_test.go
Normal file
66
gorm_test.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package gorm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Jetereting/gorm"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
db *gorm.DB
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
db, err = gorm.Open("mysql", "user:password@tcp(ip:port)/dbName?charset=utf8")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestQuery 测试查询
|
||||||
|
func TestQuery(t *testing.T) {
|
||||||
|
datas, e := db.RawMap("select * from users where user_id=?", 123)
|
||||||
|
if e != nil {
|
||||||
|
fmt.Println("err:", e)
|
||||||
|
}
|
||||||
|
fmt.Println("datas:", datas)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestIsCanInsert 测试插入
|
||||||
|
func TestIsCanInsert(t *testing.T) {
|
||||||
|
_, e := db.RawMap("insert into users(user_id,user_name,user_tag) values (?,?,?)", 123, "testName", "testTag")
|
||||||
|
if e != nil {
|
||||||
|
fmt.Println("err:", e)
|
||||||
|
}
|
||||||
|
fmt.Println("It work!")
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestIsCanUpdate 测试更新
|
||||||
|
func TestIsCanUpdate(t *testing.T) {
|
||||||
|
_, e := db.RawMap("update users set user_name=? where user_id=?", "testName2", 123)
|
||||||
|
if e != nil {
|
||||||
|
fmt.Println("err:", e)
|
||||||
|
}
|
||||||
|
fmt.Println("It work!")
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestTX 测试事物
|
||||||
|
func TestTX(t *testing.T) {
|
||||||
|
tx := db.Begin()
|
||||||
|
_, e := tx.RawMap("update users set user_name=? where user_id=?", "testName3", 123)
|
||||||
|
if e != nil {
|
||||||
|
fmt.Println("err:", e)
|
||||||
|
tx.Rollback()
|
||||||
|
}
|
||||||
|
_, e = tx.RawMap("update users set user_name=? where user_id=?", "long text....long text....long text....long text....long text....long text....long text....", 123)
|
||||||
|
if e != nil {
|
||||||
|
fmt.Println("err:", e)
|
||||||
|
tx.Rollback()
|
||||||
|
}
|
||||||
|
tx.Commit()
|
||||||
|
fmt.Println("done!")
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user