move lifetime to a split file so that go1.1 is also work with this feature (#612)

This commit is contained in:
Lunny Xiao 2017-06-08 10:21:01 +08:00 committed by GitHub
parent 8a877636fd
commit 7a9bf19c65
6 changed files with 67 additions and 65 deletions

2
doc.go
View File

@ -8,7 +8,7 @@ Package xorm is a simple and powerful ORM for Go.
Installation
Make sure you have installed Go 1.5+ and then:
Make sure you have installed Go 1.6+ and then:
go get github.com/go-xorm/xorm

View File

@ -195,11 +195,6 @@ func (engine *Engine) SetMaxIdleConns(conns int) {
engine.db.SetMaxIdleConns(conns)
}
// SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
func (engine *Engine) SetConnMaxLifetime(d time.Duration) {
engine.db.SetConnMaxLifetime(d)
}
// SetDefaultCacher set the default cacher. Xorm's default not enable cacher.
func (engine *Engine) SetDefaultCacher(cacher core.Cacher) {
engine.Cacher = cacher

14
engine_maxlife.go Normal file
View File

@ -0,0 +1,14 @@
// Copyright 2017 The Xorm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build go1.6
package xorm
import "time"
// SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
func (engine *Engine) SetConnMaxLifetime(d time.Duration) {
engine.db.SetConnMaxLifetime(d)
}

View File

@ -1,59 +0,0 @@
// Copyright 2017 The Xorm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package xorm
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestAutoIncrTag(t *testing.T) {
assert.NoError(t, prepareEngine())
type TestAutoIncr1 struct {
Id int64
}
tb := testEngine.TableInfo(new(TestAutoIncr1))
cols := tb.Columns()
assert.EqualValues(t, 1, len(cols))
assert.True(t, cols[0].IsAutoIncrement)
assert.True(t, cols[0].IsPrimaryKey)
assert.Equal(t, "id", cols[0].Name)
type TestAutoIncr2 struct {
Id int64 `xorm:"id"`
}
tb = testEngine.TableInfo(new(TestAutoIncr2))
cols = tb.Columns()
assert.EqualValues(t, 1, len(cols))
assert.False(t, cols[0].IsAutoIncrement)
assert.False(t, cols[0].IsPrimaryKey)
assert.Equal(t, "id", cols[0].Name)
type TestAutoIncr3 struct {
Id int64 `xorm:"'ID'"`
}
tb = testEngine.TableInfo(new(TestAutoIncr3))
cols = tb.Columns()
assert.EqualValues(t, 1, len(cols))
assert.False(t, cols[0].IsAutoIncrement)
assert.False(t, cols[0].IsPrimaryKey)
assert.Equal(t, "ID", cols[0].Name)
type TestAutoIncr4 struct {
Id int64 `xorm:"pk"`
}
tb = testEngine.TableInfo(new(TestAutoIncr4))
cols = tb.Columns()
assert.EqualValues(t, 1, len(cols))
assert.False(t, cols[0].IsAutoIncrement)
assert.True(t, cols[0].IsPrimaryKey)
assert.Equal(t, "id", cols[0].Name)
}

View File

@ -1,3 +1,7 @@
// Copyright 2017 The Xorm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package xorm
import "testing"

View File

@ -187,3 +187,51 @@ func TestLowerCase(t *testing.T) {
panic(err)
}
}
func TestAutoIncrTag(t *testing.T) {
assert.NoError(t, prepareEngine())
type TestAutoIncr1 struct {
Id int64
}
tb := testEngine.TableInfo(new(TestAutoIncr1))
cols := tb.Columns()
assert.EqualValues(t, 1, len(cols))
assert.True(t, cols[0].IsAutoIncrement)
assert.True(t, cols[0].IsPrimaryKey)
assert.Equal(t, "id", cols[0].Name)
type TestAutoIncr2 struct {
Id int64 `xorm:"id"`
}
tb = testEngine.TableInfo(new(TestAutoIncr2))
cols = tb.Columns()
assert.EqualValues(t, 1, len(cols))
assert.False(t, cols[0].IsAutoIncrement)
assert.False(t, cols[0].IsPrimaryKey)
assert.Equal(t, "id", cols[0].Name)
type TestAutoIncr3 struct {
Id int64 `xorm:"'ID'"`
}
tb = testEngine.TableInfo(new(TestAutoIncr3))
cols = tb.Columns()
assert.EqualValues(t, 1, len(cols))
assert.False(t, cols[0].IsAutoIncrement)
assert.False(t, cols[0].IsPrimaryKey)
assert.Equal(t, "ID", cols[0].Name)
type TestAutoIncr4 struct {
Id int64 `xorm:"pk"`
}
tb = testEngine.TableInfo(new(TestAutoIncr4))
cols = tb.Columns()
assert.EqualValues(t, 1, len(cols))
assert.False(t, cols[0].IsAutoIncrement)
assert.True(t, cols[0].IsPrimaryKey)
assert.Equal(t, "id", cols[0].Name)
}