blob: 71719c7e668a23d036479972a9d8c52e24044d4c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
package database
import (
"encoding/json"
"fmt"
"git.adyxax.org/adyxax/spacetraders/golang/pkg/model"
)
func (db *DB) AppendTransaction(transaction *model.Transaction) error {
data, err := json.Marshal(transaction)
if err != nil {
return fmt.Errorf("failed to marshal transaction: %w", err)
}
if _, err := db.Exec(`INSERT INTO transactions(data) VALUES (json(?));`, data); err != nil {
return fmt.Errorf("failed to append transaction: %w", err)
}
return nil
}
|