storage

package
v0.0.0-...-de52b65 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMockDB

func GetMockDB(t *testing.T) (*gorm.DB, sqlmock.Sqlmock)

GetMockDB returns a GORM database instance and a sqlmock.Sqlmock for testing purposes.

func NewDB

func NewDB(connector DBConnector, conf DBConfig) (*gorm.DB, error)

NewDB initializes the database connection based on the provided DBConfig. If there is an error connecting to the database, it returns an error.

Types

type DBConfig

type DBConfig struct {
	MaxIdleConns int // maximum number of connections in the idle connection pool
	MaxOpenConns int // maximum number of open connections to the database
}

DBConfig is db related configuration

type DBConnector

type DBConnector interface {
	// Connect connects to the database and returns a *gorm.DB instance and an error.
	Connect() (*gorm.DB, error)
}

DBConnector is an interface that represents a database connector.

type MockDBConnector

type MockDBConnector struct {
	DB *gorm.DB
}

MockDBConnector is a mock implementation of a DBConnector interface that returns a pre-configured GORM database instance.

func (*MockDBConnector) Connect

func (c *MockDBConnector) Connect() (*gorm.DB, error)

Connect returns the pre-configured GORM database instance.

type PostgresDBConnector

type PostgresDBConnector struct {
	DSN        string
	ReplicaDSN string
}

PostgresDBConnector is an implementation of the DBConnector interface that connects to a real database for PostgreSQL.

func (*PostgresDBConnector) Connect

func (c *PostgresDBConnector) Connect() (*gorm.DB, error)

Connect connects to the database using the DSN provided in the PostgresDBConnector instance and returns a *gorm.DB instance and an error

Jump to

Keyboard shortcuts

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