setup

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package setup provides database connection setup with repository initialization. This package bridges the database and repository packages to avoid import cycles.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection interface {
	// Type returns the database type.
	Type() database.DatabaseType
	// Close closes the database connection.
	Close() error
	// Ping verifies the database connection is alive.
	Ping() error
	// Repositories returns the repository interfaces for this connection.
	Repositories() *repository.Repositories
	// DB returns the raw sql.DB for PostgreSQL connections (nil for MongoDB).
	DB() *sql.DB
	// MongoClient returns the MongoDB client for MongoDB connections (nil for PostgreSQL).
	MongoClient() *mongodb.Client
}

Connection represents a database connection with repositories.

func MustNewConnection

func MustNewConnection(cfg database.DatabaseConfig) Connection

MustNewConnection creates a new database connection and panics on error.

func MustNewConnectionWithLogger

func MustNewConnectionWithLogger(cfg database.DatabaseConfig, logger *slog.Logger) Connection

MustNewConnectionWithLogger creates a new database connection with a logger and panics on error.

func NewConnection

func NewConnection(cfg database.DatabaseConfig) (Connection, error)

NewConnection creates a new database connection based on the configuration. For PostgreSQL, it returns a PostgresConnection with an active *sql.DB. For MongoDB, it returns a MongoDBConnection with an active client.

func NewConnectionWithLogger

func NewConnectionWithLogger(cfg database.DatabaseConfig, logger *slog.Logger) (Connection, error)

NewConnectionWithLogger creates a new database connection with a custom logger.

type MongoDBConnection

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

MongoDBConnection wraps a MongoDB connection with repository adapters.

func (*MongoDBConnection) Close

func (c *MongoDBConnection) Close() error

Close closes the MongoDB connection.

func (*MongoDBConnection) DB

func (c *MongoDBConnection) DB() *sql.DB

DB returns nil for MongoDB connections.

func (*MongoDBConnection) MongoClient

func (c *MongoDBConnection) MongoClient() *mongodb.Client

MongoClient returns the MongoDB client.

func (*MongoDBConnection) Ping

func (c *MongoDBConnection) Ping() error

Ping verifies the MongoDB connection is alive.

func (*MongoDBConnection) Repositories

func (c *MongoDBConnection) Repositories() *repository.Repositories

Repositories returns the repository interfaces for MongoDB.

func (*MongoDBConnection) Type

Type returns DatabaseTypeMongoDB.

type PostgresConnection

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

PostgresConnection wraps a PostgreSQL database connection with repositories.

func (*PostgresConnection) Close

func (c *PostgresConnection) Close() error

Close closes the PostgreSQL connection.

func (*PostgresConnection) DB

func (c *PostgresConnection) DB() *sql.DB

DB returns the raw sql.DB connection.

func (*PostgresConnection) MongoClient

func (c *PostgresConnection) MongoClient() *mongodb.Client

MongoClient returns nil for PostgreSQL connections.

func (*PostgresConnection) Ping

func (c *PostgresConnection) Ping() error

Ping verifies the PostgreSQL connection is alive.

func (*PostgresConnection) Repositories

func (c *PostgresConnection) Repositories() *repository.Repositories

Repositories returns the repository interfaces for PostgreSQL.

func (*PostgresConnection) Type

Type returns DatabaseTypePostgres.

Jump to

Keyboard shortcuts

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