postgres

package
v5.0.0-rc.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package postgres implements the storage.Backend interface using GORM/PostgreSQL with internal queues and a background DB writer goroutine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	// contains filtered or unexported fields
}

Backend implements storage.Backend using GORM/PostgreSQL with queue-based batch writes.

func New

func New(deps Dependencies) *Backend

New creates a new GORM storage backend.

func (*Backend) AddMarker

func (b *Backend) AddMarker(m *core.Marker) (uint, error)

AddMarker inserts a marker synchronously (not queued) because markers are low-volume and need immediate ID assignment for the MarkerCache. Returns the DB-assigned ID (0 if no DB is configured).

func (*Backend) AddPlacedObject

func (b *Backend) AddPlacedObject(p *core.PlacedObject) error

AddPlacedObject converts a core placed object to GORM and pushes to the write queue.

func (*Backend) AddSoldier

func (b *Backend) AddSoldier(s *core.Soldier) error

AddSoldier converts a core soldier to GORM and pushes to the write queue.

func (*Backend) AddVehicle

func (b *Backend) AddVehicle(v *core.Vehicle) error

AddVehicle converts a core vehicle to GORM and pushes to the write queue.

func (*Backend) Close

func (b *Backend) Close() error

Close stops the DB writer goroutine.

func (*Backend) DeleteMarker

func (b *Backend) DeleteMarker(dm *core.DeleteMarker) error

DeleteMarker pushes an alpha=0 MarkerState to the queue and marks the marker as deleted in DB.

func (*Backend) DeleteSoldier

func (b *Backend) DeleteSoldier(id uint16, frame core.Frame) error

DeleteSoldier is a no-op — postgres tracks all states, export logic differs.

func (*Backend) DeleteVehicle

func (b *Backend) DeleteVehicle(id uint16, frame core.Frame) error

DeleteVehicle is a no-op — postgres tracks all states, export logic differs.

func (*Backend) EndMission

func (b *Backend) EndMission() error

EndMission is a no-op — mission lifecycle is managed by main.go.

func (*Backend) Init

func (b *Backend) Init() error

Init creates internal queues, runs schema migration, and starts the DB writer goroutine. If no DB was injected via Dependencies, it creates its own postgres connection.

func (*Backend) RecordAce3DeathEvent

func (b *Backend) RecordAce3DeathEvent(e *core.Ace3DeathEvent) error

RecordAce3DeathEvent converts and queues an ACE3 death event.

func (*Backend) RecordAce3UnconsciousEvent

func (b *Backend) RecordAce3UnconsciousEvent(e *core.Ace3UnconsciousEvent) error

RecordAce3UnconsciousEvent converts and queues an ACE3 unconscious event.

func (*Backend) RecordChatEvent

func (b *Backend) RecordChatEvent(e *core.ChatEvent) error

RecordChatEvent converts and queues a chat event.

func (*Backend) RecordEndMissionEvent

func (b *Backend) RecordEndMissionEvent(e *core.EndMissionEvent) error

RecordEndMissionEvent stores end mission events as general events in postgres.

func (*Backend) RecordFiredEvent

func (b *Backend) RecordFiredEvent(e *core.FiredEvent) error

RecordFiredEvent is a no-op — replaced by ProjectileEvent.

func (*Backend) RecordGeneralEvent

func (b *Backend) RecordGeneralEvent(e *core.GeneralEvent) error

RecordGeneralEvent converts and queues a general event.

func (*Backend) RecordHitEvent

func (b *Backend) RecordHitEvent(e *core.HitEvent) error

RecordHitEvent is a no-op — replaced by ProjectileEvent.

func (*Backend) RecordKillEvent

func (b *Backend) RecordKillEvent(e *core.KillEvent) error

RecordKillEvent converts and queues a kill event.

func (*Backend) RecordMarkerState

func (b *Backend) RecordMarkerState(s *core.MarkerState) error

RecordMarkerState converts and queues a marker state.

func (*Backend) RecordPlacedObjectEvent

func (b *Backend) RecordPlacedObjectEvent(e *core.PlacedObjectEvent) error

RecordPlacedObjectEvent converts and queues a placed object event.

func (*Backend) RecordProjectileEvent

func (b *Backend) RecordProjectileEvent(e *core.ProjectileEvent) error

RecordProjectileEvent converts and queues a projectile event.

func (*Backend) RecordRadioEvent

func (b *Backend) RecordRadioEvent(e *core.RadioEvent) error

RecordRadioEvent converts and queues a radio event.

func (*Backend) RecordSectorEvent

func (b *Backend) RecordSectorEvent(e *core.SectorEvent) error

RecordSectorEvent stores sector events as general events in postgres. The structured data is flattened to the general event format for DB compatibility.

func (*Backend) RecordSoldierState

func (b *Backend) RecordSoldierState(s *core.SoldierState) error

RecordSoldierState converts and queues a soldier state.

func (*Backend) RecordTelemetryEvent

func (b *Backend) RecordTelemetryEvent(e *core.TelemetryEvent) error

RecordTelemetryEvent extracts FPS data and queues it for DB storage. Full telemetry data is not stored in the database.

func (*Backend) RecordTimeState

func (b *Backend) RecordTimeState(t *core.TimeState) error

RecordTimeState is a no-op — TimeState is not in DatabaseModels, only used by memory backend.

func (*Backend) RecordVehicleState

func (b *Backend) RecordVehicleState(v *core.VehicleState) error

RecordVehicleState converts and queues a vehicle state.

func (*Backend) SetFocusEnd

func (b *Backend) SetFocusEnd(frame core.Frame) error

SetFocusEnd is a no-op — focus metadata is only used by memory backend export.

func (*Backend) SetFocusStart

func (b *Backend) SetFocusStart(frame core.Frame) error

SetFocusStart is a no-op — focus metadata is only used by memory backend export.

func (*Backend) SetMissionID

func (b *Backend) SetMissionID(id uint)

SetMissionID sets the current mission ID for the DB writer (used by CLI tools).

func (*Backend) StartMission

func (b *Backend) StartMission(coreMission *core.Mission, coreWorld *core.World) error

StartMission performs addon get-or-create, world get-or-insert, and mission create in the DB.

type Dependencies

type Dependencies struct {
	DB          *gorm.DB
	EntityCache *cache.EntityCache
	MarkerCache *cache.MarkerCache
	LogManager  *logging.SlogManager
}

Dependencies holds all dependencies for the GORM storage backend.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL