Documentation
¶
Overview ¶
Package uniquedialect provides a virtual SQL driver and GORM dialector that can translate a small cross-database SQL subset before delegating to a real database driver.
Index ¶
- Constants
- func ErrUnsupportedDialector(dialect Dialect) error
- func Open(dsn string) (*sql.DB, error)
- func OpenGORM(dsn string, cfg GORMConfig) (gorm.Dialector, error)
- func OpenGORMWithOptions(opts Options, cfg GORMConfig) (gorm.Dialector, error)
- func OpenWithOptions(opts Options) (*sql.DB, error)
- type BootstrapArtifact
- type BootstrapKind
- type BootstrapOptions
- type BootstrapPlanner
- type ConnectionOptions
- type Dialect
- type DriverName
- type EncryptionOptions
- type Encryptor
- type GORMConfig
- type LoggingOptions
- type Options
- type ParserAdaptationError
- type Translation
- type Translator
- type TranslatorOptions
- type TranslatorStats
Constants ¶
const ( // Scheme is the custom DSN scheme for UniqueDialect. Scheme = "uniquedialect" // DefaultSQLDriverName is the registered database/sql driver name. DefaultSQLDriverName = "uniquedialect" // DefaultCipherPrefix prefixes encrypted values for downgrade-safe reads. DefaultCipherPrefix = "enc:v1:" // DefaultTranslateFailureLogPath is the default JSONL log path for translation failures. DefaultTranslateFailureLogPath = "uniquedialect-translate-failures.jsonl" // DefaultExecutionFailureLogPath is the default JSONL log path for execution failures. DefaultExecutionFailureLogPath = "uniquedialect-execution-failures.jsonl" )
Variables ¶
This section is empty.
Functions ¶
func ErrUnsupportedDialector ¶
ErrUnsupportedDialector reports an unsupported target for GORM execution.
func OpenGORM ¶
func OpenGORM(dsn string, cfg GORMConfig) (gorm.Dialector, error)
OpenGORM opens a GORM dialector from a UniqueDialect DSN.
func OpenGORMWithOptions ¶
func OpenGORMWithOptions(opts Options, cfg GORMConfig) (gorm.Dialector, error)
OpenGORMWithOptions opens a GORM dialector from canonical options.
Types ¶
type BootstrapArtifact ¶
type BootstrapArtifact struct {
Name string
Kind BootstrapKind
SQL string
Idempotent bool
}
BootstrapArtifact is an executable compatibility artifact.
type BootstrapKind ¶
type BootstrapKind string
BootstrapKind identifies the artifact type.
const ( // BootstrapKindFunction is a database function shim. BootstrapKindFunction BootstrapKind = "function" // BootstrapKindTrigger is a database trigger shim. BootstrapKindTrigger BootstrapKind = "trigger" )
type BootstrapOptions ¶
BootstrapOptions configures bootstrap planning.
type BootstrapPlanner ¶
type BootstrapPlanner struct {
// contains filtered or unexported fields
}
BootstrapPlanner plans compatibility artifacts for translated SQL and DDL.
func NewBootstrapPlanner ¶
func NewBootstrapPlanner(opts BootstrapOptions) *BootstrapPlanner
NewBootstrapPlanner creates a compatibility artifact planner.
func (*BootstrapPlanner) Plan ¶
func (p *BootstrapPlanner) Plan(_ context.Context, sql string) ([]BootstrapArtifact, error)
Plan analyzes SQL/DDL and returns required bootstrap artifacts.
type ConnectionOptions ¶
type ConnectionOptions struct {
Host string
Port int
Username string
Password string
Database string
Parameters map[string]string
}
ConnectionOptions is the canonical connection model shared across targets.
type Dialect ¶
type Dialect string
Dialect identifies a SQL dialect.
const ( // DialectMySQL is the MySQL dialect. DialectMySQL Dialect = "mysql" // DialectPostgres is the PostgreSQL dialect. DialectPostgres Dialect = "postgres" // DialectSQLite is the SQLite dialect. DialectSQLite Dialect = "sqlite" // DialectOracle is the Oracle dialect. DialectOracle Dialect = "oracle" )
type DriverName ¶
type DriverName string
DriverName identifies an underlying database/sql driver family.
const ( // DriverMySQL is the MySQL database/sql driver family. DriverMySQL DriverName = "mysql" // DriverPostgres is the PostgreSQL database/sql driver family. DriverPostgres DriverName = "postgres" // DriverSQLite is the SQLite database/sql driver family. DriverSQLite DriverName = "sqlite" // DriverOracle is the Oracle database/sql driver family. DriverOracle DriverName = "oracle" )
type EncryptionOptions ¶
EncryptionOptions configures field encryption for GORM.
type Encryptor ¶
Encryptor encrypts and decrypts string values.
func NewDefaultEncryptor ¶
NewDefaultEncryptor constructs the built-in AES-GCM encryptor.
type GORMConfig ¶
GORMConfig configures the GORM dialector wrapper.
type LoggingOptions ¶
type LoggingOptions struct {
Level string
LogFailedSQL bool
TranslateFailureLogPath string
ExecutionFailureLogPath string
}
LoggingOptions configures execution logging.
type Options ¶
type Options struct {
InputDialect Dialect
TargetDialect Dialect
Driver DriverName
Connection ConnectionOptions
Translator TranslatorOptions
Logging LoggingOptions
Encryption EncryptionOptions
}
Options configures the virtual driver.
func (Options) BuildDriverDSN ¶
BuildDriverDSN maps the canonical connection options to the target driver DSN.
type ParserAdaptationError ¶
type ParserAdaptationError struct {
SourceDialect string
StatementKind string
NativeNodeType string
Status string
}
ParserAdaptationError indicates the SQL was parsed successfully but is not yet adapted by the translation pipeline.
func (*ParserAdaptationError) Error ¶
func (e *ParserAdaptationError) Error() string
type Translation ¶
Translation contains a translated SQL statement and its mapped arguments.
type Translator ¶
type Translator struct {
// contains filtered or unexported fields
}
Translator translates SQL between dialects and caches results.
func NewTranslator ¶
func NewTranslator(opts TranslatorOptions) (*Translator, error)
NewTranslator constructs a translator for a dialect pair.
func (*Translator) Stats ¶
func (t *Translator) Stats() TranslatorStats
Stats returns a snapshot of cache statistics.
func (*Translator) Translate ¶
func (t *Translator) Translate(_ context.Context, sql string, args ...any) (Translation, error)
Translate rewrites SQL text and returns mapped arguments.
type TranslatorOptions ¶
TranslatorOptions configures SQL translation.
type TranslatorStats ¶
TranslatorStats exposes in-memory cache hit statistics.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
parser/tidb/ast
Package ast is the abstract syntax tree parsed from a SQL statement by parser.
|
Package ast is the abstract syntax tree parsed from a SQL statement by parser. |
|
parser/tidb/duration
Package duration provides a customized duration, which supports unit 'd', 'h' and 'm'
|
Package duration provides a customized duration, which supports unit 'd', 'h' and 'm' |
|
parser/tidb/generate_keyword
command
|
|
|
parser/tidb/goyacc
command
Goyacc is a version of yacc generating Go parsers.
|
Goyacc is a version of yacc generating Go parsers. |