add oci8 support
This commit is contained in:
parent
076f7bbf08
commit
a9aba4b935
38
dialect.go
38
dialect.go
|
@ -56,13 +56,15 @@ type Dialect interface {
|
||||||
IsColumnExist(tableName string, col *Column) (bool, error)
|
IsColumnExist(tableName string, col *Column) (bool, error)
|
||||||
|
|
||||||
CreateTableSql(table *Table, tableName, storeEngine, charset string) string
|
CreateTableSql(table *Table, tableName, storeEngine, charset string) string
|
||||||
//DropTableSql(tableName string) string
|
DropTableSql(tableName string) string
|
||||||
CreateIndexSql(tableName string, index *Index) string
|
CreateIndexSql(tableName string, index *Index) string
|
||||||
DropIndexSql(tableName string, index *Index) string
|
DropIndexSql(tableName string, index *Index) string
|
||||||
|
|
||||||
ModifyColumnSql(tableName string, col *Column) string
|
ModifyColumnSql(tableName string, col *Column) string
|
||||||
|
|
||||||
|
//CreateTableIfNotExists(table *Table, tableName, storeEngine, charset string) error
|
||||||
MustDropTable(tableName string) error
|
MustDropTable(tableName string) error
|
||||||
|
|
||||||
GetColumns(tableName string) ([]string, map[string]*Column, error)
|
GetColumns(tableName string) ([]string, map[string]*Column, error)
|
||||||
GetTables() ([]*Table, error)
|
GetTables() ([]*Table, error)
|
||||||
GetIndexes(tableName string) (map[string]*Index, error)
|
GetIndexes(tableName string) (map[string]*Index, error)
|
||||||
|
@ -138,11 +140,15 @@ func (db *Base) RollBackStr() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Base) DropTableSql(tableName string) string {
|
func (db *Base) DropTableSql(tableName string) string {
|
||||||
return fmt.Sprintf("DROP TABLE IF EXISTS `%s`", tableName)
|
return fmt.Sprintf("DROP TABLE IF EXISTS `%s`;", tableName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Base) MustDropTable(tableName string) error {
|
func (db *Base) MustDropTable(tableName string) error {
|
||||||
_, err := db.db.Exec(db.DropTableSql(tableName))
|
query := db.DropTableSql(tableName)
|
||||||
|
_, err := db.db.Exec(query)
|
||||||
|
if db.Logger != nil {
|
||||||
|
db.Logger.Info("[sql]", query)
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,6 +174,30 @@ func (db *Base) IsColumnExist(tableName string, col *Column) (bool, error) {
|
||||||
return db.HasRecords(query, db.DbName, tableName, col.Name)
|
return db.HasRecords(query, db.DbName, tableName, col.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
func (db *Base) CreateTableIfNotExists(table *Table, tableName, storeEngine, charset string) error {
|
||||||
|
sql, args := db.dialect.TableCheckSql(tableName)
|
||||||
|
rows, err := db.DB().Query(sql, args...)
|
||||||
|
if db.Logger != nil {
|
||||||
|
db.Logger.Info("[sql]", sql, args)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
|
if rows.Next() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
sql = db.dialect.CreateTableSql(table, tableName, storeEngine, charset)
|
||||||
|
_, err = db.DB().Exec(sql)
|
||||||
|
if db.Logger != nil {
|
||||||
|
db.Logger.Info("[sql]", sql)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}*/
|
||||||
|
|
||||||
func (db *Base) CreateIndexSql(tableName string, index *Index) string {
|
func (db *Base) CreateIndexSql(tableName string, index *Index) string {
|
||||||
quote := db.dialect.Quote
|
quote := db.dialect.Quote
|
||||||
var unique string
|
var unique string
|
||||||
|
@ -176,7 +206,7 @@ func (db *Base) CreateIndexSql(tableName string, index *Index) string {
|
||||||
unique = " UNIQUE"
|
unique = " UNIQUE"
|
||||||
}
|
}
|
||||||
idxName = index.XName(tableName)
|
idxName = index.XName(tableName)
|
||||||
return fmt.Sprintf("CREATE%s INDEX %v ON %v (%v);", unique,
|
return fmt.Sprintf("CREATE%s INDEX %v ON %v (%v)", unique,
|
||||||
quote(idxName), quote(tableName),
|
quote(idxName), quote(tableName),
|
||||||
quote(strings.Join(index.Cols, quote(","))))
|
quote(strings.Join(index.Cols, quote(","))))
|
||||||
}
|
}
|
||||||
|
|
6
type.go
6
type.go
|
@ -70,6 +70,7 @@ var (
|
||||||
NVarchar = "NVARCHAR"
|
NVarchar = "NVARCHAR"
|
||||||
TinyText = "TINYTEXT"
|
TinyText = "TINYTEXT"
|
||||||
Text = "TEXT"
|
Text = "TEXT"
|
||||||
|
Clob = "CLOB"
|
||||||
MediumText = "MEDIUMTEXT"
|
MediumText = "MEDIUMTEXT"
|
||||||
LongText = "LONGTEXT"
|
LongText = "LONGTEXT"
|
||||||
Uuid = "UUID"
|
Uuid = "UUID"
|
||||||
|
@ -120,6 +121,7 @@ var (
|
||||||
MediumText: TEXT_TYPE,
|
MediumText: TEXT_TYPE,
|
||||||
LongText: TEXT_TYPE,
|
LongText: TEXT_TYPE,
|
||||||
Uuid: TEXT_TYPE,
|
Uuid: TEXT_TYPE,
|
||||||
|
Clob: TEXT_TYPE,
|
||||||
|
|
||||||
Date: TIME_TYPE,
|
Date: TIME_TYPE,
|
||||||
DateTime: TIME_TYPE,
|
DateTime: TIME_TYPE,
|
||||||
|
@ -250,7 +252,7 @@ func Type2SQLType(t reflect.Type) (st SQLType) {
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
st = SQLType{Varchar, 255, 0}
|
st = SQLType{Varchar, 255, 0}
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
if t == reflect.TypeOf(c_TIME_DEFAULT) {
|
if t.ConvertibleTo(reflect.TypeOf(c_TIME_DEFAULT)) {
|
||||||
st = SQLType{DateTime, 0, 0}
|
st = SQLType{DateTime, 0, 0}
|
||||||
} else {
|
} else {
|
||||||
// TODO need to handle association struct
|
// TODO need to handle association struct
|
||||||
|
@ -303,7 +305,7 @@ func SQLType2Type(st SQLType) reflect.Type {
|
||||||
return reflect.TypeOf(float32(1))
|
return reflect.TypeOf(float32(1))
|
||||||
case Double:
|
case Double:
|
||||||
return reflect.TypeOf(float64(1))
|
return reflect.TypeOf(float64(1))
|
||||||
case Char, Varchar, NVarchar, TinyText, Text, MediumText, LongText, Enum, Set, Uuid:
|
case Char, Varchar, NVarchar, TinyText, Text, MediumText, LongText, Enum, Set, Uuid, Clob:
|
||||||
return reflect.TypeOf("")
|
return reflect.TypeOf("")
|
||||||
case TinyBlob, Blob, LongBlob, Bytea, Binary, MediumBlob, VarBinary:
|
case TinyBlob, Blob, LongBlob, Bytea, Binary, MediumBlob, VarBinary:
|
||||||
return reflect.TypeOf([]byte{})
|
return reflect.TypeOf([]byte{})
|
||||||
|
|
Loading…
Reference in New Issue