示例#1
0
func DeleteItems(db *gorm.DB, data custom_structs.ItemsForDeleting) error {
	item := models.DBTypesMap()[data.Category]
	err := db.Where("id in (?)", data.Ids).Delete(item).Error
	if err != nil {
		return err
	}
	return nil
}
示例#2
0
func UpdateItem(db *gorm.DB, data custom_structs.ItemsData) error {
	var err error
	item := models.DBTypesMap()[data.Category]

	err = item.Decode(data.Data)
	if err == nil {
		err = db.Model(item).Updates(item).Error
		if err != nil {
			return err
		}
	}
	if err != nil {
		return err
	}
	return nil
}
示例#3
0
func AddItem(db *gorm.DB, category string) (error, interface{}) {
	item := models.DBTypesMap()[category]
	db.NewRecord(item)
	db.Create(item)
	return nil, item
}