From 01263017fcd03fa9560ddb8a5013fdf786c7d609 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Wed, 12 Feb 2025 23:55:18 +0100 Subject: [golang] implement ship refueling --- golang/pkg/database/transactions.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 golang/pkg/database/transactions.go (limited to 'golang/pkg/database/transactions.go') diff --git a/golang/pkg/database/transactions.go b/golang/pkg/database/transactions.go new file mode 100644 index 0000000..71719c7 --- /dev/null +++ b/golang/pkg/database/transactions.go @@ -0,0 +1,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 +} -- cgit v1.2.3