r3mysql

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package r3mysql is a raw-SQL r3.CRUD[T, ID] driver backed by go-sql-driver/mysql (github.com/go-sql-driver/mysql) over database/sql.

It builds SQL by reflection and scans into structs tagged `db:"col,pk"`; no ORM, so no preloads and no soft-delete (IncludeTrashed, Restore, HardDelete are unavailable). Table names derive from the struct name (CamelCase -> snake_case, pluralized); nullable columns need pointer fields. Transactions via r3.Transactor; reach the *sql.DB through Raw().DB for CTEs and the like.

MySQL-specific notes:

  • No RETURNING: Create uses INSERT + LAST_INSERT_ID() + SELECT to return the full row including auto-generated columns.
  • No ILIKE (use LIKE; case sensitivity follows the column collation, and the default utf8mb4_0900_ai_ci is case-insensitive) and no NULLS FIRST/LAST.
  • The DSN must set `parseTime=true` for time.Time scanning.

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 builds a read-only repository (r3.Querier enforces it).

Types

type MysqlCRUD

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

MysqlCRUD is a go-sql-driver/mysql repository; enginesql.BaseCRUD supplies the r3.CRUD impl. Create goes through BaseCRUD's LAST_INSERT_ID fallback, since FlavorMySQL reports SupportsRETURNING=false.

func NewMysqlCRUD

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

NewMysqlCRUD builds a repository. Map columns with `db:"column_name"` and mark the PK with `db:"id,pk"` (defaults to "id").

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 wraps enginesql.BaseRaw.

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