Documentation
¶
Index ¶
- Variables
- func GetProviderDisplayName(provider string) string
- func Has(name string) bool
- func List() []string
- func MustRegister(name string, factory DriverFactory)
- func Register(name string, factory DriverFactory) error
- func RunTestSuite()
- func TestClientCreation()
- func TestConfigBuilders()
- func TestMySQLPrismaMigrations()
- func TestPostgresPrismaMigrations()
- func TestRegistryList()
- type BaseDriver
- func (d *BaseDriver) Close() error
- func (d *BaseDriver) Connect(cfg *Config) error
- func (d *BaseDriver) DB() *sql.DB
- func (d *BaseDriver) Exec(query string, args ...any) (sql.Result, error)
- func (d *BaseDriver) Name() string
- func (d *BaseDriver) Ping() error
- func (d *BaseDriver) Query(query string, args ...any) (*sql.Rows, error)
- func (d *BaseDriver) QueryRow(query string, args ...any) *sql.Row
- func (d *BaseDriver) SetDB(db *sql.DB)
- func (d *BaseDriver) SetName(name string)
- type Client
- func (c *Client) Close() error
- func (c *Client) Config() *Config
- func (c *Client) Connect(cfg *Config) error
- func (c *Client) DB() *sql.DB
- func (c *Client) Driver() DBDriver
- func (c *Client) DriverName() string
- func (c *Client) Exec(query string, args ...any) (sql.Result, error)
- func (c *Client) Ping() error
- func (c *Client) Query(query string, args ...any) (*sql.Rows, error)
- func (c *Client) QueryRow(query string, args ...any) *sql.Row
- type Config
- func (c *Config) MySQLDSN() string
- func (c *Config) PostgresDSN() string
- func (c *Config) WithDatabase(database string) *Config
- func (c *Config) WithExtra(key, value string) *Config
- func (c *Config) WithHost(host string) *Config
- func (c *Config) WithPassword(password string) *Config
- func (c *Config) WithPort(port int) *Config
- func (c *Config) WithSSLMode(mode string) *Config
- func (c *Config) WithUser(user string) *Config
- type DBDriver
- type DriverFactory
- type Registry
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotConnected is returned when trying to use a driver that hasn't been connected ErrNotConnected = errors.New("database: not connected") // ErrDriverNotFound is returned when a driver is not registered ErrDriverNotFound = errors.New("database: driver not found") // ErrDriverAlreadyRegistered is returned when trying to register a driver with an existing name ErrDriverAlreadyRegistered = errors.New("database: driver already registered") )
var ProviderDisplayNames = map[string]string{
"postgresql": "PostgreSQL",
"postgres": "PostgreSQL",
"mysql": "MySQL",
"sqlite": "SQLite",
"sqlserver": "SQL Server",
"mongodb": "MongoDB",
"cockroachdb": "CockroachDB",
}
ProviderDisplayNames maps provider names to their display names
Functions ¶
func GetProviderDisplayName ¶
GetProviderDisplayName returns the formatted display name for a provider
func MustRegister ¶
func MustRegister(name string, factory DriverFactory)
MustRegister registers a driver and panics on error
func Register ¶
func Register(name string, factory DriverFactory) error
Register registers a driver factory with a name
func TestClientCreation ¶
func TestClientCreation()
TestClientCreation tests client creation without actual connection
func TestMySQLPrismaMigrations ¶
func TestMySQLPrismaMigrations()
TestMySQLPrismaMigrations connects to MySQL and fetches Prisma migrations
func TestPostgresPrismaMigrations ¶
func TestPostgresPrismaMigrations()
TestPostgresPrismaMigrations connects to PostgreSQL and fetches Prisma migrations
Types ¶
type BaseDriver ¶
type BaseDriver struct {
// contains filtered or unexported fields
}
BaseDriver provides common functionality for SQL-based drivers
func (*BaseDriver) Connect ¶
func (d *BaseDriver) Connect(cfg *Config) error
Connect is a no-op for BaseDriver (used when connection is already established)
func (*BaseDriver) QueryRow ¶
func (d *BaseDriver) QueryRow(query string, args ...any) *sql.Row
QueryRow executes a query that returns at most one row
func (*BaseDriver) SetDB ¶
func (d *BaseDriver) SetDB(db *sql.DB)
SetDB sets the underlying database connection
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a high-level wrapper around DBDriver
func NewClientFromDSN ¶
NewClientFromDSN creates a new client and connects using a DSN string driverName should be the Prisma provider name (postgresql, mysql, etc.)
func (*Client) DriverName ¶
DriverName returns the name of the driver
type Config ¶
type Config struct {
Host string
Port int
User string
Password string
Database string
SSLMode string // disable, require, verify-ca, verify-full
Extra map[string]string // DBMS-specific options
}
Config holds database connection configuration
func (*Config) PostgresDSN ¶
PostgresDSN returns a PostgreSQL connection string
func (*Config) WithDatabase ¶
WithDatabase sets the database name
func (*Config) WithPassword ¶
WithPassword sets the password
func (*Config) WithSSLMode ¶
WithSSLMode sets the SSL mode
type DBDriver ¶
type DBDriver interface {
// Name returns the driver name (e.g., "postgres", "mysql")
Name() string
// Connect establishes a connection using the provided config
Connect(cfg *Config) error
// Close closes the database connection
Close() error
// Ping verifies the connection is alive
Ping() error
// Query executes a query that returns rows
Query(query string, args ...any) (*sql.Rows, error)
// QueryRow executes a query that returns at most one row
QueryRow(query string, args ...any) *sql.Row
// Exec executes a query without returning rows
Exec(query string, args ...any) (sql.Result, error)
// DB returns the underlying *sql.DB for advanced operations
DB() *sql.DB
}
DBDriver defines the interface for database drivers (Strategy pattern)
type DriverFactory ¶
type DriverFactory func() DBDriver
DriverFactory is a function that creates a new DBDriver instance