{"modulePath":"github.com/bitechdev/ResolveSpec","version":"v1.3.14","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package providers\n\n## Variables\n\n```go\nvar (\n\t// ErrNotSQLDatabase is returned when attempting SQL operations on a non-SQL database\n\tErrNotSQLDatabase = errors.New(\"not a SQL database\")\n\n\t// ErrNotMongoDB is returned when attempting MongoDB operations on a non-MongoDB connection\n\tErrNotMongoDB = errors.New(\"not a MongoDB connection\")\n)\n```\nCommon errors\n\n## Types\n\n```go\ntype ConnectionConfig interface {\n\tBuildDSN() (string, error)\n\tGetName() string\n\tGetType() string\n\tGetHost() string\n\tGetPort() int\n\tGetUser() string\n\tGetPassword() string\n\tGetDatabase() string\n\tGetFilePath() string\n\tGetConnectTimeout() time.Duration\n\tGetQueryTimeout() time.Duration\n\tGetEnableLogging() bool\n\tGetEnableMetrics() bool\n\tGetMaxOpenConns() *int\n\tGetMaxIdleConns() *int\n\tGetConnMaxLifetime() *time.Duration\n\tGetConnMaxIdleTime() *time.Duration\n\tGetReadPreference() string\n\tGetApplicationName() string\n\tGetRetryAttempts() int\n\tGetRetryDelay() time.Duration\n\tGetRetryMaxDelay() time.Duration\n}\n```\nConnectionConfig is a minimal interface for configuration The actual implementation is in dbmanager package\n\n```go\ntype ConnectionStats struct {\n\tName              string\n\tType              string // Database type as string to avoid circular dependency\n\tConnected         bool\n\tLastHealthCheck   time.Time\n\tHealthCheckStatus string\n\n\t// SQL connection pool stats\n\tOpenConnections    int\n\tMaxOpenConnections int\n\tTotalOpened        int64 // physical connections ever dialled (0 when unknown)\n\tInUse              int\n\tIdle               int\n\tWaitCount          int64\n\tWaitDuration       time.Duration\n\tMaxIdleClosed      int64\n\tMaxLifetimeClosed  int64\n}\n```\nConnectionStats contains statistics about a database connection\n\n```go\ntype ExistingDBProvider struct {\n\t// contains filtered or unexported fields\n}\n```\nExistingDBProvider wraps an existing \\*sql.DB connection This allows using dbmanager features with a database connection that was opened outside of the dbmanager package\n\n```go\nfunc NewExistingDBProvider(db *sql.DB, name string) *ExistingDBProvider\n```\nNewExistingDBProvider creates a new provider wrapping an existing \\*sql.DB\n\n```go\nfunc (p *ExistingDBProvider) Close() error\n```\nClose is a no-op for the wrapped database. The pool belongs to the caller, so closing it here would break the caller's other users of it.\n\n```go\nfunc (p *ExistingDBProvider) Connect(ctx context.Context, cfg ConnectionConfig) error\n```\nConnect verifies the existing database connection is valid It does NOT create a new connection, but ensures the existing one works\n\n```go\nfunc (p *ExistingDBProvider) GetMongo() (*mongo.Client, error)\n```\nGetMongo returns an error since this is a SQL database\n\n```go\nfunc (p *ExistingDBProvider) GetNative() (*sql.DB, error)\n```\nGetNative returns the wrapped \\*sql.DB\n\n```go\nfunc (p *ExistingDBProvider) HealthCheck(ctx context.Context) error\n```\nHealthCheck verifies the connection is alive\n\n```go\nfunc (p *ExistingDBProvider) OwnsDB() bool\n```\nOwnsDB reports whether Close releases the wrapped database. It never does: the \\*sql.DB was opened by the caller, who is responsible for closing it.\n\n```go\nfunc (p *ExistingDBProvider) Refresh(ctx context.Context) error\n```\nRefresh verifies the wrapped database is still reachable. The pool belongs to the caller and cannot be re-dialed here, so it is never closed to \"reconnect\".\n\n```go\nfunc (p *ExistingDBProvider) Stats() *ConnectionStats\n```\nStats returns connection statistics\n\n```go\ntype MSSQLProvider struct {\n\t// contains filtered or unexported fields\n}\n```\nMSSQLProvider implements Provider for Microsoft SQL Server databases\n\n```go\nfunc NewMSSQLProvider() *MSSQLProvider\n```\nNewMSSQLProvider creates a new MSSQL provider\n\n```go\nfunc (p *MSSQLProvider) Close() error\n```\nClose closes the MSSQL connection\n\n```go\nfunc (p *MSSQLProvider) Connect(ctx context.Context, cfg ConnectionConfig) error\n```\nConnect establishes a MSSQL connection\n\n```go\nfunc (p *MSSQLProvider) GetMongo() (*mongo.Client, error)\n```\nGetMongo returns an error for MSSQL (not a MongoDB connection)\n\n```go\nfunc (p *MSSQLProvider) GetNative() (*sql.DB, error)\n```\nGetNative returns the native \\*sql.DB connection\n\n```go\nfunc (p *MSSQLProvider) HealthCheck(ctx context.Context) error\n```\nHealthCheck verifies the MSSQL connection is alive\n\n```go\nfunc (p *MSSQLProvider) Stats() *ConnectionStats\n```\nStats returns connection pool statistics\n\n```go\ntype MongoProvider struct {\n\t// contains filtered or unexported fields\n}\n```\nMongoProvider implements Provider for MongoDB databases\n\n```go\nfunc NewMongoProvider() *MongoProvider\n```\nNewMongoProvider creates a new MongoDB provider\n\n```go\nfunc (p *MongoProvider) Close() error\n```\nClose closes the MongoDB connection\n\n```go\nfunc (p *MongoProvider) Connect(ctx context.Context, cfg ConnectionConfig) error\n```\nConnect establishes a MongoDB connection\n\n```go\nfunc (p *MongoProvider) GetMongo() (*mongo.Client, error)\n```\nGetMongo returns the MongoDB client\n\n```go\nfunc (p *MongoProvider) GetNative() (*sql.DB, error)\n```\nGetNative returns an error for MongoDB (not a SQL database)\n\n```go\nfunc (p *MongoProvider) HealthCheck(ctx context.Context) error\n```\nHealthCheck verifies the MongoDB connection is alive\n\n```go\nfunc (p *MongoProvider) Stats() *ConnectionStats\n```\nStats returns connection statistics for MongoDB\n\n```go\ntype NotificationHandler func(channel string, payload string)\n```\nNotificationHandler is called when a notification is received\n\n```go\ntype PostgresListener struct {\n\t// contains filtered or unexported fields\n}\n```\nPostgresListener manages PostgreSQL LISTEN/NOTIFY functionality\n\n```go\nfunc NewPostgresListener(cfg ConnectionConfig) *PostgresListener\n```\nNewPostgresListener creates a new PostgreSQL listener\n\n```go\nfunc (l *PostgresListener) Channels() []string\n```\nChannels returns the list of channels currently being listened to\n\n```go\nfunc (l *PostgresListener) Close() error\n```\nClose closes the listener and all subscriptions. Closing the connection drops every subscription server-side, so no UNLISTEN round trips are needed, and the close itself is bounded so a dead socket cannot hang the caller.\n\n```go\nfunc (l *PostgresListener) Connect(ctx context.Context) error\n```\nConnect establishes a dedicated connection for listening and starts the background loops (once per listener).\n\n```go\nfunc (l *PostgresListener) IsConnected() bool\n```\nIsConnected returns true if the listener is connected\n\n```go\nfunc (l *PostgresListener) Listen(channel string, handler NotificationHandler) error\n```\nListen subscribes to a PostgreSQL notification channel\n\n```go\nfunc (l *PostgresListener) Notify(ctx context.Context, channel string, payload string) error\n```\nNotify sends a notification to a PostgreSQL channel\n\n```go\nfunc (l *PostgresListener) Unlisten(channel string) error\n```\nUnlisten unsubscribes from a PostgreSQL notification channel\n\n```go\ntype PostgresProvider struct {\n\t// contains filtered or unexported fields\n}\n```\nPostgresProvider implements Provider for PostgreSQL databases\n\n```go\nfunc NewPostgresProvider() *PostgresProvider\n```\nNewPostgresProvider creates a new PostgreSQL provider\n\n```go\nfunc (p *PostgresProvider) Close() error\n```\nClose closes the PostgreSQL connection. A listener failure does not stop the pool from being closed.\n\n```go\nfunc (p *PostgresProvider) Connect(ctx context.Context, cfg ConnectionConfig) error\n```\nConnect establishes a PostgreSQL connection\n\n```go\nfunc (p *PostgresProvider) GetListener(ctx context.Context) (*PostgresListener, error)\n```\nGetListener returns a PostgreSQL listener for NOTIFY/LISTEN functionality The listener is lazily initialized on first call and reused for subsequent calls\n\n```go\nfunc (p *PostgresProvider) GetMongo() (*mongo.Client, error)\n```\nGetMongo returns an error for PostgreSQL (not a MongoDB connection)\n\n```go\nfunc (p *PostgresProvider) GetNative() (*sql.DB, error)\n```\nGetNative returns the native \\*sql.DB connection\n\n```go\nfunc (p *PostgresProvider) HealthCheck(ctx context.Context) error\n```\nHealthCheck verifies the PostgreSQL connection is alive\n\n```go\nfunc (p *PostgresProvider) Refresh(ctx context.Context) error\n```\nRefresh retires every pooled connection and dials fresh ones on demand, without closing the \\*sql.DB. Handles already handed out keep working: connections in use finish their current query and are then discarded.\n\n```go\nfunc (p *PostgresProvider) Stats() *ConnectionStats\n```\nStats returns connection pool statistics\n\n```go\ntype Provider interface {\n\t// Connect establishes the database connection\n\tConnect(ctx context.Context, cfg ConnectionConfig) error\n\n\t// Close closes the connection\n\tClose() error\n\n\t// HealthCheck verifies the connection is alive\n\tHealthCheck(ctx context.Context) error\n\n\t// GetNative returns the native *sql.DB (SQL databases only)\n\t// Returns an error for non-SQL databases\n\tGetNative() (*sql.DB, error)\n\n\t// GetMongo returns the MongoDB client (MongoDB only)\n\t// Returns an error for non-MongoDB databases\n\tGetMongo() (*mongo.Client, error)\n\n\t// Stats returns connection statistics\n\tStats() *ConnectionStats\n}\n```\nProvider creates and manages the underlying database connection\n\n```go\ntype Refresher interface {\n\tRefresh(ctx context.Context) error\n}\n```\nRefresher is implemented by providers that can retire their pooled connections and dial fresh ones without closing the shared \\*sql.DB, so handles already handed out keep working.\n\n```go\ntype SQLiteProvider struct {\n\t// contains filtered or unexported fields\n}\n```\nSQLiteProvider implements Provider for SQLite databases\n\n```go\nfunc NewSQLiteProvider() *SQLiteProvider\n```\nNewSQLiteProvider creates a new SQLite provider\n\n```go\nfunc (p *SQLiteProvider) Close() error\n```\nClose closes the SQLite connection\n\n```go\nfunc (p *SQLiteProvider) Connect(ctx context.Context, cfg ConnectionConfig) error\n```\nConnect establishes a SQLite connection\n\n```go\nfunc (p *SQLiteProvider) GetMongo() (*mongo.Client, error)\n```\nGetMongo returns an error for SQLite (not a MongoDB connection)\n\n```go\nfunc (p *SQLiteProvider) GetNative() (*sql.DB, error)\n```\nGetNative returns the native \\*sql.DB connection\n\n```go\nfunc (p *SQLiteProvider) HealthCheck(ctx context.Context) error\n```\nHealthCheck verifies the SQLite connection is alive\n\n```go\nfunc (p *SQLiteProvider) Stats() *ConnectionStats\n```\nStats returns connection pool statistics\n\n","path":"github.com/bitechdev/ResolveSpec/pkg/dbmanager/providers","name":"providers","synopsis":"","isRedistributable":true}
