db

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClosePostgresDB

func ClosePostgresDB() error

ClosePostgresDB closes the PostgreSQL database connection

func CloseRedisClient

func CloseRedisClient() error

CloseRedisClient closes the Redis client

func CloseSQLiteDB

func CloseSQLiteDB() error

CloseSQLiteDB closes the SQLite database connection

func GetPostgresDB

func GetPostgresDB() (*sql.DB, error)

GetPostgresDB returns a singleton PostgreSQL database connection

func GetRedisClient

func GetRedisClient() (*redis.Client, error)

GetRedisClient returns a singleton Redis client

func GetSQLiteDB

func GetSQLiteDB() (*sql.DB, error)

GetSQLiteDB returns a singleton SQLite database connection

Types

type DatabaseType

type DatabaseType string

DatabaseType represents the type of database

const (
	// PostgreSQL database type
	PostgreSQL DatabaseType = "postgres"
	// SQLite database type
	SQLite DatabaseType = "sqlite"
	// Redis database type (not SQL)
	Redis DatabaseType = "redis"
)

type Service

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

Service provides a unified interface for database operations

func NewService

func NewService(dbType DatabaseType) (*Service, error)

NewService creates a new database service

func (*Service) Close

func (s *Service) Close() error

Close closes the database connection

func (*Service) Exec

func (s *Service) Exec(query string, args ...any) (sql.Result, error)

Exec executes a SQL statement (for SQL databases only)

func (*Service) GetDB

func (s *Service) GetDB() *sql.DB

GetDB returns the underlying SQL database connection

func (*Service) GetRedis

func (s *Service) GetRedis() any

GetRedis returns the underlying Redis client

func (*Service) Query

func (s *Service) Query(query string, args ...any) (*sql.Rows, error)

Query executes a SQL query and returns the rows (for SQL databases only)

Jump to

Keyboard shortcuts

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