mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
Full module path rebrand from Temporal to Hanzo Tasks: - go.mod module: github.com/hanzoai/tasks - All internal Go imports updated (1906 files) - cmd/server renamed to cmd/tasksd - Binary name: tasksd (was temporal-server) - Docker images: hanzoai/tasks (was temporalio/server) - README rewritten with Hanzo Tasks branding - LLM.md created with integration notes - Makefile, goreleaser, CI workflows updated - go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos) Fork of Temporal.io (MIT license).
70 lines
1.9 KiB
Go
70 lines
1.9 KiB
Go
package mysql
|
|
|
|
import (
|
|
"github.com/jmoiron/sqlx"
|
|
"github.com/hanzoai/tasks/common/clock"
|
|
"github.com/hanzoai/tasks/common/config"
|
|
"github.com/hanzoai/tasks/common/log"
|
|
"github.com/hanzoai/tasks/common/metrics"
|
|
"github.com/hanzoai/tasks/common/persistence/sql"
|
|
"github.com/hanzoai/tasks/common/persistence/sql/sqlplugin"
|
|
"github.com/hanzoai/tasks/common/persistence/sql/sqlplugin/mysql/session"
|
|
"github.com/hanzoai/tasks/common/resolver"
|
|
)
|
|
|
|
const (
|
|
// PluginName is the name of the plugin
|
|
PluginName = "mysql8"
|
|
)
|
|
|
|
type plugin struct {
|
|
queryConverter sqlplugin.VisibilityQueryConverter
|
|
}
|
|
|
|
var _ sqlplugin.Plugin = (*plugin)(nil)
|
|
|
|
func init() {
|
|
sql.RegisterPlugin(PluginName, &plugin{
|
|
queryConverter: &queryConverter{},
|
|
})
|
|
}
|
|
|
|
func (p *plugin) GetVisibilityQueryConverter() sqlplugin.VisibilityQueryConverter {
|
|
return p.queryConverter
|
|
}
|
|
|
|
// CreateDB initialize the db object
|
|
func (p *plugin) CreateDB(
|
|
dbKind sqlplugin.DbKind,
|
|
cfg *config.SQL,
|
|
r resolver.ServiceResolver,
|
|
logger log.Logger,
|
|
metricsHandler metrics.Handler,
|
|
) (sqlplugin.GenericDB, error) {
|
|
connect := func() (*sqlx.DB, error) {
|
|
if cfg.Connect != nil {
|
|
return cfg.Connect(cfg)
|
|
}
|
|
return p.createDBConnection(dbKind, cfg, r)
|
|
}
|
|
handle := sqlplugin.NewDatabaseHandle(dbKind, connect, isConnNeedsRefreshError, logger, metricsHandler, clock.NewRealTimeSource())
|
|
db := newDB(dbKind, cfg.DatabaseName, handle, nil, logger)
|
|
return db, nil
|
|
}
|
|
|
|
// CreateDBConnection creates a returns a reference to a logical connection to the
|
|
// underlying SQL database. The returned object is to tied to a single
|
|
// SQL database and the object can be used to perform CRUD operations on
|
|
// the tables in the database
|
|
func (p *plugin) createDBConnection(
|
|
dbKind sqlplugin.DbKind,
|
|
cfg *config.SQL,
|
|
resolver resolver.ServiceResolver,
|
|
) (*sqlx.DB, error) {
|
|
mysqlSession, err := session.NewSession(dbKind, cfg, resolver)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return mysqlSession.DB, nil
|
|
}
|