mysql

package
v1.2.12 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMySqlDatabase

func NewMySqlDatabase(URI string) (database.IDatabase, error)

NewMySqlDatabase factory method for database

param: URI - represents the database connection string in the format of: mysql://user:password@host:port/database_name?application_name return: IDatabase instance, error

func NewMySqlDatabaseWithMessageBus

func NewMySqlDatabaseWithMessageBus(URI string, bus messaging.IMessageBus) (database.IDatabase, error)

NewMySqlDatabaseWithMessageBus factory method for database with injected message bus

param: URI - represents the database connection string in the format of: postgresql://user:password@host:port/database_name?application_name return: IDatabase instance, error

func NewMySqlStore

func NewMySqlStore(URI string) (database.IDatastore, error)

NewMySqlStore factory method for datastore

param: URI - represents the database connection string in the format of: mysql://user:password@host:port/database_name?application_name return: IDatabase instance, error

Types

type DBConfig

type DBConfig struct {
	Username string
	Password string
	Host     string
	Port     int
	DBName   string
	AppName  string
	Driver   string
}

DBConfig holds the MySQL database configuration

func (*DBConfig) ConnectionString

func (c *DBConfig) ConnectionString() string

ConnectionString returns DNS connection

type MySqlDatabase

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

func (*MySqlDatabase) AdvancedQuery added in v1.2.11

func (dbs *MySqlDatabase) AdvancedQuery(factory EntityFactory) database.IAdvancedQuery

func (*MySqlDatabase) BulkDelete

func (dbs *MySqlDatabase) BulkDelete(factory EntityFactory, entityIDs []string, keys ...string) (affected int64, err error)

BulkDelete Delete multiple entities from the database in a single transaction (all must be of the same type)

param: factory - Entity factory param: entityIDs - List of entities IDs to delete param: keys - Sharding key(s) (for sharded entities and multi-tenant support) return: Number of deleted entities, error

func (*MySqlDatabase) BulkInsert

func (dbs *MySqlDatabase) BulkInsert(entities []Entity) (affected int64, err error)

BulkInsert Insert multiple entities to database in a single transaction (all must be of the same type)

param: entities - List of entities to insert return: Number of inserted entities, error

func (*MySqlDatabase) BulkSetFields

func (dbs *MySqlDatabase) BulkSetFields(factory EntityFactory, field string, values map[string]any, keys ...string) (affected int64, error error)

BulkSetFields Update specific field of multiple entities in a single transaction (eliminates the need to fetch - change - update)

param: factory - Entity factory param: field - The field name to update param: values - The map of entity Id to field value param: keys - Sharding key(s) (for sharded entities and multi-tenant support) return: Number of updated entities, error

func (*MySqlDatabase) BulkUpdate

func (dbs *MySqlDatabase) BulkUpdate(entities []Entity) (affected int64, err error)

BulkUpdate Update multiple entities to database in a single transaction (all must be of the same type)

param: entities - List of entities to update return: Number of updated entities, error

func (*MySqlDatabase) BulkUpsert

func (dbs *MySqlDatabase) BulkUpsert(entities []Entity) (affected int64, err error)

BulkUpsert Upsert multiple entities to database in a single transaction (all must be of the same type)

param: entities - List of entities to upsert return: Number of updated entities, error

func (*MySqlDatabase) CloneDatabase

func (dbs *MySqlDatabase) CloneDatabase() (database.IDatabase, error)

CloneDatabase Returns a clone (copy) of the database instance

func (*MySqlDatabase) CloneDatastore

func (dbs *MySqlDatabase) CloneDatastore() (database.IDatastore, error)

CloneDatastore Returns a clone (copy) of the database instance

func (*MySqlDatabase) Close

func (dbs *MySqlDatabase) Close() error

Close DB and free resources

func (*MySqlDatabase) CreateEntityIndex

func (dbs *MySqlDatabase) CreateEntityIndex(factory EntityFactory, key string) (name string, err error)

CreateEntityIndex creates an index of entity and add entity field mapping

func (*MySqlDatabase) CreateIndex

func (dbs *MySqlDatabase) CreateIndex(indexName string) (name string, err error)

CreateIndex creates an index (without mapping)

func (*MySqlDatabase) Delete

func (dbs *MySqlDatabase) Delete(factory EntityFactory, entityID string, keys ...string) (err error)

Delete entity

param: factory - Entity factory param: entityID - Entity ID to delete param: keys - Sharding key(s) (for sharded entities and multi-tenant support) return: error

func (*MySqlDatabase) DropIndex

func (dbs *MySqlDatabase) DropIndex(indexName string) (ack bool, err error)

DropIndex drops an index

func (*MySqlDatabase) DropTable

func (dbs *MySqlDatabase) DropTable(table string) (err error)

DropTable Drop table and indexes

param: table - Table name to drop return: error

func (*MySqlDatabase) ExecuteDDL

func (dbs *MySqlDatabase) ExecuteDDL(ddl map[string][]string) (err error)

ExecuteDDL create table and indexes

param: ddl - The ddl parameter is a map of strings (table names) to array of strings (list of fields to index) return: error

func (*MySqlDatabase) ExecuteQuery

func (dbs *MySqlDatabase) ExecuteQuery(source, sql string, args ...any) ([]Json, error)

ExecuteQuery Execute native SQL query

func (*MySqlDatabase) ExecuteQueryNew added in v1.2.9

func (dbs *MySqlDatabase) ExecuteQueryNew(source, sql string, args ...any) ([]Json, error)

ExecuteQueryNew Execute native SQL query

func (*MySqlDatabase) ExecuteSQL

func (dbs *MySqlDatabase) ExecuteSQL(sql string, args ...any) (int64, error)

ExecuteSQL Execute SQL command

param: sql - The SQL command to execute param: args - Statement arguments return: Number of affected records, error

func (*MySqlDatabase) Exists

func (dbs *MySqlDatabase) Exists(factory EntityFactory, entityID string, keys ...string) (result bool, err error)

Exists Check if entity exists by ID

param: factory - Entity factory param: entityID - Entity id param: keys - Sharding key(s) (for sharded entities and multi-tenant support) return: bool, error

func (*MySqlDatabase) Get

func (dbs *MySqlDatabase) Get(factory EntityFactory, entityID string, keys ...string) (result Entity, err error)

Get a single entity by ID

param: factory - Entity factory param: entityID - Entity id param: keys - Sharding key(s) (for sharded entities and multi-tenant support) return: Entity, error

func (*MySqlDatabase) IndexExists

func (dbs *MySqlDatabase) IndexExists(indexName string) (exists bool)

IndexExists tests if index exists

func (*MySqlDatabase) Insert

func (dbs *MySqlDatabase) Insert(entity Entity) (added Entity, err error)

Insert new entity

param: entity - The entity to insert return: Inserted Entity, error

func (*MySqlDatabase) List

func (dbs *MySqlDatabase) List(factory EntityFactory, entityIDs []string, keys ...string) (list []Entity, err error)

List Get list of entities by IDs

param: factory - Entity factory param: entityIDs - List of Entity IDs param: keys - Sharding key(s) (for sharded entities and multi-tenant support) return: []Entity, error

func (*MySqlDatabase) ListIndices

func (dbs *MySqlDatabase) ListIndices(pattern string) (map[string]int, error)

ListIndices returns a list of all indices matching the pattern

func (*MySqlDatabase) Ping

func (dbs *MySqlDatabase) Ping(retries uint, intervalInSeconds uint) error

Ping Test database connectivity

param: retries - how many retries are required (max 10) param: intervalInSeconds - time interval (in seconds) between retries (max 60)

func (*MySqlDatabase) PurgeTable

func (dbs *MySqlDatabase) PurgeTable(table string) (err error)

PurgeTable Fast delete table content (truncate)

param: table - Table name to purge return: error

func (*MySqlDatabase) Query

func (dbs *MySqlDatabase) Query(factory EntityFactory) database.IQuery

Query Helper method to construct query

param: factory - Entity factory return: Query object

func (*MySqlDatabase) SetField

func (dbs *MySqlDatabase) SetField(factory EntityFactory, entityID string, field string, value any, keys ...string) (err error)

SetField Update a single field of the document in a single transaction

param: factory - Entity factory param: entityID - The entity ID to update the field param: field - The field name to update param: value - The field value to update param: keys - Sharding key(s) (for sharded entities and multi-tenant support) return: error

func (*MySqlDatabase) SetFields

func (dbs *MySqlDatabase) SetFields(factory EntityFactory, entityID string, fields map[string]any, keys ...string) (err error)

SetFields Update some fields of the document in a single transaction

param: factory - Entity factory param: entityID - The entity ID to update the field param: fields - A map of field-value pairs to update param: keys - Sharding key(s) (for sharded entities and multi-tenant support) return: error

func (*MySqlDatabase) Update

func (dbs *MySqlDatabase) Update(entity Entity) (updated Entity, err error)

Update existing entity

param: entity - The entity to update return: Updated Entity, error

func (*MySqlDatabase) Upsert

func (dbs *MySqlDatabase) Upsert(entity Entity) (updated Entity, err error)

Upsert Update entity or insert it if it does not exist

param: entity - The entity to update return: Updated Entity, error

type SSHConfig

type SSHConfig struct {
	Username string
	Password string
	Host     string
	Port     int
	KeyFile  string
}

SSHConfig holds the SSH configuration

Jump to

Keyboard shortcuts

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