Documentation
¶
Overview ¶
Package mysql provides MySQL database connection and operation wrapper.
Index ¶
- func DB() (*sql.DB, error)
- func New() result.Result[*Table]
- func Refresh()
- func SetDBForTest(d *sql.DB) func()
- type Table
- func (t *Table) AddColumn(names ...string) *Table
- func (t *Table) AutoInsert(value []string) *Table
- func (m *Table) Clone() *Table
- func (t *Table) Create() (r result.VoidResult)
- func (t *Table) CustomPrimaryKey(primaryKeyCode string) *Table
- func (t *Table) FlushInsert() (r result.VoidResult)
- func (t *Table) SelectAll() result.Result[*sql.Rows]
- func (t *Table) SetTableName(name string) *Table
- func (t *Table) Truncate() (r result.VoidResult)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetDBForTest ¶ added in v1.4.0
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
AddColumn adds one or more column definitions to the table.
func (*Table) AutoInsert ¶ added in v1.4.0
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
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
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
SelectAll returns all rows from the table. SetTableName must be called first.
func (*Table) SetTableName ¶ added in v1.4.0
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().