diff options
| author | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-06-20 09:40:07 -0700 |
|---|---|---|
| committer | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-06-20 09:40:07 -0700 |
| commit | fb653292612eddca5b088ed88466c546d1597107 (patch) | |
| tree | 900ed32e066812688858ed3bb15128c41bb78054 /database/minecraft.go | |
| download | penguins.lan-fb653292612eddca5b088ed88466c546d1597107.tar.gz penguins.lan-fb653292612eddca5b088ed88466c546d1597107.zip | |
Initial commit
Diffstat (limited to 'database/minecraft.go')
| -rw-r--r-- | database/minecraft.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/database/minecraft.go b/database/minecraft.go new file mode 100644 index 0000000..d12b4b8 --- /dev/null +++ b/database/minecraft.go @@ -0,0 +1,28 @@ +package database + +import ( + "database/sql" + "errors" + "time" + + _ "github.com/mattn/go-sqlite3" +) + +func SaveMinecraftStatus(db *sql.DB, status string) error { + _, err := db.Exec(`INSERT INTO minecraft_status (id, status, updated_at) VALUES (1, ?, ?) + ON CONFLICT(id) DO UPDATE SET status = excluded.status, updated_at = excluded.updated_at`, + status, time.Now()) + return err +} + +// GetMinecraftStatus returns the cached status JSON and when it was written. An +// empty string (with no error) means nothing has been cached yet. +func GetMinecraftStatus(db *sql.DB) (string, time.Time, error) { + var status string + var updatedAt time.Time + err := db.QueryRow("SELECT status, updated_at FROM minecraft_status WHERE id = 1").Scan(&status, &updatedAt) + if errors.Is(err, sql.ErrNoRows) { + return "", time.Time{}, nil + } + return status, updatedAt, err +} |
