r3mysql

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package r3mysql provides an r3.CRUD[T, ID] driver backed by go-sql-driver/mysql, the pure Go MySQL driver for database/sql.

Driver: github.com/go-sql-driver/mysql Source: https://github.com/go-sql-driver/mysql

Supported r3 features:

  • Full CRUD (Create, Get, List, Update, Delete)
  • Filters, Sorts, Pagination via the r3 SQL dialect
  • Thread-safe default queries (SetDefaultListQuery, SetDefaultGetQuery)
  • Raw escape hatch (BaseRaw) for arbitrary SQL with ?-style placeholders

Limitations / notes:

  • No ORM layer: this driver builds raw SQL and uses reflection-based struct scanning. Model structs must use `db` struct tags (e.g. `db:"column_name,pk"`).
  • No preload support. Relations (joins, eager loading) must be done via Raw().
  • No soft-delete support. IncludeTrashed is ignored. Restore/HardDelete not available.
  • Table names are derived automatically from struct name (CamelCase -> snake_case + plural).
  • Nullable columns require pointer types (e.g. *string, *int64) in the model struct.
  • Uses `?` placeholders natively (no conversion needed).
  • MySQL does not support RETURNING; Create uses INSERT + LAST_INSERT_ID() + SELECT to return the full created entity including auto-generated columns.
  • ILIKE is not supported by MySQL; use LIKE instead (case sensitivity depends on column collation; default utf8mb4_0900_ai_ci is case-insensitive).
  • NULLS FIRST/LAST is not natively supported by MySQL.
  • DSN must include `parseTime=true` for time.Time scanning to work correctly.
  • Transactions are supported via the r3.Transactor interface (BeginTx).
  • For advanced use cases (CTEs, etc.), use Raw().DB to access the underlying *sql.DB directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMysqlQuerier

func NewMysqlQuerier[T any, ID comparable](db *sql.DB, opts ...r3.Option) r3.Querier[T, ID]

NewMysqlQuerier creates a read-only MySQL-based repository. Returns r3.Querier — a compile-time guarantee of read-only access.

Types

type MysqlCRUD

type MysqlCRUD[T any, ID comparable] struct {
	*enginesql.BaseCRUD[T, ID]
}

MysqlCRUD is a CRUD repository based on database/sql with go-sql-driver/mysql. It embeds enginesql.BaseCRUD which provides the full r3.CRUD implementation. Create() is handled by BaseCRUD's LAST_INSERT_ID fallback (FlavorMySQL has SupportsRETURNING=false).

func NewMysqlCRUD

func NewMysqlCRUD[T any, ID comparable](db *sql.DB, opts ...r3.Option) *MysqlCRUD[T, ID]

NewMysqlCRUD creates a new MySQL-based CRUD repository. Models should use `db:"column_name"` struct tags for column mapping. The primary key field should be tagged with `db:"id,pk"` (defaults to "id").

Accepts optional r3.Option values for framework-level configuration.

func (*MysqlCRUD[T, ID]) DB

func (r *MysqlCRUD[T, ID]) DB() *sql.DB

DB returns the underlying *sql.DB for advanced usage.

func (*MysqlCRUD[T, ID]) Raw

func (r *MysqlCRUD[T, ID]) Raw() *enginesql.BaseRaw[T, ID]

Raw returns the BaseRaw escape hatch for custom queries.

type MysqlRaw deprecated

type MysqlRaw[T any, ID any] struct {
	*enginesql.BaseRaw[T, ID]
}

MysqlRaw is a thin wrapper around enginesql.BaseRaw for backward compatibility.

Deprecated: Use enginesql.BaseRaw directly via MysqlCRUD.Raw().

func NewMysqlRaw

func NewMysqlRaw[T any, ID comparable](db *sql.DB) *MysqlRaw[T, ID]

NewMysqlRaw creates a new MysqlRaw instance.

func (*MysqlRaw[T, ID]) DB

func (r *MysqlRaw[T, ID]) DB() *sql.DB

DB returns the underlying *sql.DB for fully custom usage.

func (*MysqlRaw[T, ID]) Exec

func (r *MysqlRaw[T, ID]) Exec(ctx context.Context, query string, args ...any) (sql.Result, error)

Exec executes a raw SQL query that does not return rows.

func (*MysqlRaw[T, ID]) Query

func (r *MysqlRaw[T, ID]) Query(ctx context.Context, query string, args ...any) ([]T, error)

Query executes a raw SQL query and scans results into a slice of T.

func (*MysqlRaw[T, ID]) QueryRow

func (r *MysqlRaw[T, ID]) QueryRow(ctx context.Context, query string, args ...any) (T, error)

QueryRow executes a raw SQL query expected to return a single row and scans it into T.

Jump to

Keyboard shortcuts

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