midr @ db7e822dda56d32135eca6d3e3211a50cf93d31a

 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	OutputFolder string
13}
14
15type EntryModel struct {
16	DB *gorm.DB
17}
18
19func (m EntryModel) Find(id string) Entry {
20	var entry Entry
21	where := "id = " + id
22	m.DB.Where(where).FirstOrInit(&entry)
23	return entry
24}
25
26func (m EntryModel) All() []Entry {
27	var entries []Entry
28	m.DB.Find(&entries)
29	return entries
30}
31
32func (m EntryModel) Create(entry Entry) {
33	m.DB.Create(&entry)
34}
35
36func (m EntryModel) Update(entry Entry) {
37	m.DB.Save(&entry)
38}
39
40func (m EntryModel) Delete(id string) {
41	m.DB.Delete(&Entry{}, id)
42}