mysql

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package mysql implements the Dialect of mysql database, supporting the corresponding database of mysql 5.7+

Index

Constants

View Source
const WriteModeReplace = "replace"

WriteModeReplace represents the replace into write mode.

Variables

This section is empty.

Functions

func NewSource

func NewSource(bs *database.BaseSource) (s database.Source, err error)

NewSource generates a MySQL data source and will report an error if there's an issue with the configuration file

func Quoted

func Quoted(s string) string

Quoted is the quoting function for MySQL

Types

type Config

type Config struct {
	URL      string `json:"url"`      // Database URL, including the database address and other database parameters
	Username string `json:"username"` // Username
	Password string `json:"password"` // Password
}

Config is the MySQL configuration, and the reading time needs to be parsed, i.e., parseTime=true

func NewConfig

func NewConfig(conf *config.JSON) (c *Config, err error)

NewConfig creates a MySQL configuration and will report an error if the format does not meet the requirements

func (*Config) FetchMysqlConfig

func (c *Config) FetchMysqlConfig() (conf *mysql.Config, err error)

FetchMysqlConfig retrieves the generated MySQL connection configuration, and will report an error if the URL is incorrect

type Dialect

type Dialect struct{}

Dialect represents the database dialect for MySQL

func (Dialect) Name

func (d Dialect) Name() string

Name is the registered name of the database dialect

func (Dialect) Source

func (d Dialect) Source(bs *database.BaseSource) (database.Source, error)

Source refers to the production data source

type Field

type Field struct {
	*database.BaseField
	database.BaseConfigSetter
}

Field Field

func NewField

func NewField(bf *database.BaseField) *Field

NewField Generate a field based on basic column attributes

func (*Field) BindVar

func (f *Field) BindVar(_ int) string

BindVar SQL placeholder, used in SQL statements

func (*Field) Quoted

func (f *Field) Quoted() string

Quoted Quotation, used in SQL statements

func (*Field) Scanner

func (f *Field) Scanner() database.Scanner

Scanner Scanner, used for reading data

func (*Field) Select

func (f *Field) Select() string

Select Field for querying, used in SQL query statements

func (*Field) Type

func (f *Field) Type() database.FieldType

Type Field type

func (*Field) Valuer

func (f *Field) Valuer(c element.Column) database.Valuer

Valuer Valuer, using GoValuer to process data

type FieldType

type FieldType struct {
	*database.BaseFieldType
	// contains filtered or unexported fields
}

FieldType Field type

func NewFieldType

func NewFieldType(typ database.ColumnType) *FieldType

NewFieldType Create a new field type

func (*FieldType) GoType

func (f *FieldType) GoType() database.GoType

GoType Returns the Golang type when processing numeric values

func (*FieldType) IsSupported added in v0.1.8

func (f *FieldType) IsSupported() bool

IsSupported Whether it supports parsing

type ReplaceParam

type ReplaceParam struct {
	*database.BaseParam
}

ReplaceParam represents the parameters for the replace into operation.

func NewReplaceParam

func NewReplaceParam(t database.Table, txOpts *sql.TxOptions) *ReplaceParam

NewReplaceParam creates replace parameters based on the table and transaction options (txOpts).

func (*ReplaceParam) Agrs

func (rp *ReplaceParam) Agrs(records []element.Record) (valuers []interface{}, err error)

Agrs generates a batch of replace into parameters based on multiple records.

func (*ReplaceParam) Query

func (rp *ReplaceParam) Query(records []element.Record) (query string, err error)

Query generates a batch of replace into SQL statements for insertion based on multiple records.

type Scanner

type Scanner struct {
	database.BaseScanner
	// contains filtered or unexported fields
}

Scanner Scanner

func NewScanner

func NewScanner(f *Field) *Scanner

NewScanner Generate a scanner based on the column type

func (*Scanner) Scan

func (s *Scanner) Scan(src interface{}) (err error)

Scan Read data based on the column type MEDIUMINT, INT, BIGINT, SMALLINT, TINYINT, YEAR, UNSIGNED INT, UNSIGNED BIGINT, UNSIGNED SMALLINT, UNSIGNED TINYINT are treated as integers. DOUBLE, FLOAT, DECIMAL are treated as high-precision real numbers. DATE, DATETIME, TIMESTAMP are treated as time. TEXT, LONGTEXT, MEDIUMTEXT, TINYTEXT, CHAR, VARCHAR, TIME are treated as strings. BLOB, LONGBLOB, MEDIUMBLOB, BINARY, TINYBLOB, VARBINARY are treated as byte streams.

type Source

type Source struct {
	*database.BaseSource // Basic data source
	// contains filtered or unexported fields
}

Source mysql represents the MySQL data source

func (*Source) ConnectName

func (s *Source) ConnectName() string

ConnectName is the connection information for the MySQL data source using github.com/go-sql-driver/mysql

func (*Source) Connector

func (s *Source) Connector() (driver.Connector, error)

Connector is the data source connector for github.com/go-sql-driver/mysql

func (*Source) DriverName

func (s *Source) DriverName() string

DriverName is the driver name for github.com/go-sql-driver/mysql

func (*Source) Key

func (s *Source) Key() string

Key is a keyword for the data source, used for reuse by DBWrapper

func (*Source) Table

func (s *Source) Table(b *database.BaseTable) database.Table

Table generates a table for MySQL

type Table

type Table struct {
	*database.BaseTable
	database.BaseConfigSetter
}

Table represents a MySQL table.

func NewTable

func NewTable(b *database.BaseTable) *Table

NewTable creates a new MySQL table. Note that at this point, the schema parameter in BaseTable is empty, instance is the database name, and name is the table name.

func (*Table) AddField

func (t *Table) AddField(baseField *database.BaseField)

AddField adds a new column to the table.

func (*Table) ExecParam

func (t *Table) ExecParam(mode string, txOpts *sql.TxOptions) (database.Parameter, bool)

ExecParam retrieves execution parameters, where the replace into parameter mode has been registered.

func (*Table) Quoted

func (t *Table) Quoted() string

Quoted refers to the fully qualified name of the table.

func (*Table) ShouldOneByOne

func (t *Table) ShouldOneByOne(err error) bool

ShouldOneByOne specifies whether to retry one operation at a time.

func (*Table) ShouldRetry

func (t *Table) ShouldRetry(err error) bool

ShouldRetry determines whether a retry is necessary.

func (*Table) String

func (t *Table) String() string

Jump to

Keyboard shortcuts

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