summaryrefslogtreecommitdiff
path: root/database/updates.go
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2025-01-05 16:39:13 -0800
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2025-01-05 16:39:13 -0800
commitd25ec27fb1c3df175e1b98af1fdc26881d68a1ab (patch)
treea79c729b92c0d0a52b19b37c3a506b988f1e0b80 /database/updates.go
downloadwhois-d25ec27fb1c3df175e1b98af1fdc26881d68a1ab.tar.gz
whois-d25ec27fb1c3df175e1b98af1fdc26881d68a1ab.zip
initial commit by simponic-infra
Diffstat (limited to 'database/updates.go')
-rw-r--r--database/updates.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/database/updates.go b/database/updates.go
new file mode 100644
index 0000000..3021334
--- /dev/null
+++ b/database/updates.go
@@ -0,0 +1,44 @@
+package database
+
+import (
+ "database/sql"
+ "time"
+)
+
+type Update struct {
+ Name string
+ Time time.Time
+}
+
+type ListUpdatesQuery struct {
+ Limit int
+}
+
+func ListUpdates(dbConn *sql.DB, query ListUpdatesQuery) ([]Update, error) {
+ rows, err := dbConn.Query(`SELECT name, time FROM updates ORDER BY time DESC LIMIT ?;`, query.Limit)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+
+ updates := []Update{}
+ for rows.Next() {
+ var update Update
+ err := rows.Scan(&update.Name, &update.Time)
+ if err != nil {
+ return nil, err
+ }
+ updates = append(updates, update)
+ }
+
+ return updates, nil
+}
+
+func SaveUpdate(db *sql.DB, update *Update) (*Update, error) {
+ _, err := db.Exec("INSERT INTO updates (time, name) VALUES (?, ?)", update.Time, update.Name)
+
+ if err != nil {
+ return nil, err
+ }
+ return update, nil
+}