Write on the margins of the internet. Powered by the AT Protocol.
margin.at
extension
web
atproto
comments
1package db
2
3import (
4 "time"
5)
6
7func (db *DB) SaveEditHistory(uri, recordType, previousContent string, previousCID *string) error {
8 _, err := db.Exec(db.Rebind(`
9 INSERT INTO edit_history (uri, record_type, previous_content, previous_cid, edited_at)
10 VALUES (?, ?, ?, ?, ?)
11 `), uri, recordType, previousContent, previousCID, time.Now())
12 return err
13}
14
15func (db *DB) GetEditHistory(uri string) ([]EditHistory, error) {
16 rows, err := db.Query(db.Rebind(`
17 SELECT id, uri, record_type, previous_content, previous_cid, edited_at
18 FROM edit_history
19 WHERE uri = ?
20 ORDER BY edited_at DESC
21 `), uri)
22 if err != nil {
23 return nil, err
24 }
25 defer rows.Close()
26
27 var history []EditHistory
28 for rows.Next() {
29 var h EditHistory
30 if err := rows.Scan(&h.ID, &h.URI, &h.RecordType, &h.PreviousContent, &h.PreviousCID, &h.EditedAt); err != nil {
31 return nil, err
32 }
33 history = append(history, h)
34 }
35 return history, nil
36}