mysql

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 12 Imported by: 0

README

NLG MySQL Driver

MySQL driver for the NetLife Guru Go database layer.

Use mysql to connect MySQL databases to the shared github.com/netlifeguru/db repository API with mapper-backed result scanning.

Go Reference Go Report Card Go Version License


About

mysql is the MySQL driver package for the NetLife Guru Go database stack.

It provides real MySQL database connections that implement the shared db.Conn interface from github.com/netlifeguru/db.

Application code normally imports this package to open MySQL connections, while repository code can depend on the shared db package.

How It Fits Together

Layer Package Purpose
Mapper github.com/netlifeguru/mapper Row-to-struct and map scanning
DB github.com/netlifeguru/db Shared query and repository API
Driver github.com/netlifeguru/db-mysql Real MySQL database connections

Features

  • MySQL Driver: Connects the shared NetLife Guru database layer to MySQL
  • Shared DB Interface: Provides connections compatible with db.Conn
  • Repository Friendly: Lets repository code use common db helpers such as List, Get, Value, and Maps
  • Mapper Integration: Uses github.com/netlifeguru/mapper for struct, map, and scalar result scanning
  • SQL Model Support: Works with MySQL model.sql files through the shared db package
  • Transaction Support: Supports transaction workflows through the shared database layer
  • Explicit SQL: Designed for applications that prefer direct SQL and typed repository helpers
  • Standard Go Friendly: Built around context-aware operations, interfaces, structs, and explicit error handling

Requirements

This package requires Go 1.24 or newer.

  • Go: 1.24 or newer
  • Shared dependencies: github.com/netlifeguru/db, github.com/netlifeguru/mapper
  • Database: MySQL-compatible server

Installation

Add the MySQL driver to your project using go get:

go get github.com/netlifeguru/db-mysql

This also installs the shared db and mapper packages required by the driver.

Basic Usage

import (
	"context"

	"github.com/netlifeguru/db"
	"github.com/netlifeguru/db-mysql"
)

Once a MySQL connection is created, repository code can work with the shared db.Conn interface:

func ListUsers(ctx context.Context, conn db.Conn) ([]User, error) {
	return db.List[User](ctx, conn, db.Raw(`
		SELECT *
		FROM users
		ORDER BY created_at DESC
	`))
}

Documentation

Full package documentation, guides, and examples are available at:

https://netlife.guru/docs/go/mysql

Shared database layer documentation:

https://netlife.guru/docs/go/db

API reference is also available on pkg.go.dev:

https://pkg.go.dev/github.com/netlifeguru/db-mysql


Notes

  • This package is the MySQL driver for the shared NetLife Guru database layer.
  • Repository code can depend on github.com/netlifeguru/db while application setup imports this driver.
  • Review package-specific concurrency behavior before using it in highly parallel workloads.
  • Check performance characteristics when using this package in latency-sensitive paths.
  • See the package documentation and examples for limitations and recommended usage patterns.

Versioning

This project follows Semantic Versioning.

See CHANGELOG.md for release history and breaking changes.


Contributing

Community contributions, feedback, and improvements are welcome.

Please read CONTRIBUTING.md before submitting pull requests or opening issues.


Code of Conduct

This project follows a Code of Conduct.

Please read CODE_OF_CONDUCT.md before contributing or participating in discussions.


Author

Created and maintained by NetLife Guru s.r.o.


License

MIT License. See LICENSE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connect

type Connect struct {
	Host       string
	Identifier string
	TX         any

	Timeout time.Duration
	// contains filtered or unexported fields
}

func New

func New() *Connect

func (*Connect) AnalyzeSQL

func (c *Connect) AnalyzeSQL(sql string) (prepared string, placeholders int, err error)

func (*Connect) Close

func (c *Connect) Close()

func (*Connect) Connection

func (c *Connect) Connection() (db.Config, *sql.DB)

func (*Connect) CreatePool

func (c *Connect) CreatePool(cfg db.Config) error

func (*Connect) DriverName

func (c *Connect) DriverName() string

func (*Connect) Exec

func (c *Connect) Exec(q db.Query) (db.Result, error)

func (*Connect) ExecCtx

func (c *Connect) ExecCtx(ctx context.Context, q db.Query) (db.Result, error)

func (*Connect) Fork

func (c *Connect) Fork() db.Conn

func (*Connect) LoadFile

func (c *Connect) LoadFile() string

func (*Connect) Query

func (c *Connect) Query(query db.Query, each func(row map[string]any) error) error

func (*Connect) QueryCtx

func (c *Connect) QueryCtx(ctx context.Context, query db.Query, each func(row map[string]any) error) error

func (*Connect) QueryRows

func (c *Connect) QueryRows(ctx context.Context, q db.Query) (mapper.Rows, error)

func (*Connect) SelectSQL

func (c *Connect) SelectSQL(q db.DialectSQL) string

func (*Connect) Settings

func (c *Connect) Settings(identifier string) error

func (*Connect) Transaction

func (c *Connect) Transaction(fn func(tx db.Conn) error) (retErr error)

func (*Connect) TransactionCtx

func (c *Connect) TransactionCtx(ctx context.Context, fn func(tx db.Conn) error) (retErr error)

type Pool

type Pool struct {
	Connect    db.Config
	Connection *sql.DB
	ConfigKey  string
	PoolKey    string
	Refs       int
}

type Result

type Result struct {
	// contains filtered or unexported fields
}

func (Result) LastInsertId

func (r Result) LastInsertId() int64

func (Result) RowsAffected

func (r Result) RowsAffected() int64

Jump to

Keyboard shortcuts

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