// SaveOrUpdate func (s Xorm) SaveOrUpdate(model interface{}) (int64, error) { // id == ""; insert with new uuid. id := mmodel.GetModelId(model) if id == "" { logger.Trace("uuid save") return s.UuidSave(model) } // id!=null && id in db, update tableName := mmodel.GetModelTableName(model) q := fmt.Sprintf("select Id from %s where Id = ? ", tableName) row, _ := s.Engine.Query(q, id) if len(row) > 0 { logger.Trace("update") n, err := s.Engine.Id(id).Update(model) logger.CheckError(err) return n, err } // id != null && id not in db, insert with provide id logger.Trace("normal insert.") n, err := s.Engine.Insert(model) logger.CheckError(err) return n, err }
func DemoTableName() { m := Model{} fmt.Printf("%s\n", mmodel.GetModelTableName(m)) m2 := &Model{} fmt.Printf("%s\n", mmodel.GetModelTableName(m2)) }
// TableName func TableName(model interface{}) string { return mmodel.GetModelTableName(model) }
// GetModelFieldLabel // returns model locale filed name message. Parameters: // locale // model can be a slice? no. do as name. // field // Field name save as column name. // table name should be follow some rules. func GetModelFieldLabel(locale string, model interface{}, field string) string { //table := mcore.GetTypeName(model) table := mmodel.GetModelTableName(model) column := field return GetTableColumnLabel(locale, table, column) }