| | |
| | | return "caches" |
| | | } |
| | | |
| | | func (c *Cache) First() error { |
| | | return db.Table(c.TableName()).First(c).Error |
| | | } |
| | | |
| | | func (c *Cache) FindAll() ([]Cache, error) { |
| | | var caches []Cache |
| | | if err := db.Table(c.TableName()).Find(&caches).Error; err != nil { |
| | |
| | | } |
| | | |
| | | return caches, nil |
| | | } |
| | | |
| | | func (c *Cache) Count() (int64, error) { |
| | | var total int64 |
| | | if err := db.Table(c.TableName()).Count(&total).Error; err != nil { |
| | | return total, err |
| | | } |
| | | |
| | | return total, nil |
| | | } |
| | | |
| | | func (c *Cache) Save() error { |
| | |
| | | func (c *Cache) Delete() error { |
| | | return db.Table(c.TableName()).Where("id = ?", c.Id).Delete(c).Error |
| | | } |
| | | |
| | | func (c *Cache) Clean() error { |
| | | sql := "DELETE FROM caches WHERE id NOT IN (SELECT id FROM caches ORDER BY id DESC LIMIT 15000);" |
| | | return db.Table(c.TableName()).Exec(sql).Error |
| | | } |