move lifetime to a split file so that go1.1 is also work with this feature (#612)
This commit is contained in:
parent
8a877636fd
commit
7a9bf19c65
2
doc.go
2
doc.go
|
@ -8,7 +8,7 @@ Package xorm is a simple and powerful ORM for Go.
|
||||||
|
|
||||||
Installation
|
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
|
go get github.com/go-xorm/xorm
|
||||||
|
|
||||||
|
|
|
@ -195,11 +195,6 @@ func (engine *Engine) SetMaxIdleConns(conns int) {
|
||||||
engine.db.SetMaxIdleConns(conns)
|
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.
|
// SetDefaultCacher set the default cacher. Xorm's default not enable cacher.
|
||||||
func (engine *Engine) SetDefaultCacher(cacher core.Cacher) {
|
func (engine *Engine) SetDefaultCacher(cacher core.Cacher) {
|
||||||
engine.Cacher = cacher
|
engine.Cacher = cacher
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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
|
package xorm
|
||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
48
tag_test.go
48
tag_test.go
|
@ -187,3 +187,51 @@ func TestLowerCase(t *testing.T) {
|
||||||
panic(err)
|
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)
|
||||||
|
}
|
Loading…
Reference in New Issue