database

package
v1.6.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeriveScopedCredentials added in v1.6.0

func DeriveScopedCredentials(base *models.DriverCredentials, projectID, scopeKey string) *models.DriverCredentials

DeriveScopedCredentials copies base project credentials and points at the scope-specific database. Base credentials must be registered under projectID (not the composite key).

func SanitizeScopeDBSegment added in v1.6.0

func SanitizeScopeDBSegment(s string) string

SanitizeScopeDBSegment returns a safe fragment for database / file names.

func ScopedConnectionCacheKey added in v1.6.0

func ScopedConnectionCacheKey(projectID, scopeKey string) string

ScopedConnectionCacheKey builds the cache key for a per-scope project DB connection.

Types

type Closeable added in v1.4.0

type Closeable interface {
	Close() error
}

Closeable is an interface for connections that can be closed

type Connection

type Connection struct {
	ScopeKey     string
	DBConn       interfaces.ProjectDBInterface
	LastAccessed time.Time
	IsActive     bool
}

Connection represents a database connection with metadata

type ConnectionConfig

type ConnectionConfig struct {
	ScopeKey    string
	Driver      string
	ConnString  string
	MaxIdleConn int
	MaxOpenConn int
	MaxLifetime time.Duration
}

ConnectionConfig holds the database connection configuration for a scoped connection

type ConnectionHealthStatus added in v1.4.0

type ConnectionHealthStatus struct {
	HealthLevel       HealthLevel
	ActiveConnections int
	MaxConnections    int
	CacheItems        int
	UsagePercent      float64
	CacheHits         int64
	CacheMisses       int64
	Evictions         int64
	CloseErrors       int64
	LastCheck         time.Time
	Message           string
}

ConnectionHealthStatus represents the health status of the connection pool

type ConnectionManager

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

ConnectionManager manages database connections for multiple scopes

func NewConnectionManager

func NewConnectionManager(cfg *models.Config, maxConns int, systemDB interfaces.ApitoSystemDB) *ConnectionManager

NewConnectionManager creates a new connection manager

func (*ConnectionManager) AddDriverCredentials

func (cm *ConnectionManager) AddDriverCredentials(ctx context.Context, config *models.DriverCredentials)

AddDriverCredentials adds a new connection configuration for a project

func (*ConnectionManager) AddProDriverExtras added in v1.6.0

func (cm *ConnectionManager) AddProDriverExtras(projectID string, pro interface{})

AddProDriverExtras registers pro-only driver metadata for a project (or scope composite key). Nil removes the entry.

func (*ConnectionManager) AddScopedDriverCredentials added in v1.6.0

func (cm *ConnectionManager) AddScopedDriverCredentials(projectID, scopeKey string, config *models.DriverCredentials)

AddScopedDriverCredentials registers explicit credentials for a composite project:scope cache key (e.g. after a hosted driver API returns a dedicated URL). Normally DeriveScopedCredentials + EnsureScopedCredentials is enough.

func (*ConnectionManager) CloseAll added in v1.4.0

func (cm *ConnectionManager) CloseAll()

CloseAll closes all active connections - call this on graceful shutdown

func (*ConnectionManager) EnsureScopedCredentials added in v1.6.0

func (cm *ConnectionManager) EnsureScopedCredentials(projectID, scopeKey string) error

EnsureScopedCredentials registers derived per-scope credentials from the base project config if missing.

func (*ConnectionManager) GetConfig added in v1.6.0

func (cm *ConnectionManager) GetConfig() *models.Config

GetConfig returns the configuration used by this connection manager.

func (*ConnectionManager) GetConnection

func (cm *ConnectionManager) GetConnection(ctx context.Context, connKey string) (_ *Connection, err error)

GetConnection returns a database connection for the given connection key

func (*ConnectionManager) GetDetailedStats added in v1.4.0

func (cm *ConnectionManager) GetDetailedStats() map[string]interface{}

GetDetailedStats returns detailed statistics including cache state

func (*ConnectionManager) GetMaxConnections added in v1.4.0

func (cm *ConnectionManager) GetMaxConnections() int

GetMaxConnections returns the maximum number of connections allowed

func (*ConnectionManager) GetProjectDependedSettings

func (cm *ConnectionManager) GetProjectDependedSettings() ProjectDependedSettings

GetProjectDependedSettings returns project dependent settings

func (*ConnectionManager) GetScopedConnection added in v1.6.0

func (cm *ConnectionManager) GetScopedConnection(ctx context.Context, projectID, scopeKey string) (*Connection, error)

GetScopedConnection returns a pooled driver for projectID + scopeKey (composite cache key).

func (*ConnectionManager) GetStats

func (cm *ConnectionManager) GetStats() ConnectionStats

GetStats returns current connection statistics

func (*ConnectionManager) GetUsagePercent added in v1.4.0

func (cm *ConnectionManager) GetUsagePercent() float64

GetUsagePercent returns the current connection pool usage percentage

func (*ConnectionManager) IsHealthy added in v1.4.0

func (cm *ConnectionManager) IsHealthy() bool

IsHealthy returns true if the connection pool is under 90% capacity

func (*ConnectionManager) RemoveConnection added in v1.4.0

func (cm *ConnectionManager) RemoveConnection(connKey string)

RemoveConnection explicitly removes a connection by key

func (*ConnectionManager) SetProjectDefaultMediaPlugin

func (cm *ConnectionManager) SetProjectDefaultMediaPlugin(defaultStorageProviderId string)

SetProjectDefaultMediaPlugin sets project dependent settings

func (*ConnectionManager) SetProjectLogicExecutionProvider

func (cm *ConnectionManager) SetProjectLogicExecutionProvider(activatedLogicExecutionProvidersID string)

SetProjectLogicExecutionProvider sets project dependent settings

type ConnectionMonitor added in v1.4.0

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

ConnectionMonitor handles health monitoring for the connection manager

func NewConnectionMonitor added in v1.4.0

func NewConnectionMonitor(cm *ConnectionManager) *ConnectionMonitor

NewConnectionMonitor creates a new connection monitor

func (*ConnectionMonitor) ForceHealthCheck added in v1.4.0

func (m *ConnectionMonitor) ForceHealthCheck() ConnectionHealthStatus

ForceHealthCheck forces an immediate health check (useful for API endpoints)

func (*ConnectionMonitor) GetHealthLevel added in v1.4.0

func (m *ConnectionMonitor) GetHealthLevel() HealthLevel

GetHealthLevel returns the current health level

func (*ConnectionMonitor) GetHealthStatus added in v1.4.0

func (m *ConnectionMonitor) GetHealthStatus() ConnectionHealthStatus

GetHealthStatus returns the current health status

func (*ConnectionMonitor) IsHealthy added in v1.4.0

func (m *ConnectionMonitor) IsHealthy() bool

IsHealthy returns true if the connection pool is healthy (under 90% capacity)

func (*ConnectionMonitor) StartMonitoring added in v1.4.0

func (m *ConnectionMonitor) StartMonitoring(ctx context.Context)

StartMonitoring begins the connection health monitoring process

func (*ConnectionMonitor) StopMonitoring added in v1.4.0

func (m *ConnectionMonitor) StopMonitoring()

StopMonitoring stops the connection health monitoring

type ConnectionStats

type ConnectionStats struct {
	ActiveConnections int
	CacheHits         int64
	CacheMisses       int64
	Evictions         int64
	CloseErrors       int64
}

type HealthLevel added in v1.4.0

type HealthLevel string

HealthLevel represents the health level of the connection pool

const (
	HealthLevelHealthy  HealthLevel = "HEALTHY"
	HealthLevelWarning  HealthLevel = "WARNING"
	HealthLevelCritical HealthLevel = "CRITICAL"
)

type ProjectDependedSettings

type ProjectDependedSettings struct {
	ActivatedLogicExecutionProvidersID []string
	DefaultStorageProviderId           string
}

Directories

Path Synopsis
memory
Package memoryCache provides an in-memory cache driver with TTL support
Package memoryCache provides an in-memory cache driver with TTL support
kv
driver/bbolt
Package bbolt provides a BBolt database driver implementation for Apito project operations.
Package bbolt provides a BBolt database driver implementation for Apito project operations.
bootstrapmeta
Package bootstrapmeta holds shared constants and helpers for system DB first-run bootstrap.
Package bootstrapmeta holds shared constants and helpers for system DB first-run bootstrap.
driver/bbolt
Package bbolt provides a BBolt database driver implementation for the Apito system.
Package bbolt provides a BBolt database driver implementation for the Apito system.
driverdefaults
Package driverdefaults holds shared defaults for system DB drivers (SQL, Mongo, etc.).
Package driverdefaults holds shared defaults for system DB drivers (SQL, Mongo, etc.).

Jump to

Keyboard shortcuts

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