This commit is contained in:
Lunny Xiao 2016-04-22 21:43:22 +08:00
parent 21d219c872
commit 5c116a34d6
14 changed files with 29 additions and 57 deletions

View File

@ -1 +1 @@
xorm v0.5.3.0407
xorm v0.5.4.0422

18
doc.go
View File

@ -1,4 +1,4 @@
// Copyright 2013 - 2015 The Xorm Authors. All rights reserved.
// Copyright 2013 - 2016 The XORM Authors. All rights reserved.
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file.
@ -129,26 +129,28 @@ Attention: the above 7 methods should be the last chainable method.
5. Sql, let you custom SQL
engine.Sql("select * from user").Find()
var users []User
engine.Sql("select * from user").Find(&users)
6. Cols, Omit, Distinct
engine.Cols("col1, col2").Find()
var users []*User
engine.Cols("col1, col2").Find(&users)
// SELECT col1, col2 FROM user
engine.Cols("col1", "col2").Where().Update(user)
// UPDATE user set col1 = ?, col2 = ? Where ...
engine.Omit("col1").Find()
engine.Omit("col1").Find(&users)
// SELECT col2, col3 FROM user
engine.Omit("col1").Insert()
engine.Omit("col1").Insert(&user)
// INSERT INTO table (non-col1) VALUES ()
engine.Distinct("col1").Find()
engine.Distinct("col1").Find(&users)
// SELECT DISTINCT col1 FROM user
7. Join, GroupBy, Having
engine.GroupBy("name").Having("name='xlw'").Find()
engine.GroupBy("name").Having("name='xlw'").Find(&users)
//SELECT * FROM user GROUP BY name HAVING name='xlw'
engine.Join("LEFT", "userdetail", "user.id=userdetail.id").Find()
engine.Join("LEFT", "userdetail", "user.id=userdetail.id").Find(&users)
//SELECT * FROM user LEFT JOIN userdetail ON user.id=userdetail.id
More usage, please visit http://xorm.io/docs

View File

@ -13,10 +13,6 @@ import (
"github.com/go-xorm/core"
)
// func init() {
// RegisterDialect("mssql", &mssql{})
// }
var (
mssqlReservedWords = map[string]bool{
"ADD": true,

View File

@ -12,10 +12,6 @@ import (
"github.com/go-xorm/core"
)
// func init() {
// core.RegisterDriver("mymysql", &mymysqlDriver{})
// }
type mymysqlDriver struct {
}

View File

@ -15,10 +15,6 @@ import (
"github.com/go-xorm/core"
)
// func init() {
// RegisterDialect("mysql", &mysql{})
// }
var (
mysqlReservedWords = map[string]bool{
"ADD": true,

View File

@ -11,10 +11,6 @@ import (
"github.com/go-xorm/core"
)
// func init() {
// core.RegisterDriver("mysql", &mysqlDriver{})
// }
type mysqlDriver struct {
}

View File

@ -11,10 +11,6 @@ import (
"github.com/go-xorm/core"
)
// func init() {
// core.RegisterDriver("oci8", &oci8Driver{})
// }
type oci8Driver struct {
}

View File

@ -11,10 +11,6 @@ import (
"github.com/go-xorm/core"
)
// func init() {
// core.RegisterDriver("odbc", &odbcDriver{})
// }
type odbcDriver struct {
}

View File

@ -13,10 +13,6 @@ import (
"github.com/go-xorm/core"
)
// func init() {
// RegisterDialect("oracle", &oracle{})
// }
var (
oracleReservedWords = map[string]bool{
"ACCESS": true,

View File

@ -13,9 +13,6 @@ import (
"github.com/go-xorm/core"
)
// func init() {
// RegisterDialect("postgres", &postgres{})
// }
// from http://www.postgresql.org/docs/current/static/sql-keywords-appendix.html
var (
postgresReservedWords = map[string]bool{
@ -913,7 +910,8 @@ func (db *postgres) IsColumnExist(tableName, colName string) (bool, error) {
}
func (db *postgres) GetColumns(tableName string) ([]string, map[string]*core.Column, error) {
args := []interface{}{tableName, db.URI().Schema}
// FIXME: the schema should be replaced by user custom's
args := []interface{}{tableName, "public"}
s := `SELECT column_name, column_default, is_nullable, data_type, character_maximum_length, numeric_precision, numeric_precision_radix ,
CASE WHEN p.contype = 'p' THEN true ELSE false END AS primarykey,
CASE WHEN p.contype = 'u' THEN true ELSE false END AS uniquekey
@ -986,11 +984,13 @@ WHERE c.relkind = 'r'::char AND c.relname = $1 AND s.table_schema = $2 AND f.att
col.SQLType = core.SQLType{core.Bool, 0, 0}
case "time without time zone":
col.SQLType = core.SQLType{core.Time, 0, 0}
case "oid":
col.SQLType = core.SQLType{core.BigInt, 0, 0}
default:
col.SQLType = core.SQLType{strings.ToUpper(dataType), 0, 0}
}
if _, ok := core.SqlTypes[col.SQLType.Name]; !ok {
return nil, nil, errors.New(fmt.Sprintf("unkonw colType %v", dataType))
return nil, nil, errors.New(fmt.Sprintf("unknow colType: %v", dataType))
}
col.Length = maxLen
@ -1012,8 +1012,9 @@ WHERE c.relkind = 'r'::char AND c.relname = $1 AND s.table_schema = $2 AND f.att
}
func (db *postgres) GetTables() ([]*core.Table, error) {
args := []interface{}{}
s := fmt.Sprintf("SELECT tablename FROM pg_tables where schemaname = '%s'", db.Uri.Schema)
// FIXME: replace public to user customrize schema
args := []interface{}{"public"}
s := fmt.Sprintf("SELECT tablename FROM pg_tables WHERE schemaname = $1")
db.LogSQL(s, args)
rows, err := db.DB().Query(s, args...)
@ -1037,8 +1038,9 @@ func (db *postgres) GetTables() ([]*core.Table, error) {
}
func (db *postgres) GetIndexes(tableName string) (map[string]*core.Index, error) {
args := []interface{}{tableName}
s := fmt.Sprintf("SELECT indexname, indexdef FROM pg_indexes WHERE schemaname='%s' AND tablename=$1", db.URI().Schema)
// FIXME: replace the public schema to user specify schema
args := []interface{}{"public", tableName}
s := fmt.Sprintf("SELECT indexname, indexdef FROM pg_indexes WHERE schemaname=$1 AND tablename=$2")
db.LogSQL(s, args)
rows, err := db.DB().Query(s, args...)

View File

@ -14,10 +14,6 @@ import (
"github.com/go-xorm/core"
)
// func init() {
// core.RegisterDriver("postgres", &pqDriver{})
// }
type pqDriver struct {
}
@ -115,9 +111,9 @@ func (p *pqDriver) Parse(driverName, dataSourceName string) (*core.Uri, error) {
if db.DbName == "" {
return nil, errors.New("dbname is empty")
}
db.Schema = o.Get("schema")
/*db.Schema = o.Get("schema")
if len(db.Schema) == 0 {
db.Schema = "public"
}
}*/
return db, nil
}

View File

@ -3888,9 +3888,9 @@ func (session *Session) tbName(table *core.Table) string {
tbName = session.Statement.AltTableName
}
if len(session.Engine.dialect.URI().Schema) > 0 {
/*if len(session.Engine.dialect.URI().Schema) > 0 {
return session.Engine.dialect.URI().Schema + "." + tbName
}
}*/
return tbName
}

View File

@ -674,10 +674,10 @@ func (statement *Statement) TableName() string {
}
if statement.RefTable != nil {
schema := statement.Engine.dialect.URI().Schema
/*schema := statement.Engine.dialect.URI().Schema
if len(schema) > 0 {
return schema + "." + statement.RefTable.Name
}
}*/
return statement.RefTable.Name
}
return ""

View File

@ -17,7 +17,7 @@ import (
const (
// Version show the xorm's version
Version string = "0.5.3.0407"
Version string = "0.5.4.0422"
)
func regDrvsNDialects() bool {