mysql

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMySQLMigrator

func NewMySQLMigrator(db *sql.DB, mysqlDB *MySQLDB) types.DatabaseMigrator

NewMySQLMigrator creates a new MySQL migrator that implements types.DatabaseMigrator

func NewMySQLRawQuery

func NewMySQLRawQuery(db *sql.DB, sql string, args ...any) types.RawQuery

NewMySQLRawQuery creates a new MySQL raw query

func NewMySQLTransaction

func NewMySQLTransaction(tx *sql.Tx, database *MySQLDB) types.Transaction

NewMySQLTransaction creates a new MySQL transaction

Types

type MySQLCapabilities

type MySQLCapabilities struct{}

MySQLCapabilities implements types.DriverCapabilities for MySQL

func NewMySQLCapabilities

func NewMySQLCapabilities() *MySQLCapabilities

NewMySQLCapabilities creates new MySQL capabilities

func (*MySQLCapabilities) GetBooleanLiteral

func (c *MySQLCapabilities) GetBooleanLiteral(value bool) string

func (*MySQLCapabilities) GetDriverType

func (c *MySQLCapabilities) GetDriverType() types.DriverType

func (*MySQLCapabilities) GetNullsOrderingSQL

func (c *MySQLCapabilities) GetNullsOrderingSQL(direction types.Order, nullsFirst bool) string

func (*MySQLCapabilities) GetPlaceholder

func (c *MySQLCapabilities) GetPlaceholder(index int) string

func (*MySQLCapabilities) GetSupportedSchemes

func (c *MySQLCapabilities) GetSupportedSchemes() []string

func (*MySQLCapabilities) IsNoSQL

func (c *MySQLCapabilities) IsNoSQL() bool

func (*MySQLCapabilities) IsSystemIndex

func (c *MySQLCapabilities) IsSystemIndex(indexName string) bool

func (*MySQLCapabilities) IsSystemTable

func (c *MySQLCapabilities) IsSystemTable(tableName string) bool

func (*MySQLCapabilities) NeedsTypeConversion

func (c *MySQLCapabilities) NeedsTypeConversion() bool

func (*MySQLCapabilities) QuoteIdentifier

func (c *MySQLCapabilities) QuoteIdentifier(name string) string

func (*MySQLCapabilities) RequiresLimitForOffset

func (c *MySQLCapabilities) RequiresLimitForOffset() bool

func (*MySQLCapabilities) SupportsAggregationPipeline

func (c *MySQLCapabilities) SupportsAggregationPipeline() bool

func (*MySQLCapabilities) SupportsArrayFields

func (c *MySQLCapabilities) SupportsArrayFields() bool

func (*MySQLCapabilities) SupportsDefaultValues

func (c *MySQLCapabilities) SupportsDefaultValues() bool

func (*MySQLCapabilities) SupportsDistinctOn

func (c *MySQLCapabilities) SupportsDistinctOn() bool

func (*MySQLCapabilities) SupportsNestedDocuments

func (c *MySQLCapabilities) SupportsNestedDocuments() bool

func (*MySQLCapabilities) SupportsReturning

func (c *MySQLCapabilities) SupportsReturning() bool

func (*MySQLCapabilities) SupportsTransactions

func (c *MySQLCapabilities) SupportsTransactions() bool

type MySQLDB

type MySQLDB struct {
	*base.Driver
	// contains filtered or unexported fields
}

MySQLDB implements the Database interface for MySQL

func NewMySQLDB

func NewMySQLDB(nativeURI string) (*MySQLDB, error)

NewMySQLDB creates a new MySQL database instance The uri parameter should be a native MySQL DSN (e.g., "user:pass@tcp(host:port)/db")

func (*MySQLDB) Begin

func (m *MySQLDB) Begin(ctx context.Context) (types.Transaction, error)

Begin starts a new transaction

func (*MySQLDB) Connect

func (m *MySQLDB) Connect(ctx context.Context) error

Connect establishes connection to MySQL database

func (*MySQLDB) CreateModel

func (m *MySQLDB) CreateModel(ctx context.Context, modelName string) error

CreateModel creates a table for the given model

func (*MySQLDB) DropModel

func (m *MySQLDB) DropModel(ctx context.Context, modelName string) error

DropModel drops the table for the given model

func (*MySQLDB) Exec

func (m *MySQLDB) Exec(query string, args ...any) (sql.Result, error)

Exec executes a raw SQL statement

func (*MySQLDB) GetCapabilities

func (m *MySQLDB) GetCapabilities() types.DriverCapabilities

GetCapabilities returns driver capabilities

func (*MySQLDB) GetDriverType

func (m *MySQLDB) GetDriverType() string

GetMigrator returns a migrator for MySQL GetDriverType returns the database driver type

func (*MySQLDB) GetMigrator

func (m *MySQLDB) GetMigrator() types.DatabaseMigrator

func (*MySQLDB) Model

func (m *MySQLDB) Model(modelName string) types.ModelQuery

Model creates a new model query

func (*MySQLDB) Query

func (m *MySQLDB) Query(query string, args ...any) (*sql.Rows, error)

Query executes a raw SQL query that returns rows

func (*MySQLDB) QueryRow

func (m *MySQLDB) QueryRow(query string, args ...any) *sql.Row

QueryRow executes a raw SQL query that returns a single row

func (*MySQLDB) Raw

func (m *MySQLDB) Raw(sql string, args ...any) types.RawQuery

Raw creates a new raw query

func (*MySQLDB) SyncSchemas

func (m *MySQLDB) SyncSchemas(ctx context.Context) error

SyncSchemas synchronizes all loaded schemas with the database

func (*MySQLDB) Transaction

func (m *MySQLDB) Transaction(ctx context.Context, fn func(tx types.Transaction) error) error

Transaction executes a function within a transaction

type MySQLMigrator

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

MySQLMigrator implements types.DatabaseSpecificMigrator for MySQL

func (*MySQLMigrator) ApplyMigration

func (m *MySQLMigrator) ApplyMigration(sql string) error

ApplyMigration executes a migration SQL

func (*MySQLMigrator) ConvertFieldToColumnInfo

func (m *MySQLMigrator) ConvertFieldToColumnInfo(field schema.Field) *types.ColumnInfo

ConvertFieldToColumnInfo converts a schema field to column info

func (*MySQLMigrator) FormatDefaultValue

func (m *MySQLMigrator) FormatDefaultValue(value any) string

FormatDefaultValue formats a default value for MySQL

func (*MySQLMigrator) GenerateAddColumnSQL

func (m *MySQLMigrator) GenerateAddColumnSQL(tableName string, field any) (string, error)

GenerateAddColumnSQL generates ADD COLUMN SQL

func (*MySQLMigrator) GenerateColumnDefinitionFromColumnInfo

func (m *MySQLMigrator) GenerateColumnDefinitionFromColumnInfo(col types.ColumnInfo) string

GenerateColumnDefinitionFromColumnInfo generates column definition from ColumnInfo

func (*MySQLMigrator) GenerateCreateIndexSQL

func (m *MySQLMigrator) GenerateCreateIndexSQL(tableName, indexName string, columns []string, unique bool) string

GenerateCreateIndexSQL generates CREATE INDEX SQL

func (*MySQLMigrator) GenerateCreateTableSQL

func (m *MySQLMigrator) GenerateCreateTableSQL(s *schema.Schema) (string, error)

GenerateCreateTableSQL generates CREATE TABLE SQL from schema

func (*MySQLMigrator) GenerateDropColumnSQL

func (m *MySQLMigrator) GenerateDropColumnSQL(tableName, columnName string) ([]string, error)

GenerateDropColumnSQL generates DROP COLUMN SQL

func (*MySQLMigrator) GenerateDropIndexSQL

func (m *MySQLMigrator) GenerateDropIndexSQL(indexName string) string

GenerateDropIndexSQL generates DROP INDEX SQL

func (*MySQLMigrator) GenerateDropTableSQL

func (m *MySQLMigrator) GenerateDropTableSQL(tableName string) string

GenerateDropTableSQL generates DROP TABLE SQL

func (*MySQLMigrator) GenerateModifyColumnSQL

func (m *MySQLMigrator) GenerateModifyColumnSQL(change types.ColumnChange) ([]string, error)

GenerateModifyColumnSQL generates MODIFY COLUMN SQL

func (*MySQLMigrator) GetDatabaseType

func (m *MySQLMigrator) GetDatabaseType() string

GetDatabaseType returns the database type

func (*MySQLMigrator) GetTableInfo

func (m *MySQLMigrator) GetTableInfo(tableName string) (*types.TableInfo, error)

GetTableInfo returns table information

func (*MySQLMigrator) GetTables

func (m *MySQLMigrator) GetTables() ([]string, error)

GetTables returns all table names

func (*MySQLMigrator) IsSystemIndex

func (m *MySQLMigrator) IsSystemIndex(indexName string) bool

IsSystemIndex checks if an index is a system-generated index in MySQL

func (*MySQLMigrator) IsSystemTable

func (m *MySQLMigrator) IsSystemTable(tableName string) bool

IsSystemTable checks if a table is a system table in MySQL

func (*MySQLMigrator) MapFieldType

func (m *MySQLMigrator) MapFieldType(field schema.Field) string

MapFieldType maps schema field types to MySQL types

type MySQLMigratorWrapper

type MySQLMigratorWrapper struct {
	*base.BaseMigrator
	// contains filtered or unexported fields
}

MySQLMigratorWrapper wraps MySQLMigrator with BaseMigrator to implement types.DatabaseMigrator

func (*MySQLMigratorWrapper) CompareSchema

func (w *MySQLMigratorWrapper) CompareSchema(existingTable *types.TableInfo, desiredSchema any) (*types.MigrationPlan, error)

CompareSchema wraps the BaseMigrator's CompareSchema to match the DatabaseMigrator interface

func (*MySQLMigratorWrapper) GenerateAddColumnSQL

func (w *MySQLMigratorWrapper) GenerateAddColumnSQL(tableName string, field any) (string, error)

GenerateAddColumnSQL wraps to match the DatabaseMigrator interface

func (*MySQLMigratorWrapper) GenerateCreateTableSQL

func (w *MySQLMigratorWrapper) GenerateCreateTableSQL(schemaInterface any) (string, error)

GenerateCreateTableSQL wraps to match the DatabaseMigrator interface

func (*MySQLMigratorWrapper) IsSystemTable

func (w *MySQLMigratorWrapper) IsSystemTable(tableName string) bool

IsSystemTable delegates to the specific implementation

type MySQLRawQuery

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

MySQLRawQuery implements types.RawQuery for MySQL

func (*MySQLRawQuery) Exec

func (q *MySQLRawQuery) Exec(ctx context.Context) (types.Result, error)

Exec executes the query and returns the result

func (*MySQLRawQuery) Find

func (q *MySQLRawQuery) Find(ctx context.Context, dest any) error

Find executes the query and scans results into dest

func (*MySQLRawQuery) FindOne

func (q *MySQLRawQuery) FindOne(ctx context.Context, dest any) error

FindOne executes the query and scans a single result into dest

type MySQLTransaction

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

MySQLTransaction implements types.Transaction for MySQL

func (*MySQLTransaction) Commit

func (t *MySQLTransaction) Commit(ctx context.Context) error

Commit commits the transaction

func (*MySQLTransaction) CreateMany

func (t *MySQLTransaction) CreateMany(ctx context.Context, modelName string, data []any) (types.Result, error)

CreateMany creates multiple records within the transaction

func (*MySQLTransaction) DeleteMany

func (t *MySQLTransaction) DeleteMany(ctx context.Context, modelName string, condition types.Condition) (types.Result, error)

DeleteMany deletes multiple records within the transaction

func (*MySQLTransaction) Model

func (t *MySQLTransaction) Model(modelName string) types.ModelQuery

Model creates a new model query within the transaction

func (*MySQLTransaction) Raw

func (t *MySQLTransaction) Raw(sql string, args ...any) types.RawQuery

Raw creates a new raw query within the transaction

func (*MySQLTransaction) Rollback

func (t *MySQLTransaction) Rollback(ctx context.Context) error

Rollback rolls back the transaction

func (*MySQLTransaction) RollbackTo

func (t *MySQLTransaction) RollbackTo(ctx context.Context, name string) error

RollbackTo rolls back to a specific savepoint

func (*MySQLTransaction) Savepoint

func (t *MySQLTransaction) Savepoint(ctx context.Context, name string) error

Savepoint creates a new savepoint

func (*MySQLTransaction) UpdateMany

func (t *MySQLTransaction) UpdateMany(ctx context.Context, modelName string, condition types.Condition, data any) (types.Result, error)

UpdateMany updates multiple records within the transaction

type MySQLTransactionDB

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

MySQLTransactionDB implements types.Database for use within a transaction

func (*MySQLTransactionDB) Begin

Begin - not supported in transaction

func (*MySQLTransactionDB) Close

func (tdb *MySQLTransactionDB) Close() error

Close - not supported in transaction

func (*MySQLTransactionDB) Connect

func (tdb *MySQLTransactionDB) Connect(ctx context.Context) error

Connect - not supported in transaction

func (*MySQLTransactionDB) CreateModel

func (tdb *MySQLTransactionDB) CreateModel(ctx context.Context, modelName string) error

CreateModel - not supported in transaction

func (*MySQLTransactionDB) DropModel

func (tdb *MySQLTransactionDB) DropModel(ctx context.Context, modelName string) error

DropModel - not supported in transaction

func (*MySQLTransactionDB) Exec

func (tdb *MySQLTransactionDB) Exec(query string, args ...any) (sql.Result, error)

Exec executes a query within the transaction

func (*MySQLTransactionDB) GetCapabilities

func (tdb *MySQLTransactionDB) GetCapabilities() types.DriverCapabilities

GetCapabilities delegates to the main database

func (*MySQLTransactionDB) GetDriverType

func (tdb *MySQLTransactionDB) GetDriverType() string

GetDriverType delegates to the main database

func (*MySQLTransactionDB) GetFieldMapper

func (tdb *MySQLTransactionDB) GetFieldMapper() types.FieldMapper

GetFieldMapper delegates to the main database

func (*MySQLTransactionDB) GetMigrator

func (tdb *MySQLTransactionDB) GetMigrator() types.DatabaseMigrator

GetMigrator delegates to the main database

func (*MySQLTransactionDB) GetModelSchema

func (tdb *MySQLTransactionDB) GetModelSchema(modelName string) (*schema.Schema, error)

GetModelSchema delegates to the main database

func (*MySQLTransactionDB) GetModels

func (tdb *MySQLTransactionDB) GetModels() []string

GetModels delegates to the main database

func (*MySQLTransactionDB) GetSchema

func (tdb *MySQLTransactionDB) GetSchema(modelName string) (*schema.Schema, error)

GetSchema delegates to the main database

func (*MySQLTransactionDB) LoadSchema

func (tdb *MySQLTransactionDB) LoadSchema(ctx context.Context, schemaContent string) error

LoadSchema is not supported within a transaction

func (*MySQLTransactionDB) LoadSchemaFrom

func (tdb *MySQLTransactionDB) LoadSchemaFrom(ctx context.Context, filename string) error

LoadSchemaFrom is not supported within a transaction

func (*MySQLTransactionDB) Model

func (tdb *MySQLTransactionDB) Model(modelName string) types.ModelQuery

Model creates a model query that uses the transaction

func (*MySQLTransactionDB) Ping

func (tdb *MySQLTransactionDB) Ping(ctx context.Context) error

Ping delegates to the main database

func (*MySQLTransactionDB) Query

func (tdb *MySQLTransactionDB) Query(query string, args ...any) (*sql.Rows, error)

Query executes a query within the transaction

func (*MySQLTransactionDB) QueryRow

func (tdb *MySQLTransactionDB) QueryRow(query string, args ...any) *sql.Row

QueryRow executes a query within the transaction

func (*MySQLTransactionDB) Raw

func (tdb *MySQLTransactionDB) Raw(sql string, args ...any) types.RawQuery

Raw creates a raw query that uses the transaction

func (*MySQLTransactionDB) RegisterSchema

func (tdb *MySQLTransactionDB) RegisterSchema(modelName string, s *schema.Schema) error

RegisterSchema delegates to the main database

func (*MySQLTransactionDB) ResolveFieldName

func (tdb *MySQLTransactionDB) ResolveFieldName(modelName, fieldName string) (string, error)

ResolveFieldName delegates to the main database

func (*MySQLTransactionDB) ResolveFieldNames

func (tdb *MySQLTransactionDB) ResolveFieldNames(modelName string, fieldNames []string) ([]string, error)

ResolveFieldNames delegates to the main database

func (*MySQLTransactionDB) ResolveTableName

func (tdb *MySQLTransactionDB) ResolveTableName(modelName string) (string, error)

ResolveTableName delegates to the main database

func (*MySQLTransactionDB) SyncSchemas

func (tdb *MySQLTransactionDB) SyncSchemas(ctx context.Context) error

SyncSchemas is not supported within a transaction

func (*MySQLTransactionDB) Transaction

func (tdb *MySQLTransactionDB) Transaction(ctx context.Context, fn func(tx types.Transaction) error) error

Transaction - not supported in transaction

type MySQLTransactionRawQuery

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

MySQLTransactionRawQuery implements RawQuery for MySQL transactions

func (*MySQLTransactionRawQuery) Exec

Exec executes the query within a transaction

func (*MySQLTransactionRawQuery) Find

func (q *MySQLTransactionRawQuery) Find(ctx context.Context, dest any) error

Find executes the query and scans results into dest within a transaction

func (*MySQLTransactionRawQuery) FindOne

func (q *MySQLTransactionRawQuery) FindOne(ctx context.Context, dest any) error

FindOne executes the query and scans a single result into dest within a transaction

type MySQLURIParser

type MySQLURIParser struct{}

MySQLURIParser implements URIParser for MySQL databases

func NewMySQLURIParser

func NewMySQLURIParser() *MySQLURIParser

NewMySQLURIParser creates a new MySQL URI parser

func (*MySQLURIParser) GetDriverType

func (p *MySQLURIParser) GetDriverType() string

GetDriverType returns the driver type this parser is for

func (*MySQLURIParser) GetSupportedSchemes

func (p *MySQLURIParser) GetSupportedSchemes() []string

GetSupportedSchemes returns the URI schemes this parser supports

func (*MySQLURIParser) ParseURI

func (p *MySQLURIParser) ParseURI(uri string) (string, error)

ParseURI parses a MySQL URI and returns a MySQL DSN Supported formats:

  • mysql://user:password@host:port/database
  • mysql://user:password@host/database (default port 3306)
  • mysql://user@host/database (no password)
  • mysql://host/database (no auth)

Jump to

Keyboard shortcuts

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