Documentation
¶
Overview ¶
Package storage provides shared database connections for all features. This abstraction allows multiple features (audit logging, IAM, guardrails) to share a single database connection.
Index ¶
Constants ¶
const ( TypeSQLite = "sqlite" TypePostgreSQL = "postgresql" TypeMongoDB = "mongodb" )
Type constants for storage backends
const DefaultSQLitePath = "data/gomodel.db"
DefaultSQLitePath is the default file path for the SQLite database.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Type specifies the storage backend: "sqlite", "postgresql", or "mongodb"
Type string
// SQLite configuration
SQLite SQLiteConfig
// PostgreSQL configuration
PostgreSQL PostgreSQLConfig
// MongoDB configuration
MongoDB MongoDBConfig
}
Config holds storage configuration
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults
type MongoDBConfig ¶
type MongoDBConfig struct {
// URL is the connection string (e.g., mongodb://localhost:27017)
URL string
// Database is the database name (default: gomodel)
Database string
}
MongoDBConfig holds MongoDB-specific configuration
type MongoDBStorage ¶
MongoDBStorage exposes a MongoDB database handle.
func NewMongoDB ¶
func NewMongoDB(ctx context.Context, cfg MongoDBConfig) (MongoDBStorage, error)
NewMongoDB creates a new MongoDB storage connection.
type PostgreSQLConfig ¶
type PostgreSQLConfig struct {
// URL is the connection string (e.g., postgres://user:pass@localhost/dbname)
URL string
// MaxConns is the maximum connection pool size (default: 10)
MaxConns int
}
PostgreSQLConfig holds PostgreSQL-specific configuration
type PostgreSQLStorage ¶
PostgreSQLStorage exposes a PostgreSQL connection pool.
func NewPostgreSQL ¶
func NewPostgreSQL(ctx context.Context, cfg PostgreSQLConfig) (PostgreSQLStorage, error)
NewPostgreSQL creates a new PostgreSQL storage connection. It creates a connection pool for efficient connection reuse.
type SQLiteConfig ¶
type SQLiteConfig struct {
// Path is the database file path (default: data/gomodel.db)
Path string
}
SQLiteConfig holds SQLite-specific configuration
type SQLiteStorage ¶
SQLiteStorage exposes a SQLite database handle.
func NewSQLite ¶
func NewSQLite(cfg SQLiteConfig) (SQLiteStorage, error)
NewSQLite creates a new SQLite storage connection. It enables WAL mode for better concurrent read/write performance.