diff --git a/dialect_sqlite3.go b/dialect_sqlite3.go index c13fd02b..a55b1615 100644 --- a/dialect_sqlite3.go +++ b/dialect_sqlite3.go @@ -14,10 +14,6 @@ import ( "github.com/go-xorm/core" ) -// func init() { -// RegisterDialect("sqlite3", &sqlite3{}) -// } - var ( sqlite3ReservedWords = map[string]bool{ "ABORT": true, @@ -310,11 +306,25 @@ func (db *sqlite3) GetColumns(tableName string) ([]string, map[string]*core.Colu for _, colStr := range colCreates { reg = regexp.MustCompile(`,\s`) colStr = reg.ReplaceAllString(colStr, ",") + if strings.HasPrefix(strings.TrimSpace(colStr), "PRIMARY KEY") { + parts := strings.Split(strings.TrimSpace(colStr), "(") + if len(parts) == 2 { + pkCols := strings.Split(strings.TrimRight(strings.TrimSpace(parts[1]), ")"), ",") + for _, pk := range pkCols { + if col, ok := cols[strings.Trim(strings.TrimSpace(pk), "`")]; ok { + col.IsPrimaryKey = true + } + } + } + continue + } + fields := strings.Fields(strings.TrimSpace(colStr)) col := new(core.Column) col.Indexes = make(map[string]int) col.Nullable = true col.DefaultIsEmpty = true + for idx, field := range fields { if idx == 0 { col.Name = strings.Trim(strings.Trim(field, "`[] "), `"`) diff --git a/doc.go b/doc.go index 5b36fcd8..9944bcd8 100644 --- a/doc.go +++ b/doc.go @@ -8,7 +8,7 @@ Package xorm is a simple and powerful ORM for Go. Installation -Make sure you have installed Go 1.1+ and then: +Make sure you have installed Go 1.5+ and then: go get github.com/go-xorm/xorm diff --git a/engine.go b/engine.go index b2b2f97b..5cc8da95 100644 --- a/engine.go +++ b/engine.go @@ -195,6 +195,11 @@ 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 diff --git a/session_pk_test.go b/session_pk_test.go index b9c70321..0dff9df7 100644 --- a/session_pk_test.go +++ b/session_pk_test.go @@ -7,6 +7,7 @@ package xorm import ( "errors" "testing" + "time" "github.com/go-xorm/core" "github.com/stretchr/testify/assert" @@ -1117,3 +1118,24 @@ func TestSingleAutoIncrColumn(t *testing.T) { _, err := testEngine.Insert(&Account{}) assert.NoError(t, err) } + +func TestCompositePK(t *testing.T) { + type TaskSolution struct { + UID string `xorm:"notnull pk UUID 'uid'"` + TID string `xorm:"notnull pk UUID 'tid'"` + Created time.Time `xorm:"created"` + Updated time.Time `xorm:"updated"` + } + + assert.NoError(t, prepareEngine()) + assertSync(t, new(TaskSolution)) + + assert.NoError(t, testEngine.Sync2(new(TaskSolution))) + tables, err := testEngine.DBMetas() + assert.NoError(t, err) + assert.EqualValues(t, 1, len(tables)) + pkCols := tables[0].PKColumns() + assert.EqualValues(t, 2, len(pkCols)) + assert.EqualValues(t, "uid", pkCols[0].Name) + assert.EqualValues(t, "tid", pkCols[1].Name) +} diff --git a/xorm.go b/xorm.go index 3e1e2e50..8b2fd6c6 100644 --- a/xorm.go +++ b/xorm.go @@ -17,7 +17,7 @@ import ( const ( // Version show the xorm's version - Version string = "0.6.2.0517" + Version string = "0.6.2.0605" ) func regDrvsNDialects() bool {