db

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseDB

func CloseDB() error

CloseDB closes the global database connection

func GetDB

func GetDB() *sql.DB

GetDB returns the global database connection

func InitDB

func InitDB(config Config) error

InitDB initializes the global database connection

Types

type Config

type Config struct {
	Driver          string
	Host            string
	Port            int
	Username        string
	Password        string
	Database        string
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime int
	DataSource      string
}

Config holds database configuration

type Connection

type Connection struct {
	DB     *sql.DB
	Driver string
}

Connection represents a database connection

func NewConnection

func NewConnection(config Config) (*Connection, error)

NewConnection creates a new database connection based on the driver

func (*Connection) Close

func (c *Connection) Close() error

Close closes the database connection

func (*Connection) Ping

func (c *Connection) Ping() error

Ping checks if the database connection is alive

type Option

type Option struct {
	ID        int64
	Key       string
	Value     string
	CreatedAt time.Time
	UpdatedAt time.Time
}

Option represents a key-value option in the database.

type OptionRepository

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

OptionRepository handles database operations for options.

func NewOptionRepository

func NewOptionRepository(db *sql.DB) *OptionRepository

NewOptionRepository creates a new option repository.

func (*OptionRepository) Create

func (r *OptionRepository) Create(key, value string) error

Create inserts a new option into the database.

func (*OptionRepository) Delete

func (r *OptionRepository) Delete(key string) error

Delete removes an option from the database.

func (*OptionRepository) Get

func (r *OptionRepository) Get(key string) (*Option, error)

Get retrieves an option by key.

func (*OptionRepository) List

func (r *OptionRepository) List() ([]*Option, error)

List retrieves all options from the database.

func (*OptionRepository) Update

func (r *OptionRepository) Update(key, value string) error

Update updates an option value.

Jump to

Keyboard shortcuts

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