database

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: Apache-2.0 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

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

MigrateDSN returns the Migration Data Source Name for the database configuration.

type Database

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

func NewDatabase

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

NewDatabase initializes the Database struct and establishes a connection.

func (*Database) Close

func (db *Database) Close() error

Close closes the database connection.

func (*Database) MigrateDown

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

MigrateDown handles database down migrations from the specified directory.

func (*Database) MigrateUp

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