bun

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package bun provides a Bun ORM implementation of the store.Store interface.

Bun is a SQL-first Golang ORM for PostgreSQL, MySQL, MSSQL, and SQLite. This implementation supports PostgreSQL with TimescaleDB for time-series data and SQLite for lightweight deployments. The store uses proper relational schema with tables, indexes, and foreign keys, and includes a migration system for schema management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Driver specifies the database driver (postgres or sqlite).
	Driver Driver `default:"postgres" env:"CP_BUN_DRIVER" json:"driver"`

	// DSN is the database connection string.
	DSN string `env:"CP_BUN_DSN" json:"dsn"`

	// MaxOpenConns is the maximum number of open connections.
	MaxOpenConns int `default:"25" env:"CP_BUN_MAX_OPEN_CONNS" json:"max_open_conns"`

	// MaxIdleConns is the maximum number of idle connections.
	MaxIdleConns int `default:"5" env:"CP_BUN_MAX_IDLE_CONNS" json:"max_idle_conns"`

	// ConnMaxLifetime is the maximum lifetime of a connection.
	ConnMaxLifetime time.Duration `default:"5m" env:"CP_BUN_CONN_MAX_LIFETIME" json:"conn_max_lifetime"`

	// ConnMaxIdleTime is the maximum idle time of a connection.
	ConnMaxIdleTime time.Duration `default:"1m" env:"CP_BUN_CONN_MAX_IDLE_TIME" json:"conn_max_idle_time"`
}

Config holds the configuration for the Bun store.

type Driver

type Driver string

Driver represents the database driver type.

const (
	// DriverPostgreSQL uses PostgreSQL driver.
	DriverPostgreSQL Driver = "postgres"

	// DriverSQLite uses SQLite driver.
	DriverSQLite Driver = "sqlite"
)

type Store

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

Store is the Bun SQL implementation of store.Store.

func New

func New(cfg Config) (*Store, error)

New creates a new Bun store.

func (*Store) Close

func (s *Store) Close() error

Close closes the database connection.

func (*Store) CountByTenant

func (s *Store) CountByTenant(ctx context.Context, tenantID string) (int, error)

func (*Store) CountDomainsByTenant

func (s *Store) CountDomainsByTenant(ctx context.Context, tenantID string) (int, error)

func (*Store) CountSecretsByTenant

func (s *Store) CountSecretsByTenant(ctx context.Context, tenantID string) (int, error)

func (*Store) CountTenants

func (s *Store) CountTenants(ctx context.Context) (int, error)

func (*Store) CountTenantsByStatus

func (s *Store) CountTenantsByStatus(ctx context.Context, status admin.TenantStatus) (int, error)

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, tenantID string, instanceID id.ID) error

func (*Store) DeleteCertificate

func (s *Store) DeleteCertificate(ctx context.Context, tenantID string, certID id.ID) error

func (*Store) DeleteCheck

func (s *Store) DeleteCheck(ctx context.Context, tenantID string, checkID id.ID) error

func (*Store) DeleteDomain

func (s *Store) DeleteDomain(ctx context.Context, tenantID string, domainID id.ID) error

func (*Store) DeleteRoute

func (s *Store) DeleteRoute(ctx context.Context, tenantID string, routeID id.ID) error

func (*Store) DeleteSecret

func (s *Store) DeleteSecret(ctx context.Context, tenantID string, instanceID id.ID, key string) error

func (*Store) DeleteTenant

func (s *Store) DeleteTenant(ctx context.Context, tenantID string) error

func (*Store) GetByID

func (s *Store) GetByID(ctx context.Context, tenantID string, instanceID id.ID) (*instance.Instance, error)

func (*Store) GetBySlug

func (s *Store) GetBySlug(ctx context.Context, tenantID string, slug string) (*instance.Instance, error)

func (*Store) GetCertificate

func (s *Store) GetCertificate(ctx context.Context, tenantID string, certID id.ID) (*network.Certificate, error)

func (*Store) GetCheck

func (s *Store) GetCheck(ctx context.Context, tenantID string, checkID id.ID) (*health.HealthCheck, error)

func (*Store) GetDeployment

func (s *Store) GetDeployment(ctx context.Context, tenantID string, deployID id.ID) (*deploy.Deployment, error)

func (*Store) GetDomain

func (s *Store) GetDomain(ctx context.Context, tenantID string, domainID id.ID) (*network.Domain, error)

func (*Store) GetDomainByHostname

func (s *Store) GetDomainByHostname(ctx context.Context, hostname string) (*network.Domain, error)

func (*Store) GetLatestResourceSnapshot

func (s *Store) GetLatestResourceSnapshot(ctx context.Context, tenantID string, instanceID id.ID) (*telemetry.ResourceSnapshot, error)

func (*Store) GetLatestResult

func (s *Store) GetLatestResult(ctx context.Context, tenantID string, checkID id.ID) (*health.HealthResult, error)

func (*Store) GetRelease

func (s *Store) GetRelease(ctx context.Context, tenantID string, releaseID id.ID) (*deploy.Release, error)

func (*Store) GetRoute

func (s *Store) GetRoute(ctx context.Context, tenantID string, routeID id.ID) (*network.Route, error)

func (*Store) GetSecretByKey

func (s *Store) GetSecretByKey(ctx context.Context, tenantID string, instanceID id.ID, key string) (*secrets.Secret, error)

func (*Store) GetTenant

func (s *Store) GetTenant(ctx context.Context, tenantID string) (*admin.Tenant, error)

func (*Store) GetTenantBySlug

func (s *Store) GetTenantBySlug(ctx context.Context, slug string) (*admin.Tenant, error)

func (*Store) Insert

func (s *Store) Insert(ctx context.Context, inst *instance.Instance) error

func (*Store) InsertAuditEntry

func (s *Store) InsertAuditEntry(ctx context.Context, entry *admin.AuditEntry) error

func (*Store) InsertCertificate

func (s *Store) InsertCertificate(ctx context.Context, cert *network.Certificate) error

func (*Store) InsertCheck

func (s *Store) InsertCheck(ctx context.Context, check *health.HealthCheck) error

func (*Store) InsertDeployment

func (s *Store) InsertDeployment(ctx context.Context, d *deploy.Deployment) error

func (*Store) InsertDomain

func (s *Store) InsertDomain(ctx context.Context, domain *network.Domain) error

func (*Store) InsertLogs

func (s *Store) InsertLogs(ctx context.Context, logs []telemetry.LogEntry) error

func (*Store) InsertMetrics

func (s *Store) InsertMetrics(ctx context.Context, metrics []telemetry.Metric) error

func (*Store) InsertRelease

func (s *Store) InsertRelease(ctx context.Context, r *deploy.Release) error

func (*Store) InsertResourceSnapshot

func (s *Store) InsertResourceSnapshot(ctx context.Context, snap *telemetry.ResourceSnapshot) error

func (*Store) InsertResult

func (s *Store) InsertResult(ctx context.Context, result *health.HealthResult) error

func (*Store) InsertRoute

func (s *Store) InsertRoute(ctx context.Context, route *network.Route) error

func (*Store) InsertSecret

func (s *Store) InsertSecret(ctx context.Context, secret *secrets.Secret) error

func (*Store) InsertTenant

func (s *Store) InsertTenant(ctx context.Context, tenant *admin.Tenant) error

func (*Store) InsertTraces

func (s *Store) InsertTraces(ctx context.Context, traces []telemetry.Trace) error

func (*Store) List

func (s *Store) List(ctx context.Context, tenantID string, opts instance.ListOptions) (*instance.ListResult, error)

func (*Store) ListCertificates

func (s *Store) ListCertificates(ctx context.Context, tenantID string, instanceID id.ID) ([]network.Certificate, error)

func (*Store) ListCertificatesByDomain

func (s *Store) ListCertificatesByDomain(ctx context.Context, tenantID string, domainID id.ID) ([]network.Certificate, error)

func (*Store) ListChecks

func (s *Store) ListChecks(ctx context.Context, tenantID string, instanceID id.ID) ([]health.HealthCheck, error)

func (*Store) ListDeployments

func (s *Store) ListDeployments(ctx context.Context, tenantID string, instanceID id.ID, opts deploy.ListOptions) (*deploy.DeployListResult, error)

func (*Store) ListDomains

func (s *Store) ListDomains(ctx context.Context, tenantID string, instanceID id.ID) ([]network.Domain, error)

func (*Store) ListReleases

func (s *Store) ListReleases(ctx context.Context, tenantID string, instanceID id.ID, opts deploy.ListOptions) (*deploy.ReleaseListResult, error)

func (*Store) ListResourceSnapshots

func (s *Store) ListResourceSnapshots(ctx context.Context, tenantID string, instanceID id.ID, opts telemetry.TimeRange) ([]telemetry.ResourceSnapshot, error)

func (*Store) ListResults

func (s *Store) ListResults(ctx context.Context, tenantID string, checkID id.ID, opts health.HistoryOptions) ([]health.HealthResult, error)

func (*Store) ListRoutes

func (s *Store) ListRoutes(ctx context.Context, tenantID string, instanceID id.ID) ([]network.Route, error)

func (*Store) ListSecrets

func (s *Store) ListSecrets(ctx context.Context, tenantID string, instanceID id.ID) ([]secrets.Secret, error)

func (*Store) ListTenants

func (s *Store) ListTenants(ctx context.Context, opts admin.ListTenantsOptions) (*admin.TenantListResult, error)

func (*Store) Migrate

func (s *Store) Migrate(ctx context.Context) error

Migrate runs all schema migrations.

func (*Store) NextReleaseVersion

func (s *Store) NextReleaseVersion(ctx context.Context, tenantID string, instanceID id.ID) (int, error)

func (*Store) Ping

func (s *Store) Ping(ctx context.Context) error

Ping checks database connectivity.

func (*Store) QueryAuditLog

func (s *Store) QueryAuditLog(ctx context.Context, opts admin.AuditQuery) (*admin.AuditResult, error)

func (*Store) QueryLogs

func (s *Store) QueryLogs(ctx context.Context, q telemetry.LogQuery) ([]telemetry.LogEntry, error)

func (*Store) QueryMetrics

func (s *Store) QueryMetrics(ctx context.Context, q telemetry.MetricQuery) ([]telemetry.Metric, error)

func (*Store) QueryTraces

func (s *Store) QueryTraces(ctx context.Context, q telemetry.TraceQuery) ([]telemetry.Trace, error)

func (*Store) Update

func (s *Store) Update(ctx context.Context, inst *instance.Instance) error

func (*Store) UpdateCertificate

func (s *Store) UpdateCertificate(ctx context.Context, cert *network.Certificate) error

func (*Store) UpdateCheck

func (s *Store) UpdateCheck(ctx context.Context, check *health.HealthCheck) error

func (*Store) UpdateDeployment

func (s *Store) UpdateDeployment(ctx context.Context, d *deploy.Deployment) error

func (*Store) UpdateDomain

func (s *Store) UpdateDomain(ctx context.Context, domain *network.Domain) error

func (*Store) UpdateRoute

func (s *Store) UpdateRoute(ctx context.Context, route *network.Route) error

func (*Store) UpdateSecret

func (s *Store) UpdateSecret(ctx context.Context, secret *secrets.Secret) error

func (*Store) UpdateTenant

func (s *Store) UpdateTenant(ctx context.Context, tenant *admin.Tenant) error

Jump to

Keyboard shortcuts

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