mysql

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package mysql provides MySQL database connection and operation wrapper.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DB

func DB() (*sql.DB, error)

DB returns the MySQL database connection and any initialization error.

func New

func New() result.Result[*Table]

New creates a new Table instance.

func Refresh

func Refresh()

Refresh initializes or reconnects the MySQL database.

func SetDBForTest added in v1.4.0

func SetDBForTest(d *sql.DB) func()

SetDBForTest injects db for testing. Returns a cleanup that restores the previous db and err.

Types

type Table added in v1.4.0

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

Table holds SQL conversion state for MySQL output.

func (*Table) AddColumn added in v1.4.0

func (t *Table) AddColumn(names ...string) *Table

AddColumn adds one or more column definitions to the table.

func (*Table) AutoInsert added in v1.4.0

func (t *Table) AutoInsert(value []string) *Table

AutoInsert adds a row for insert, flushing automatically when buffer is full or size limit is reached.

func (*Table) Clone added in v1.4.0

func (m *Table) Clone() *Table

Clone returns a copy of the Table with the same table name, columns, and primary key settings.

func (*Table) Create added in v1.4.0

func (t *Table) Create() (r result.VoidResult)

Create generates and executes a CREATE TABLE statement. Requires prior SetTableName() and AddColumn().

func (*Table) CustomPrimaryKey added in v1.4.0

func (t *Table) CustomPrimaryKey(primaryKeyCode string) *Table

CustomPrimaryKey sets a custom primary key definition (optional).

func (*Table) FlushInsert added in v1.4.0

func (t *Table) FlushInsert() (r result.VoidResult)

FlushInsert executes the buffered INSERT. Create and AutoInsert must be called first.

func (*Table) SelectAll added in v1.4.0

func (t *Table) SelectAll() result.Result[*sql.Rows]

SelectAll returns all rows from the table. SetTableName must be called first.

func (*Table) SetTableName added in v1.4.0

func (t *Table) SetTableName(name string) *Table

SetTableName sets the table name for the Table.

func (*Table) Truncate added in v1.4.0

func (t *Table) Truncate() (r result.VoidResult)

Truncate empties the table. Requires prior SetTableName().

Jump to

Keyboard shortcuts

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