[golang] implement ship refueling
This commit is contained in:
parent
23dd8f4a27
commit
01263017fc
8 changed files with 121 additions and 6 deletions
19
golang/pkg/database/transactions.go
Normal file
19
golang/pkg/database/transactions.go
Normal file
|
@ -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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue