From 3dad3f60f280289dee1b34ae04744f244d070bf7 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 13 Feb 2025 21:35:32 +0100 Subject: [golang] Bootstrap contracting and refactor the agent code --- golang/pkg/database/agents.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 golang/pkg/database/agents.go (limited to 'golang/pkg/database/agents.go') diff --git a/golang/pkg/database/agents.go b/golang/pkg/database/agents.go new file mode 100644 index 0000000..cd9e0a2 --- /dev/null +++ b/golang/pkg/database/agents.go @@ -0,0 +1,19 @@ +package database + +import ( + "encoding/json" + "fmt" + + "git.adyxax.org/adyxax/spacetraders/golang/pkg/model" +) + +func (db *DB) SaveAgent(agent *model.Agent) error { + data, err := json.Marshal(agent) + if err != nil { + return fmt.Errorf("failed to marshal agent: %w", err) + } + if _, err := db.Exec(`INSERT INTO agents SET data = (json(?));`, data); err != nil { + return fmt.Errorf("failed to insert agent data: %w", err) + } + return nil +} -- cgit v1.2.3