diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2025-01-05 16:39:13 -0800 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2025-01-05 16:39:13 -0800 |
commit | d25ec27fb1c3df175e1b98af1fdc26881d68a1ab (patch) | |
tree | a79c729b92c0d0a52b19b37c3a506b988f1e0b80 /database/updates.go | |
download | whois-d25ec27fb1c3df175e1b98af1fdc26881d68a1ab.tar.gz whois-d25ec27fb1c3df175e1b98af1fdc26881d68a1ab.zip |
initial commit by simponic-infra
Diffstat (limited to 'database/updates.go')
-rw-r--r-- | database/updates.go | 44 |
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 +} |