midr @ dc81e33f760b45778f2646d6f1a7c9e8166b2fe5

 1package db
 2
 3import (
 4	"gorm.io/gorm"
 5)
 6
 7type Entry struct {
 8	gorm.Model
 9	Title        string
10	Link         string
11	Format       string
12	DateAfter    string
13	OutputFolder string
14}
15
16type EntryModel struct {
17	DB *gorm.DB
18}
19
20func (m *EntryModel) Find(id string) Entry {
21	var entry Entry
22	where := "id = " + id
23	m.DB.Where(where).FirstOrInit(&entry)
24	return entry
25}
26
27func (m *EntryModel) All() []Entry {
28	var entries []Entry
29	m.DB.Find(&entries)
30	return entries
31}
32
33func (m *EntryModel) Create(entry *Entry) {
34	m.DB.Create(entry)
35}
36
37func (m *EntryModel) Update(entry Entry) {
38	m.DB.Save(&entry)
39}
40
41func (m *EntryModel) Delete(id string) {
42	m.DB.Delete(&Entry{}, id)
43}