database

package
v0.3.5 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Type       Type   // The type of database
	DBName     string // The name of database
	Host       string // The host of database
	Port       int    // The port of database
	Username   string // The username of database
	Password   string // The password of database
	DBFilePath string // The file path for sqlite
}

Config holds the configuration for connecting to a database.

func (Config) DSN

func (c Config) DSN() (string, error)

DSN returns the Data Source Name for the database configuration.

func (Config) MigrateDSN added in v0.3.0

func (c Config) MigrateDSN() (string, error)

type Database added in v0.3.0

type Database struct {
	Config Config
	Conn   *sqlx.DB
}

func NewDatabase added in v0.3.0

func NewDatabase(config Config) (*Database, error)

NewDatabase initializes the Database struct and establishes a connection.

func (*Database) Close added in v0.3.0

func (db *Database) Close() error

Close closes the database connection.

func (*Database) MigrateDown added in v0.3.0

func (db *Database) MigrateDown(migrationsDir string) error

MigrateDown handles database down migrations from the specified directory.

func (*Database) MigrateUp added in v0.3.0

func (db *Database) MigrateUp(migrationsDir string) error

MigrateUp handles database up migrations from the specified directory.

type Type

type Type string

Type represents the type of database (e.g., MySQL, PostgreSQL, SQLite).

const (
	// Supported database types
	TypeMySQL    Type = "mysql"
	TypePostgres Type = "postgres"
	TypeSQLite   Type = "sqlite3"
)

Jump to

Keyboard shortcuts

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