Skip to content

Commit

Permalink
[xorm] Support xorm v0.6.3 and use Go1.9 on CI (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
evalphobia authored Sep 4, 2017
1 parent c99a6c7 commit d1c1f95
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 26 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
sudo: false
language: go
go:
- 1.5
- 1.8
- 1.9
- tip
matrix:
allow_failures:
- go: tip
before_install:
- if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
- go get golang.org/x/tools/cmd/cover
- go get github.com/golang/lint/golint
- go get github.com/modocache/gover
- go get -d github.com/stretchr/testify/assert github.com/go-sql-driver/mysql github.com/mattn/go-sqlite3
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Wizard
[![Build Status](https://travis-ci.org/evalphobia/wizard.svg?branch=master)](https://travis-ci.org/evalphobia/wizard) [![codecov.io](https://codecov.io/github/evalphobia/wizard/coverage.svg?branch=master)](https://codecov.io/github/evalphobia/wizard?branch=master)
[![GoDoc](https://godoc.org/github.com/evalphobia/wizard?status.svg)](https://godoc.org/github.com/evalphobia/wizard) [![Join the chat at https://gitter.im/evalphobia/wizard](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/evalphobia/wizard?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Wizard is database/sql management library for multi instance and sharding in golang.
Wizard is database/sql management library for multi instance and sharding in golang.
Inspired by [MixedGauge](https://github.com/taiki45/mixed_gauge)

## Supported orm list
Expand Down Expand Up @@ -144,3 +144,7 @@ func main() {
- Struct field tag: `shard_key:"true"` is used as a shard-key
- shard_key is divided by slot size and the mod value is used for shard mapping
- string shard_key convert to int64 with CRC64 and divided by slot-size

### Other info

- Slide ["golang.tokyo #7 Wizard"](https://www.slideshare.net/TakumaMorikawa/golangtokyo-7-wizard-database-sharding-library-for-golang)
12 changes: 6 additions & 6 deletions orm/xorm/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type User struct {
Name string `xorm:"varchar(255) not null"`
}

func ExampleRegisterStandardDatabases() {
func _ExampleRegisterStandardDatabases() {
engine1, _ = xorm.NewEngine("mysql", "root:@/example_user?charset=utf8")
engine2, _ = xorm.NewEngine("mysql", "root:@/example_user?charset=utf8")
engine3, _ = xorm.NewEngine("mysql", "root:@/example_foobar?charset=utf8")
Expand All @@ -33,7 +33,7 @@ func ExampleRegisterStandardDatabases() {
w.SetDefault(stndardCluster) // engine4 is master database used for all the other tables
}

func ExampleRegisterShardedDatabase() {
func _ExampleRegisterShardedDatabase() {
engine1, _ = xorm.NewEngine("mysql", "root:@/example_user_a?charset=utf8")
engine2, _ = xorm.NewEngine("mysql", "root:@/example_user_a?charset=utf8")
engine3, _ = xorm.NewEngine("mysql", "root:@/example_user_b?charset=utf8")
Expand All @@ -50,7 +50,7 @@ func ExampleRegisterShardedDatabase() {
shardClusters.RegisterShard(501, 996, standardClusterB)
}

func ExampleGet() {
func _ExampleGet() {
orm := New(w)

user := &User{ID: 99}
Expand All @@ -69,7 +69,7 @@ func ExampleGet() {
fmt.Printf("user found. id:%d, name:%s", user.ID, user.Name)
}

func ExampleInsert() {
func _ExampleInsert() {
orm := New(w)

user := &User{ID: 99, Name: "Adam Smith"}
Expand All @@ -86,7 +86,7 @@ func ExampleInsert() {
}
}

func ExampleTransaction() {
func _ExampleTransaction() {
var err error
orm := New(w)

Expand All @@ -109,7 +109,7 @@ func ExampleTransaction() {
orm.CommitAll(testID)
}

func ExampleTransactionAuto() {
func _ExampleTransactionAuto() {
var err error
orm := New(w)

Expand Down
25 changes: 11 additions & 14 deletions orm/xorm/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package xorm
import (
"database/sql"
"io"
"time"

"github.com/go-xorm/core"
"github.com/go-xorm/xorm"
Expand Down Expand Up @@ -53,14 +52,15 @@ type ORM interface {
CloseAll(Identifier)
}

// Session is interface for xorm.Session
// Session is interface for xorm.Session.
// (xorm v0.6.3)
type Session interface {
Init()
Close()
Sql(string, ...interface{}) *xorm.Session
Where(string, ...interface{}) *xorm.Session
And(string, ...interface{}) *xorm.Session
Or(string, ...interface{}) *xorm.Session
Where(interface{}, ...interface{}) *xorm.Session
And(interface{}, ...interface{}) *xorm.Session
Or(interface{}, ...interface{}) *xorm.Session

Id(interface{}) *xorm.Session
Table(interface{}) *xorm.Session
Expand Down Expand Up @@ -100,7 +100,7 @@ type Session interface {
Rows(interface{}) (*xorm.Rows, error)
Iterate(interface{}, xorm.IterFunc) error
Get(interface{}) (bool, error)
Count(interface{}) (int64, error)
Count(...interface{}) (int64, error)
Find(interface{}, ...interface{}) error

IsTableExist(interface{}) (bool, error)
Expand Down Expand Up @@ -141,11 +141,11 @@ type Engine interface {

Sql(string, ...interface{}) *xorm.Session
NoAutoTime() *xorm.Session
DumpAllToFile(string) error
DumpAll(io.Writer) error
DumpAllToFile(string, ...core.DbType) error
DumpAll(io.Writer, ...core.DbType) error

Cascade(...bool) *xorm.Session
Where(string, ...interface{}) *xorm.Session
Where(interface{}, ...interface{}) *xorm.Session
Id(interface{}) *xorm.Session

Before(func(interface{})) *xorm.Session
Expand Down Expand Up @@ -196,14 +196,11 @@ type Engine interface {
Find(interface{}, ...interface{}) error
Iterate(interface{}, xorm.IterFunc) error
Rows(interface{}) (*xorm.Rows, error)
Count(interface{}) (int64, error)
Count(...interface{}) (int64, error)

ImportFile(string) ([]sql.Result, error)
Import(io.Reader) ([]sql.Result, error)

TZTime(time.Time) time.Time
NowTime(string) interface{}
NowTime2(string) (interface{}, time.Time)
FormatTime(string, time.Time) interface{}
ShowSQL(...bool)
Unscoped() *xorm.Session
}
2 changes: 1 addition & 1 deletion orm/xorm/xorm_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestFind(t *testing.T) {

var foobars []*testFoobar
err = orm.Find(&testFoobar{}, func(s Session) error {
s.Id(1)
s.And("id = 1")
return s.Find(&foobars)
})
assert.Nil(err)
Expand Down
4 changes: 2 additions & 2 deletions orm/xorm/xorm_parallel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ func TestCountParallelByCondition(t *testing.T) {
counts, err := orm.CountParallelByCondition(&testObj, cond)
assert.Nil(err)
assert.Len(counts, 2)
assert.Equal(counts[0], int64(3))
assert.Equal(counts[1], int64(2))
assert.Contains(counts, int64(3))
assert.Contains(counts, int64(2))
}

0 comments on commit d1c1f95

Please sign in to comment.