mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 15:10:55 +00:00
support oracle
This commit is contained in:
parent
f45b271b96
commit
3a12e238cc
@ -59,6 +59,7 @@ var (
|
|||||||
"postgres": DRPostgres,
|
"postgres": DRPostgres,
|
||||||
"sqlite3": DRSqlite,
|
"sqlite3": DRSqlite,
|
||||||
"tidb": DRTiDB,
|
"tidb": DRTiDB,
|
||||||
|
"oracle": DROracle,
|
||||||
}
|
}
|
||||||
dbBasers = map[DriverType]dbBaser{
|
dbBasers = map[DriverType]dbBaser{
|
||||||
DRMySQL: newdbBaseMysql(),
|
DRMySQL: newdbBaseMysql(),
|
||||||
@ -151,7 +152,7 @@ func detectTZ(al *alias) {
|
|||||||
al.Engine = "INNODB"
|
al.Engine = "INNODB"
|
||||||
}
|
}
|
||||||
|
|
||||||
case DRSqlite:
|
case DRSqlite, DROracle:
|
||||||
al.TZ = time.UTC
|
al.TZ = time.UTC
|
||||||
|
|
||||||
case DRPostgres:
|
case DRPostgres:
|
||||||
|
@ -14,6 +14,41 @@
|
|||||||
|
|
||||||
package orm
|
package orm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// oracle operators.
|
||||||
|
var oracleOperators = map[string]string{
|
||||||
|
"exact": "= ?",
|
||||||
|
"gt": "> ?",
|
||||||
|
"gte": ">= ?",
|
||||||
|
"lt": "< ?",
|
||||||
|
"lte": "<= ?",
|
||||||
|
"//iendswith": "LIKE ?",
|
||||||
|
}
|
||||||
|
|
||||||
|
// oracle column field types.
|
||||||
|
var oracleTypes = map[string]string{
|
||||||
|
"pk": "NOT NULL PRIMARY KEY",
|
||||||
|
"bool": "bool",
|
||||||
|
"string": "VARCHAR2(%d)",
|
||||||
|
"string-text": "VARCHAR2(%d)",
|
||||||
|
"time.Time-date": "DATE",
|
||||||
|
"time.Time": "TIMESTAMP",
|
||||||
|
"int8": "INTEGER",
|
||||||
|
"int16": "INTEGER",
|
||||||
|
"int32": "INTEGER",
|
||||||
|
"int64": "INTEGER",
|
||||||
|
"uint8": "INTEGER",
|
||||||
|
"uint16": "INTEGER",
|
||||||
|
"uint32": "INTEGER",
|
||||||
|
"uint64": "INTEGER",
|
||||||
|
"float64": "NUMBER",
|
||||||
|
"float64-decimal": "NUMBER(%d, %d)",
|
||||||
|
}
|
||||||
|
|
||||||
// oracle dbBaser
|
// oracle dbBaser
|
||||||
type dbBaseOracle struct {
|
type dbBaseOracle struct {
|
||||||
dbBase
|
dbBase
|
||||||
@ -27,3 +62,35 @@ func newdbBaseOracle() dbBaser {
|
|||||||
b.ins = b
|
b.ins = b
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OperatorSQL get oracle operator.
|
||||||
|
func (d *dbBaseOracle) OperatorSQL(operator string) string {
|
||||||
|
return oracleOperators[operator]
|
||||||
|
}
|
||||||
|
|
||||||
|
// DbTypes get oracle table field types.
|
||||||
|
func (d *dbBaseOracle) DbTypes() map[string]string {
|
||||||
|
return oracleTypes
|
||||||
|
}
|
||||||
|
|
||||||
|
//ShowTablesQuery show all the tables in database
|
||||||
|
func (d *dbBaseOracle) ShowTablesQuery() string {
|
||||||
|
return "SELECT TABLE_NAME FROM USER_TABLES"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Oracle
|
||||||
|
func (d *dbBaseOracle) ShowColumnsQuery(table string) string {
|
||||||
|
return fmt.Sprintf("SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS "+
|
||||||
|
"WHERE TABLE_NAME ='%s'", strings.ToUpper(table))
|
||||||
|
}
|
||||||
|
|
||||||
|
// check index is exist
|
||||||
|
func (d *dbBaseOracle) IndexExists(db dbQuerier, table string, name string) bool {
|
||||||
|
row := db.QueryRow("SELECT COUNT(*) FROM USER_IND_COLUMNS, USER_INDEXES "+
|
||||||
|
"WHERE USER_IND_COLUMNS.INDEX_NAME = USER_INDEXES.INDEX_NAME "+
|
||||||
|
"AND USER_IND_COLUMNS.TABLE_NAME = ? AND USER_IND_COLUMNS.INDEX_NAME = ?", strings.ToUpper(table), strings.ToUpper(name))
|
||||||
|
|
||||||
|
var cnt int
|
||||||
|
row.Scan(&cnt)
|
||||||
|
return cnt > 0
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user