mysql

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README ΒΆ

Compogo MySQL 🐬

Compogo MySQL β€” это ΠΏΠΎΠ»Π½ΠΎΡ†Π΅Π½Π½Ρ‹ΠΉ MySQL-Π΄Ρ€Π°ΠΉΠ²Π΅Ρ€ для экосистСмы Compogo. Π’ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ ΠΊΠ»ΠΈΠ΅Π½Ρ‚ с автоматичСской Π·Π°Ρ‰ΠΈΡ‚ΠΎΠΉ ΠΎΡ‚ сбоСв, ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΡƒ ΠΌΠΈΠ³Ρ€Π°Ρ†ΠΈΠΉ, Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ SQL-запросов ΠΈ Π³ΠΎΡ‚ΠΎΠ²Ρ‹Π΅ рСгистрации для всСх ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ΠΎΠ².

πŸš€ Установка

go get github.com/Compogo/mysql
πŸ“¦ Быстрый старт (ΠΎΠ΄Π½Π° Π‘Π”, всё автоматичСски)
package main

import (
    "github.com/Compogo/compogo"
    "github.com/Compogo/db-client"
    "github.com/Compogo/db-migrator"
    "github.com/Compogo/db-sql-generator"
    "github.com/Compogo/mysql"
    "github.com/Compogo/mysql/registration/all"
)

func main() {
    app := compogo.NewApp("myapp",
        compogo.WithOsSignalCloser(),
        db_client.Component,
        db_migrator.Component,
        db_sql_generator.Component,
        mysql.Component,
        all.Component,  // ← магия: всё настраиваСтся само
        compogo.WithComponents(
            userRepositoryComponent,
        ),
    )

    if err := app.Serve(); err != nil {
        panic(err)
    }
}

// Π Π΅ΠΏΠΎΠ·ΠΈΡ‚ΠΎΡ€ΠΈΠΉ Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ с ΠΎΠ±Ρ‰ΠΈΠΌ интСрфСйсом
var userRepositoryComponent = &component.Component{
    Dependencies: component.Components{db_client.Component},
    Execute: component.StepFunc(func(c container.Container) error {
        return c.Invoke(func(db db_client.Client) {
            repo := &UserRepository{db: db}
            // ...
        })
    }),
}

Запуск:

./myapp --db.driver=mysql --db.mysql.dsn="user:pass@tcp(localhost:3306)/db"
✨ ВозмоТности
πŸ›‘οΈ ΠšΠ»ΠΈΠ΅Π½Ρ‚ с Π·Π°Ρ‰ΠΈΡ‚ΠΎΠΉ ΠΈΠ· ΠΊΠΎΡ€ΠΎΠ±ΠΊΠΈ

ΠšΠ°ΠΆΠ΄Ρ‹ΠΉ MySQL-ΠΊΠ»ΠΈΠ΅Π½Ρ‚ автоматичСски оборачиваСтся:

  • Circuit breaker β€” Π·Π°Ρ‰ΠΈΡ‚Π° ΠΎΡ‚ Π²Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Ρ… сбоСв (настраиваСмыС Π»ΠΈΠΌΠΈΡ‚ ΠΈ Ρ‚Π°ΠΉΠΌΠ°ΡƒΡ‚)
  • Π›ΠΎΠ³ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ β€” всС запросы Π»ΠΎΠ³ΠΈΡ€ΡƒΡŽΡ‚ΡΡ Π½Π° ΡƒΡ€ΠΎΠ²Π½Π΅ DEBUG

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

View Source
const (
	DsnFieldName = "db.mysql.dsn"

	ConnectionErrorLimitFieldName   = "db.mysql.connection.error.limit"
	ConnectionErrorTimeoutFieldName = "db.mysql.connection.error.timeout"

	ConnectionErrorLimitDefault   = uint32(10)
	ConnectionErrorTimeoutDefault = 10 * time.Second
)
View Source
const MySQL = "mysql"

MySQL is the driver identifier for MySQL database. It is used across all Compogo database components (client, migrator, generator).

Variables ΒΆ

View Source
var Component = &component.Component{
	Init: component.StepFunc(func(container container.Container) error {
		return container.Provides(
			NewConfig,
			NewMySQL,
		)
	}),
	BindFlags: component.BindFlags(func(flagSet flag.FlagSet, container container.Container) error {
		return container.Invoke(func(config *Config) {
			flagSet.StringVar(&config.DSN, DsnFieldName, "", "mysql dsn string connection")
			flagSet.Uint32Var(&config.ErrorLimit, ConnectionErrorLimitFieldName, ConnectionErrorLimitDefault, "")
			flagSet.DurationVar(&config.ErrorTimeout, ConnectionErrorTimeoutFieldName, ConnectionErrorTimeoutDefault, "")
		})
	}),
	Configuration: component.StepFunc(func(container container.Container) error {
		return container.Invoke(Configuration)
	}),
}

Component is a ready-to-use Compogo component that provides a MySQL client. It automatically:

  • Registers Config and NewMySQL in the DI container
  • Adds command-line flags for MySQL configuration
  • Applies configuration during Configuration phase

Usage:

compogo.WithComponents(
    db_client.Component,
    mysql.Component,
    // ... other components
)

The MySQL client can be injected into any component:

type UserService struct {
    db mysql.Client
}

Functions ΒΆ

This section is empty.

Types ΒΆ

type Client ΒΆ

type Client client.Client

Client is an alias for client.Client to provide a cleaner API. Users can work with mysql.Client without importing the internal client package.

func NewMySQL ΒΆ

func NewMySQL(logger logger.Logger, config *Config) (Client, error)

NewMySQL creates a new MySQL client with automatic decorators. The returned client is wrapped with:

  • connection.Limiter (circuit breaker for error protection)
  • logger.Logger (query logging at DEBUG level)

This provides production-ready behavior out of the box.

type Config ΒΆ

type Config struct {
	DSN          string
	ErrorLimit   uint32
	ErrorTimeout time.Duration
}

func Configuration ΒΆ

func Configuration(config *Config, configurator configurator.Configurator) *Config

func NewConfig ΒΆ

func NewConfig() *Config

Directories ΒΆ

Path Synopsis
registration
all

Jump to

Keyboard shortcuts

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