/
notification.go
38 lines (31 loc) · 1.07 KB
/
notification.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package sql
type NotificationSQL struct {
ID string
Notification string
CreatedAt string `db:"created_at"`
UpdatedAt string `db:"updated_at"`
}
func (db *sqlImpl) GetNotification(id string) (notification NotificationSQL, err error) {
err = db.db.Get(¬ification, "SELECT * FROM notifications WHERE id=$1", id)
return notification, err
}
func (db *sqlImpl) GetAllNotifications() (notifications []NotificationSQL, err error) {
err = db.db.Select(¬ifications, "SELECT * FROM notifications")
return notifications, err
}
func (db *sqlImpl) InsertNotification(notification NotificationSQL) (err error) {
_, err = db.db.NamedExec(
"INSERT INTO notifications (notification) VALUES (:notification)",
notification)
return err
}
func (db *sqlImpl) UpdateNotification(notification NotificationSQL) error {
_, err := db.db.NamedExec(
"UPDATE notifications SET notification=:notification WHERE id=:id",
notification)
return err
}
func (db *sqlImpl) DeleteNotification(ID string) error {
_, err := db.db.Exec("DELETE FROM notifications WHERE id=$1", ID)
return err
}