mysql

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

vormia-go-driver-mysql

Pure-Go MySQL driver for Vormia Go — thin database/sql wrapper over go-sql-driver/mysql that satisfies the shared Database contract.

Install

go get github.com/vormialabs/vormia-go-driver-mysql@v1.1.0

Usage

import mysql "github.com/vormialabs/vormia-go-driver-mysql"

db, err := mysql.Open(mysql.Config{
    Host:     "localhost",
    Port:     3306,
    User:     "root",
    Password: "secret",
    Database: "myapp",
})
if err != nil {
    log.Fatal(err)
}
defer db.Close()

// MySQL uses ? placeholders natively; Rebind is the identity function
// and exists only to keep queries portable across drivers.
query := db.Rebind("SELECT * FROM users WHERE id = ?")
rows, err := db.QueryContext(ctx, query, userID)

parseTime=true and loc=UTC are set by default, so DATETIME/TIMESTAMP columns scan into time.Time instead of []byte.

Config

Field Default Description
Host localhost MySQL host
Port 3306 MySQL port
Params — Extra DSN parameters (e.g. "charset": "utf8mb4")
MaxOpenConns 0 (unlimited) Set deliberately in production (e.g. 10–25)
MaxIdleConns 0 Idle connections kept in the pool
ConnMaxLifetime 0 Max lifetime of a connection

Testing

Unit tests (TestRebind, contract check) run without a database:

go test ./...

Integration tests require a running MySQL. Set MYSQL_TEST_HOST to enable them:

docker run --name vormia-mysql \
  -e MYSQL_ROOT_PASSWORD=root \
  -e MYSQL_DATABASE=testdb \
  -p 3306:3306 -d mysql:8

# MySQL takes a few seconds to accept connections on first boot.
export MYSQL_TEST_HOST=127.0.0.1
export MYSQL_TEST_PASSWORD=root

go test -v ./...
Env var Default
MYSQL_TEST_HOST (required to run integration tests)
MYSQL_TEST_PORT 3306
MYSQL_TEST_USER root
MYSQL_TEST_PASSWORD root
MYSQL_TEST_DB testdb

Release Notes

v1.1.0
  • Confirmed ready for framework db.Wipe / seed.Run (db:wipe / db:seed) using only the existing Database contract (QueryContext, ExecContext, BeginTx).
  • MySQL wipe pattern verified: catalog via information_schema, SET FOREIGN_KEY_CHECKS=0/1, and non-transactional DROP TABLE as separate ExecContext calls (no multiStatements DSN change).
  • No public API or behavior changes in this driver.
v1.0.0
  • Initial release: thin database/sql wrapper over go-sql-driver/mysql with shared Database contract, identity Rebind, and default parseTime=true / loc=UTC.

License

MIT

Documentation

Overview

Package mysql is a thin database/sql wrapper over go-sql-driver/mysql that satisfies the shared Vormia Database contract.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Host     string
	Port     int
	User     string
	Password string
	Database string

	// Params are extra DSN parameters (e.g. "charset": "utf8mb4").
	// parseTime and loc are set sensibly by default below.
	Params map[string]string

	// Pool tuning. Zero means "use database/sql defaults".
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime time.Duration
}

Config describes how to open a MySQL database.

type DB

type DB struct {
	*sql.DB
}

DB wraps *sql.DB. Embedding promotes all standard methods so the framework's Database contract is satisfied directly.

func Open

func Open(cfg Config) (*DB, error)

Open builds the DSN with the official mysql.Config builder, opens the pool, applies tuning, and verifies connectivity.

func (*DB) Rebind

func (d *DB) Rebind(query string) string

Rebind returns the query unchanged: MySQL uses ? placeholders natively, same as SQLite. It exists only to satisfy the uniform contract.

Jump to

Keyboard shortcuts

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