database

package
v2.4.42 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColumnExists

func ColumnExists(db *sql.DB, tableName string, columnName string) bool

func NewDatabaseHandler

func NewDatabaseHandler(sqlBackend SqlBackend, opts ...handler.Option) handler.Handler

func NewHandler

func NewHandler(dbType DatabaseType, opts ...handler.Option) (handler.Handler, error)

NewHandler creates a new database handler based on the database type

func NewMySQLHandler

func NewMySQLHandler(opts ...handler.Option) handler.Handler

func NewPostgresHandler

func NewPostgresHandler(opts ...handler.Option) handler.Handler

func NewSQLiteHandler

func NewSQLiteHandler(opts ...handler.Option) handler.Handler

Types

type DatabaseType

type DatabaseType string

DatabaseType represents the type of database to use

const (
	SQLite     DatabaseType = "sqlite"
	MySQL      DatabaseType = "mysql"
	PostgreSQL DatabaseType = "postgres"
)

func DetectDatabaseType

func DetectDatabaseType(connectionString string) (DatabaseType, error)

DetectDatabaseType attempts to detect the database type from a connection string

type MysqlBackend

type MysqlBackend struct {
}

func (MysqlBackend) CreateSchema

func (b MysqlBackend) CreateSchema(db *sql.DB)

Create db/schema if necessary

func (MysqlBackend) GetDriverName

func (b MysqlBackend) GetDriverName() string

func (MysqlBackend) GetPrepareSymbol

func (b MysqlBackend) GetPrepareSymbol() string

func (MysqlBackend) MigrateSchema

func (b MysqlBackend) MigrateSchema(db *sql.DB, checker func(*sql.DB, string, string) bool)

Migrate schema if necessary

type PostgresBackend

type PostgresBackend struct {
}

func (PostgresBackend) CreateSchema

func (b PostgresBackend) CreateSchema(db *sql.DB)

Create db/schema if necessary

func (PostgresBackend) GetDriverName

func (b PostgresBackend) GetDriverName() string

func (PostgresBackend) GetPrepareSymbol

func (b PostgresBackend) GetPrepareSymbol() string

func (PostgresBackend) MigrateSchema

func (b PostgresBackend) MigrateSchema(db *sql.DB, checker func(*sql.DB, string, string) bool)

Migrate schema if necessary

type SqlBackend

type SqlBackend interface {
	// Name used by database/sql when loading the driver
	GetDriverName() string
	// Create db/schema if necessary
	CreateSchema(db *sql.DB)
	// Migrate schema if necessary
	MigrateSchema(db *sql.DB, checker func(*sql.DB, string, string) bool)
	//
	GetPrepareSymbol() string
}

type SqliteBackend

type SqliteBackend struct {
}

func (SqliteBackend) CreateSchema

func (b SqliteBackend) CreateSchema(db *sql.DB)

Create db/schema if necessary

func (SqliteBackend) GetDriverName

func (b SqliteBackend) GetDriverName() string

func (SqliteBackend) GetPrepareSymbol

func (b SqliteBackend) GetPrepareSymbol() string

func (SqliteBackend) MigrateSchema

func (b SqliteBackend) MigrateSchema(db *sql.DB, checker func(*sql.DB, string, string) bool)

Migrate schema if necessary

Jump to

Keyboard shortcuts

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