|
@@ -3,7 +3,7 @@ package db
|
|
|
import "fmt"
|
|
|
|
|
|
func (db DB) Insert(obj interface{}) error {
|
|
|
- tx := db.orm.Begin()
|
|
|
+ tx := db.Orm.Begin()
|
|
|
|
|
|
err := tx.Create(obj).Error
|
|
|
if err != nil {
|
|
@@ -19,7 +19,7 @@ func (db DB) Insert(obj interface{}) error {
|
|
|
return nil
|
|
|
}
|
|
|
func (db DB) Get(objs interface{}, where map[string]interface{}, order string, limit uint64, offset uint64, deleted bool) error {
|
|
|
- con := db.orm
|
|
|
+ con := db.Orm
|
|
|
if deleted {
|
|
|
con = con.Unscoped()
|
|
|
}
|
|
@@ -48,14 +48,14 @@ func (db DB) Get(objs interface{}, where map[string]interface{}, order string, l
|
|
|
|
|
|
// get by id
|
|
|
func (db DB) GetById(obj interface{}, id uint64) error {
|
|
|
- err := db.orm.First(obj, id).Error
|
|
|
+ err := db.Orm.First(obj, id).Error
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
func (db DB) Update(obj interface{}, para map[string]interface{}) error {
|
|
|
- tx := db.orm.Begin()
|
|
|
+ tx := db.Orm.Begin()
|
|
|
|
|
|
err := tx.Model(obj).Updates(para).Error
|
|
|
if err != nil {
|
|
@@ -71,7 +71,7 @@ func (db DB) Update(obj interface{}, para map[string]interface{}) error {
|
|
|
return nil
|
|
|
}
|
|
|
func (db DB) Delete(obj interface{}, para map[string]interface{}) error {
|
|
|
- tx := db.orm.Begin()
|
|
|
+ tx := db.Orm.Begin()
|
|
|
|
|
|
err := tx.Where(para).Delete(obj).Error
|
|
|
if err != nil {
|
|
@@ -90,14 +90,14 @@ func (db DB) Delete(obj interface{}, para map[string]interface{}) error {
|
|
|
// get tables
|
|
|
func (db DB) GetTables() ([]interface{}, error) {
|
|
|
var tables []interface{}
|
|
|
- if db.driver == SQLITE_DRIVER {
|
|
|
+ if db.Driver == SQLITE_DRIVER {
|
|
|
ts, err := db.sqliteTables()
|
|
|
if err != nil {
|
|
|
return ts, err
|
|
|
}
|
|
|
tables = ts
|
|
|
}
|
|
|
- if db.driver == POSTGRES_DRIVER {
|
|
|
+ if db.Driver == POSTGRES_DRIVER {
|
|
|
tp, err := db.Select("select table_name from information_schema.tables", Filter{Field: "table_type", Compare: "=", Value: "BASE TABLE"})
|
|
|
if err != nil {
|
|
|
return tp, err
|
|
@@ -108,14 +108,14 @@ func (db DB) GetTables() ([]interface{}, error) {
|
|
|
}
|
|
|
func (db DB) GetMeta(tableName interface{}) (interface{}, error) {
|
|
|
var meta interface{}
|
|
|
- if db.driver == SQLITE_DRIVER {
|
|
|
+ if db.Driver == SQLITE_DRIVER {
|
|
|
tm, err := db.sqliteMeta(tableName)
|
|
|
if err != nil {
|
|
|
return meta, err
|
|
|
}
|
|
|
meta = tm
|
|
|
}
|
|
|
- if db.driver == POSTGRES_DRIVER {
|
|
|
+ if db.Driver == POSTGRES_DRIVER {
|
|
|
pm, err := db.postgresMeta(fmt.Sprint(tableName))
|
|
|
if err != nil {
|
|
|
return pm, err
|
|
@@ -138,7 +138,7 @@ func (db DB) sqliteMeta(tableName interface{}) ([]TableInfo, error) {
|
|
|
var info []TableInfo
|
|
|
str := fmt.Sprint(tableName)
|
|
|
q := "pragma table_info(" + str + ")"
|
|
|
- row, err := db.orm.DB().Query(q)
|
|
|
+ row, err := db.Orm.DB().Query(q)
|
|
|
if err != nil {
|
|
|
return info, err
|
|
|
}
|
|
@@ -167,7 +167,7 @@ func (db DB) sqliteMeta(tableName interface{}) ([]TableInfo, error) {
|
|
|
}
|
|
|
func (db DB) Select(para string, filter Filter) ([]interface{}, error) {
|
|
|
var tables []interface{}
|
|
|
- row, err := db.orm.Select(para).Where(filter.Field+" "+filter.Compare+" ?", filter.Value).Rows()
|
|
|
+ row, err := db.Orm.Select(para).Where(filter.Field+" "+filter.Compare+" ?", filter.Value).Rows()
|
|
|
if err != nil {
|
|
|
return tables, err
|
|
|
}
|