parser

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBatchProcessorStopped indicates the batch processor has been stopped
	ErrBatchProcessorStopped = errors.New("batch processor stopped")
	// ErrBatchTimeout indicates a batch processing timeout
	ErrBatchTimeout = errors.New("batch processing timeout")
)
View Source
var (
	// MySQL to PostgreSQL mappings
	MySQLToPostgresMappings = []TypeMapping{
		{
			SourceType: "int",
			TargetType: "integer",
			ConversionFunc: func(v interface{}) (interface{}, error) {
				return v, nil
			},
		},
		{
			SourceType: "varchar",
			TargetType: "character varying",
			ConversionFunc: func(v interface{}) (interface{}, error) {
				return v, nil
			},
		},
		{
			SourceType: "datetime",
			TargetType: "timestamp",
			ConversionFunc: func(v interface{}) (interface{}, error) {
				if str, ok := v.(string); ok {
					return time.Parse("2006-01-02 15:04:05", str)
				}
				return v, nil
			},
		},
		{
			SourceType: "tinyint(1)",
			TargetType: "boolean",
			ConversionFunc: func(v interface{}) (interface{}, error) {
				switch val := v.(type) {
				case int64:
					return val != 0, nil
				case string:
					return strconv.ParseBool(val)
				default:
					return nil, fmt.Errorf("unsupported type for boolean conversion: %T", v)
				}
			},
		},
		{
			SourceType: "json",
			TargetType: "jsonb",
			ConversionFunc: func(v interface{}) (interface{}, error) {
				return v, nil
			},
		},
	}

	// PostgreSQL to MySQL mappings
	PostgresToMySQLMappings = []TypeMapping{
		{
			SourceType: "integer",
			TargetType: "int",
			ConversionFunc: func(v interface{}) (interface{}, error) {
				return v, nil
			},
		},
		{
			SourceType: "character varying",
			TargetType: "varchar",
			ConversionFunc: func(v interface{}) (interface{}, error) {
				return v, nil
			},
		},
		{
			SourceType: "timestamp",
			TargetType: "datetime",
			ConversionFunc: func(v interface{}) (interface{}, error) {
				if str, ok := v.(string); ok {
					return time.Parse("2006-01-02 15:04:05.999999-07", str)
				}
				return v, nil
			},
		},
		{
			SourceType: "boolean",
			TargetType: "tinyint(1)",
			ConversionFunc: func(v interface{}) (interface{}, error) {
				if b, ok := v.(bool); ok {
					if b {
						return 1, nil
					}
					return 0, nil
				}
				return nil, fmt.Errorf("value is not a boolean: %v", v)
			},
		},
		{
			SourceType: "jsonb",
			TargetType: "json",
			ConversionFunc: func(v interface{}) (interface{}, error) {
				return v, nil
			},
		},
	}

	// SQLite specific mappings
	SQLiteMappings = []TypeMapping{
		{
			SourceType: "integer",
			TargetType: "integer",
			ConversionFunc: func(v interface{}) (interface{}, error) {
				return v, nil
			},
		},
		{
			SourceType: "text",
			TargetType: "text",
			ConversionFunc: func(v interface{}) (interface{}, error) {
				return v, nil
			},
		},
		{
			SourceType: "real",
			TargetType: "real",
			ConversionFunc: func(v interface{}) (interface{}, error) {
				return v, nil
			},
		},
		{
			SourceType: "blob",
			TargetType: "blob",
			ConversionFunc: func(v interface{}) (interface{}, error) {
				return v, nil
			},
		},
	}
)

Common data type mappings

View Source
var (
	// ErrInvalidInput represents an invalid input error
	ErrInvalidInput = errors.New("invalid input")
	// ErrBufferOverflow represents a buffer overflow error
	ErrBufferOverflow = errors.New("buffer overflow")
	// ErrParserTimeout represents a parser timeout error
	ErrParserTimeout = errors.New("parser timeout")
)
View Source
var (
	DefaultUTF8MB4 = CharSet{
		Name:        "utf8mb4",
		Description: "UTF-8 Unicode",
		MaxLength:   4,
		Supported: map[DataType]bool{
			TypeMySQL:      true,
			TypePostgreSQL: true,
			TypeSQLite:     true,
			TypeOracle:     true,
			TypeSQLServer:  true,
		},
	}

	DefaultLatin1 = CharSet{
		Name:        "latin1",
		Description: "cp1252 West European",
		MaxLength:   1,
		Supported: map[DataType]bool{
			TypeMySQL:      true,
			TypePostgreSQL: true,
			TypeSQLite:     true,
			TypeOracle:     true,
			TypeSQLServer:  true,
		},
	}
)

Common character sets

View Source
var (
	DefaultUTF8MB4Unicode = CollationConfig{
		Name:        "utf8mb4_unicode_ci",
		CharSet:     "utf8mb4",
		Description: "Unicode (case-insensitive)",
		Supported: map[DataType]bool{
			TypeMySQL:      true,
			TypePostgreSQL: true,
			TypeSQLite:     true,
		},
	}

	DefaultUTF8MB4Bin = CollationConfig{
		Name:        "utf8mb4_bin",
		CharSet:     "utf8mb4",
		Description: "Unicode (binary)",
		Supported: map[DataType]bool{
			TypeMySQL:      true,
			TypePostgreSQL: true,
			TypeSQLite:     true,
		},
	}
)

Common collations

View Source
var (
	// ErrWorkerPoolStopped indicates the worker pool has been stopped
	ErrWorkerPoolStopped = errors.New("worker pool stopped")
	// ErrTaskTimeout indicates a task execution timeout
	ErrTaskTimeout = errors.New("task execution timeout")
	// ErrQueueFull indicates the task queue is full
	ErrQueueFull = errors.New("task queue is full")
)
View Source
var DatabaseInfoMap = map[DatabaseType]DatabaseInfo{
	MySQL: {
		DefaultSchema:       "",
		IdentifierQuote:     "`",
		StringQuote:         "'",
		MaxIdentifierLength: 64,
	},
	PostgreSQL: {
		DefaultSchema:       "public",
		IdentifierQuote:     "\"",
		StringQuote:         "'",
		MaxIdentifierLength: 63,
	},
	SQLServer: {
		DefaultSchema:       "dbo",
		IdentifierQuote:     "\"",
		StringQuote:         "'",
		MaxIdentifierLength: 128,
	},
	Oracle: {
		DefaultSchema:       "",
		IdentifierQuote:     "\"",
		StringQuote:         "'",
		MaxIdentifierLength: 30,
	},
	SQLite: {
		DefaultSchema:       "main",
		IdentifierQuote:     "\"",
		StringQuote:         "'",
		MaxIdentifierLength: 0,
	},
}

DatabaseInfoMap contains database information for each supported database type

Functions

This section is empty.

Types

type BatchConfig added in v0.1.0

type BatchConfig struct {
	BatchSize    int
	Workers      int
	Timeout      time.Duration
	MemOptimizer *MemoryOptimizer
	ErrorHandler func(error)
}

BatchConfig represents batch processor configuration

type BatchProcessor added in v0.1.0

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

BatchProcessor handles batch processing of SQL statements

func NewBatchProcessor added in v0.1.0

func NewBatchProcessor(config BatchConfig) *BatchProcessor

NewBatchProcessor creates a new batch processor

func (*BatchProcessor) ProcessBatch added in v0.1.0

func (bp *BatchProcessor) ProcessBatch(ctx context.Context, stmts []*Statement, handler func(*Statement) error) error

ProcessBatch processes statements in batches

func (*BatchProcessor) SetBatchSize added in v0.1.0

func (bp *BatchProcessor) SetBatchSize(size int)

SetBatchSize sets the batch size

func (*BatchProcessor) SetErrorHandler added in v0.1.0

func (bp *BatchProcessor) SetErrorHandler(handler func(error))

SetErrorHandler sets the error handler function

func (*BatchProcessor) SetTimeout added in v0.1.0

func (bp *BatchProcessor) SetTimeout(timeout time.Duration)

SetTimeout sets the processing timeout

func (*BatchProcessor) Stop added in v0.1.0

func (bp *BatchProcessor) Stop()

Stop stops the batch processor

type CharSet added in v0.1.0

type CharSet struct {
	Name        string
	Description string
	MaxLength   int
	Supported   map[DataType]bool
}

CharSet represents character set configuration

type CollationConfig added in v0.1.0

type CollationConfig struct {
	Name        string
	CharSet     string
	Description string
	Supported   map[DataType]bool
}

CollationConfig represents collation configuration

type Column added in v0.1.0

type Column struct {
	Name          string
	DataType      *DataType
	IsNullable    bool
	Nullable      bool
	Default       string
	AutoIncrement bool
	PrimaryKey    bool
	Unique        bool
	Collation     string
}

Column represents a table column

type ConnectionManager added in v0.1.0

type ConnectionManager interface {
	Connect(ctx context.Context) error
	Disconnect(ctx context.Context) error
	IsConnected() bool
}

ConnectionManager connection management interface

type Constraint added in v0.1.0

type Constraint struct {
	Name       string
	Type       string
	Columns    []string
	RefTable   string
	RefColumns []string
	OnDelete   string
	OnUpdate   string
}

Constraint represents a table constraint

type Converter added in v0.1.0

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

Converter handles data type conversions

func NewConverter added in v0.1.0

func NewConverter() *Converter

NewConverter creates a new type converter

func (*Converter) ConvertType added in v0.1.0

func (c *Converter) ConvertType(value interface{}, sourceType string, targetType string, sourceVersion, targetVersion *Version) (interface{}, error)

ConvertType converts a value from one type to another

func (*Converter) GetCharSet added in v0.1.0

func (c *Converter) GetCharSet(name string) (CharSet, error)

GetCharSet returns character set information

func (*Converter) GetCollation added in v0.1.0

func (c *Converter) GetCollation(name string) (CollationConfig, error)

GetCollation returns collation information

func (*Converter) RegisterCharSet added in v0.1.0

func (c *Converter) RegisterCharSet(charset CharSet)

RegisterCharSet registers a new character set

func (*Converter) RegisterCollation added in v0.1.0

func (c *Converter) RegisterCollation(collation CollationConfig)

RegisterCollation registers a new collation

func (*Converter) RegisterDefaultMappings added in v0.1.0

func (c *Converter) RegisterDefaultMappings()

RegisterDefaultMappings registers default type mappings

func (*Converter) RegisterMapping added in v0.1.0

func (c *Converter) RegisterMapping(mapping TypeMapping)

RegisterMapping registers a new type mapping

type DataType added in v0.1.0

type DataType string

DataType represents supported database types

const (
	TypeMySQL      DataType = "mysql"
	TypePostgreSQL DataType = "postgresql"
	TypeSQLite     DataType = "sqlite"
	TypeOracle     DataType = "oracle"
	TypeSQLServer  DataType = "sqlserver"
)

type DatabaseInfo

type DatabaseInfo struct {
	DefaultSchema       string
	IdentifierQuote     string
	StringQuote         string
	MaxIdentifierLength int
	ReservedWords       []string
}

DatabaseInfo holds database-specific information

type DatabaseType

type DatabaseType string

DatabaseType represents the type of database

const (
	MySQL      DatabaseType = "mysql"
	PostgreSQL DatabaseType = "postgresql"
	SQLServer  DatabaseType = "sqlserver"
	Oracle     DatabaseType = "oracle"
	SQLite     DatabaseType = "sqlite"
)

type Entity added in v0.1.0

type Entity struct {
	Tables []*Table
}

Entity represents a database entity

type MemoryOptimizer added in v0.1.0

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

MemoryOptimizer handles memory optimization

func NewMemoryOptimizer added in v0.1.0

func NewMemoryOptimizer(maxMemoryMB int64, gcThreshold float64) *MemoryOptimizer

NewMemoryOptimizer creates a new memory optimizer

func (*MemoryOptimizer) GetBuffer added in v0.1.0

func (mo *MemoryOptimizer) GetBuffer() []byte

GetBuffer gets a buffer from the pool

func (*MemoryOptimizer) GetStats added in v0.1.0

func (mo *MemoryOptimizer) GetStats() *MemoryStats

GetStats returns current memory statistics

func (*MemoryOptimizer) MonitorMemory added in v0.1.0

func (mo *MemoryOptimizer) MonitorMemory(ctx context.Context)

MonitorMemory monitors and optimizes memory usage

func (*MemoryOptimizer) PutBuffer added in v0.1.0

func (mo *MemoryOptimizer) PutBuffer(buf []byte)

PutBuffer returns a buffer to the pool

func (*MemoryOptimizer) SetGCThreshold added in v0.1.0

func (mo *MemoryOptimizer) SetGCThreshold(threshold float64)

SetGCThreshold sets the garbage collection threshold

func (*MemoryOptimizer) SetMaxMemory added in v0.1.0

func (mo *MemoryOptimizer) SetMaxMemory(maxMemoryMB int64)

SetMaxMemory sets the maximum memory threshold

func (*MemoryOptimizer) SetMonitoringInterval added in v0.1.0

func (mo *MemoryOptimizer) SetMonitoringInterval(d time.Duration)

SetMonitoringInterval sets the monitoring interval

type MemoryStats added in v0.1.0

type MemoryStats struct {
	AllocatedBytes    uint64
	TotalAllocBytes   uint64
	SystemBytes       uint64
	GCCycles          uint32
	LastGCPauseNanos  uint64
	TotalGCPauseNanos uint64
}

MemoryStats holds memory statistics

type MigrationManager added in v0.1.0

type MigrationManager interface {
	ApplyMigrations(ctx context.Context) error
	RollbackMigration(ctx context.Context) error
	GetMigrationStatus(ctx context.Context) ([]MigrationStatus, error)
}

MigrationManager migration operations interface

type MigrationStatus added in v0.1.0

type MigrationStatus struct {
	ID        string
	Name      string
	Version   string
	AppliedAt string
	Status    string
}

MigrationStatus migration status struct

type MySQLParser

type MySQLParser struct{}

MySQLParser implements the parser for MySQL database

func (*MySQLParser) Convert

func (p *MySQLParser) Convert(entity *sdc.Entity) (string, error)

Convert transforms Entity structure to MySQL format

func (*MySQLParser) ConvertDataTypeFrom

func (p *MySQLParser) ConvertDataTypeFrom(sourceType string, length int, precision int, scale int) *sdc.DataType

ConvertDataTypeFrom converts source database data type to MySQL data type

func (*MySQLParser) EscapeIdentifier

func (p *MySQLParser) EscapeIdentifier(name string) string

EscapeIdentifier escapes the identifier name

func (*MySQLParser) EscapeString

func (p *MySQLParser) EscapeString(value string) string

EscapeString escapes the string value

func (*MySQLParser) GetDefaultSchema

func (p *MySQLParser) GetDefaultSchema() string

GetDefaultSchema returns the default schema name

func (*MySQLParser) GetIdentifierQuote

func (p *MySQLParser) GetIdentifierQuote() string

GetIdentifierQuote returns the identifier quote character

func (*MySQLParser) GetMaxIdentifierLength

func (p *MySQLParser) GetMaxIdentifierLength() int

GetMaxIdentifierLength returns the maximum identifier length

func (*MySQLParser) GetReservedWords

func (p *MySQLParser) GetReservedWords() []string

GetReservedWords returns the reserved words

func (*MySQLParser) GetSchemaPrefix

func (p *MySQLParser) GetSchemaPrefix(schema string) string

GetSchemaPrefix returns the schema prefix

func (*MySQLParser) GetStringQuote

func (p *MySQLParser) GetStringQuote() string

GetStringQuote returns the string quote character

func (*MySQLParser) Parse

func (p *MySQLParser) Parse(sql string) (*sdc.Entity, error)

Parse converts MySQL dump to Entity structure

func (*MySQLParser) ParseAlterTable

func (p *MySQLParser) ParseAlterTable(sql string) (*sdc.AlterTable, error)

ParseAlterTable parses ALTER TABLE statement

func (*MySQLParser) ParseCreateIndex

func (p *MySQLParser) ParseCreateIndex(sql string) (*sdc.Index, error)

ParseCreateIndex parses CREATE INDEX statement

func (*MySQLParser) ParseCreateTable

func (p *MySQLParser) ParseCreateTable(sql string) (*sdc.Table, error)

ParseCreateTable parses CREATE TABLE statement

func (*MySQLParser) ParseDropIndex

func (p *MySQLParser) ParseDropIndex(sql string) (*sdc.DropIndex, error)

ParseDropIndex parses DROP INDEX statement

func (*MySQLParser) ParseDropTable

func (p *MySQLParser) ParseDropTable(sql string) (*sdc.DropTable, error)

ParseDropTable parses DROP TABLE statement

func (*MySQLParser) ValidateIdentifier

func (p *MySQLParser) ValidateIdentifier(name string) error

ValidateIdentifier validates the identifier name

type OracleParser

type OracleParser struct{}

OracleParser implements the parser for Oracle database

func (*OracleParser) Convert

func (p *OracleParser) Convert(entity *sdc.Entity) (string, error)

Convert transforms Entity structure to Oracle format

func (*OracleParser) ConvertDataTypeFrom

func (p *OracleParser) ConvertDataTypeFrom(sourceType string, length int, precision int, scale int) *sdc.DataType

ConvertDataTypeFrom converts source database data type to Oracle data type

func (*OracleParser) EscapeIdentifier

func (p *OracleParser) EscapeIdentifier(name string) string

EscapeIdentifier escapes the identifier name

func (*OracleParser) EscapeString

func (p *OracleParser) EscapeString(value string) string

EscapeString escapes the string value

func (*OracleParser) GetDefaultSchema

func (p *OracleParser) GetDefaultSchema() string

GetDefaultSchema returns the default schema name

func (*OracleParser) GetIdentifierQuote

func (p *OracleParser) GetIdentifierQuote() string

GetIdentifierQuote returns the identifier quote character

func (*OracleParser) GetMaxIdentifierLength

func (p *OracleParser) GetMaxIdentifierLength() int

GetMaxIdentifierLength returns the maximum identifier length

func (*OracleParser) GetReservedWords

func (p *OracleParser) GetReservedWords() []string

GetReservedWords returns the reserved words

func (*OracleParser) GetSchemaPrefix

func (p *OracleParser) GetSchemaPrefix(schema string) string

GetSchemaPrefix returns the schema prefix

func (*OracleParser) GetStringQuote

func (p *OracleParser) GetStringQuote() string

GetStringQuote returns the string quote character

func (*OracleParser) Parse

func (p *OracleParser) Parse(sql string) (*sdc.Entity, error)

Parse converts Oracle dump to Entity structure

func (*OracleParser) ParseAlterTable

func (p *OracleParser) ParseAlterTable(sql string) (*sdc.AlterTable, error)

ParseAlterTable parses ALTER TABLE statement

func (*OracleParser) ParseCreateIndex

func (p *OracleParser) ParseCreateIndex(sql string) (*sdc.Index, error)

ParseCreateIndex parses CREATE INDEX statement

func (*OracleParser) ParseCreateTable

func (p *OracleParser) ParseCreateTable(sql string) (*sdc.Table, error)

ParseCreateTable parses CREATE TABLE statement

func (*OracleParser) ParseDropIndex

func (p *OracleParser) ParseDropIndex(sql string) (*sdc.DropIndex, error)

ParseDropIndex parses DROP INDEX statement

func (*OracleParser) ParseDropTable

func (p *OracleParser) ParseDropTable(sql string) (*sdc.DropTable, error)

ParseDropTable parses DROP TABLE statement

func (*OracleParser) ValidateIdentifier

func (p *OracleParser) ValidateIdentifier(name string) error

ValidateIdentifier validates the identifier name

type Parser

type Parser interface {
	Parse(sql string) (*Entity, error)
	Convert(entity *Entity) (string, error)
	ValidateIdentifier(name string) error
	EscapeIdentifier(name string) string
	EscapeString(value string) string
	GetDefaultSchema() string
	GetSchemaPrefix(schema string) string
	GetIdentifierQuote() string
	GetStringQuote() string
	GetMaxIdentifierLength() int
	GetReservedWords() []string
}

Parser interface for SQL parsing and conversion

type PostgresParser

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

PostgresParser implements the parser for PostgreSQL database

func NewPostgresParser

func NewPostgresParser() *PostgresParser

NewPostgresParser creates a new PostgreSQL parser

func (*PostgresParser) Convert

func (p *PostgresParser) Convert(entity *sdc.Entity) (string, error)

Convert transforms Entity structure to PostgreSQL format with optimized string handling

func (*PostgresParser) ConvertDataTypeFrom

func (p *PostgresParser) ConvertDataTypeFrom(sourceType string, length int, precision int, scale int) *sdc.DataType

ConvertDataTypeFrom converts source database data type to PostgreSQL data type

func (*PostgresParser) EscapeIdentifier

func (p *PostgresParser) EscapeIdentifier(name string) string

EscapeIdentifier escapes the identifier name

func (*PostgresParser) EscapeString

func (p *PostgresParser) EscapeString(value string) string

EscapeString escapes the string value

func (*PostgresParser) GetDefaultSchema

func (p *PostgresParser) GetDefaultSchema() string

GetDefaultSchema returns the default schema name

func (*PostgresParser) GetIdentifierQuote

func (p *PostgresParser) GetIdentifierQuote() string

GetIdentifierQuote returns the identifier quote character

func (*PostgresParser) GetMaxIdentifierLength

func (p *PostgresParser) GetMaxIdentifierLength() int

GetMaxIdentifierLength returns the maximum identifier length

func (*PostgresParser) GetReservedWords

func (p *PostgresParser) GetReservedWords() []string

GetReservedWords returns the reserved words

func (*PostgresParser) GetSchemaPrefix

func (p *PostgresParser) GetSchemaPrefix(schema string) string

GetSchemaPrefix returns the schema prefix

func (*PostgresParser) GetStringQuote

func (p *PostgresParser) GetStringQuote() string

GetStringQuote returns the string quote character

func (*PostgresParser) Parse

func (p *PostgresParser) Parse(sql string) (*sdc.Entity, error)

Parse converts PostgreSQL dump to Entity structure

func (*PostgresParser) ParseAlterTable

func (p *PostgresParser) ParseAlterTable(sql string) (*sdc.AlterTable, error)

ParseAlterTable parses ALTER TABLE statement

func (*PostgresParser) ParseCreateIndex

func (p *PostgresParser) ParseCreateIndex(sql string) (*sdc.Index, error)

ParseCreateIndex parses CREATE INDEX statement

func (*PostgresParser) ParseCreateTable

func (p *PostgresParser) ParseCreateTable(sql string) (*sdc.Table, error)

ParseCreateTable parses CREATE TABLE statement

func (*PostgresParser) ParseDropIndex

func (p *PostgresParser) ParseDropIndex(sql string) (*sdc.DropIndex, error)

ParseDropIndex parses DROP INDEX statement

func (*PostgresParser) ParseDropTable

func (p *PostgresParser) ParseDropTable(sql string) (*sdc.DropTable, error)

ParseDropTable parses DROP TABLE statement

func (*PostgresParser) ParseSQL

func (p *PostgresParser) ParseSQL(sql string) (*sdc.Entity, error)

ParseSQL parses PostgreSQL SQL statements and returns an Entity

func (*PostgresParser) ValidateIdentifier

func (p *PostgresParser) ValidateIdentifier(name string) error

ValidateIdentifier validates the identifier name

type QueryExecutor added in v0.1.0

type QueryExecutor interface {
	Execute(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(ctx context.Context, query string, args ...interface{}) *sql.Row
}

QueryExecutor basic query operations interface

type Result added in v0.1.0

type Result struct {
	TaskID    string
	Data      interface{}
	Error     error
	StartTime time.Time
	EndTime   time.Time
	Duration  time.Duration
}

Result represents the result of a task

type SQLServerParser

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

SQLServerParser implements the parser for SQL Server database

func NewSQLServerParser

func NewSQLServerParser() *SQLServerParser

NewSQLServerParser creates a new SQL Server parser with default security options

func (*SQLServerParser) Convert

func (p *SQLServerParser) Convert(entity *sdc.Entity, options SecurityOptions) (string, error)

Convert transforms Entity structure to SQL Server format with security validation

func (*SQLServerParser) Parse

func (p *SQLServerParser) Parse(sql string) (*sdc.Entity, error)

Parse converts SQL Server dump to Entity structure with security validation

func (*SQLServerParser) SetSecurityOptions

func (p *SQLServerParser) SetSecurityOptions(options SecurityOptions)

SetSecurityOptions sets custom security options

func (*SQLServerParser) ValidateSchema

func (p *SQLServerParser) ValidateSchema(table *sdc.Table, options SecurityOptions) error

ValidateSchema validates the schema structure with security checks

type SQLiteParser

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

SQLiteParser implements the parser for SQLite database

func NewSQLiteParser

func NewSQLiteParser() *SQLiteParser

NewSQLiteParser creates a new SQLite parser

func (*SQLiteParser) Convert

func (p *SQLiteParser) Convert(entity *sdc.Entity) (string, error)

Convert transforms Entity structure to SQLite format with optimized string handling

func (*SQLiteParser) ConvertDataTypeFrom

func (p *SQLiteParser) ConvertDataTypeFrom(sourceType string, length int, precision int, scale int) *sdc.DataType

ConvertDataTypeFrom converts source database data type to SQLite data type

func (*SQLiteParser) EscapeIdentifier

func (p *SQLiteParser) EscapeIdentifier(name string) string

EscapeIdentifier escapes the identifier name

func (*SQLiteParser) EscapeString

func (p *SQLiteParser) EscapeString(value string) string

EscapeString escapes the string value

func (*SQLiteParser) GetDefaultSchema

func (p *SQLiteParser) GetDefaultSchema() string

GetDefaultSchema returns the default schema name

func (*SQLiteParser) GetIdentifierQuote

func (p *SQLiteParser) GetIdentifierQuote() string

GetIdentifierQuote returns the identifier quote character

func (*SQLiteParser) GetMaxIdentifierLength

func (p *SQLiteParser) GetMaxIdentifierLength() int

GetMaxIdentifierLength returns the maximum identifier length

func (*SQLiteParser) GetReservedWords

func (p *SQLiteParser) GetReservedWords() []string

GetReservedWords returns the reserved words

func (*SQLiteParser) GetSchemaPrefix

func (p *SQLiteParser) GetSchemaPrefix(schema string) string

GetSchemaPrefix returns the schema prefix

func (*SQLiteParser) GetStringQuote

func (p *SQLiteParser) GetStringQuote() string

GetStringQuote returns the string quote character

func (*SQLiteParser) Parse

func (p *SQLiteParser) Parse(sql string) (*sdc.Entity, error)

Parse converts SQLite dump to Entity structure

func (*SQLiteParser) ParseAlterTable

func (p *SQLiteParser) ParseAlterTable(sql string) (*sdc.Table, error)

ParseAlterTable parses ALTER TABLE statement

func (*SQLiteParser) ParseCreateIndex

func (p *SQLiteParser) ParseCreateIndex(sql string) (*sdc.Index, error)

ParseCreateIndex parses CREATE INDEX statement

func (*SQLiteParser) ParseCreateTable

func (p *SQLiteParser) ParseCreateTable(sql string) (*sdc.Table, error)

ParseCreateTable parses CREATE TABLE statement

func (*SQLiteParser) ParseDropIndex

func (p *SQLiteParser) ParseDropIndex(sql string) (*sdc.Index, error)

ParseDropIndex parses DROP INDEX statement

func (*SQLiteParser) ParseDropTable

func (p *SQLiteParser) ParseDropTable(sql string) (*sdc.Table, error)

ParseDropTable parses DROP TABLE statement

func (*SQLiteParser) ParseSQL

func (p *SQLiteParser) ParseSQL(sql string) (*sdc.Entity, error)

ParseSQL parses SQLite SQL statements and returns an Entity

func (*SQLiteParser) ValidateIdentifier

func (p *SQLiteParser) ValidateIdentifier(name string) error

ValidateIdentifier validates the identifier name

type SchemaManager added in v0.1.0

type SchemaManager interface {
	CreateTable(ctx context.Context, table string) error
	DropTable(ctx context.Context, table string) error
	AlterTable(ctx context.Context, table string, alterations []string) error
}

SchemaManager schema management interface

type SecurityLevel

type SecurityLevel int

SecurityLevel represents the security level for parsing and validation

const (
	// SecurityLevelLow minimal security checks
	SecurityLevelLow SecurityLevel = iota
	// SecurityLevelMedium standard security checks
	SecurityLevelMedium
	// SecurityLevelHigh strict security checks
	SecurityLevelHigh
)

type SecurityOptions

type SecurityOptions struct {
	Level               SecurityLevel
	DisableComments     bool     // Disable SQL comments
	MaxIdentifierLength int      // Maximum length for identifiers
	MaxQueryLength      int      // Maximum length for SQL queries
	AllowedSchemas      []string // List of allowed schemas
	DisallowedKeywords  []string // List of disallowed keywords
	LogSensitiveData    bool     // Whether to log sensitive data
}

SecurityOptions contains security-related configuration

func DefaultSecurityOptions

func DefaultSecurityOptions() SecurityOptions

DefaultSecurityOptions returns default security options

type Statement added in v0.1.0

type Statement struct {
	Query string
	Args  []interface{}
}

Statement represents a SQL statement

func NewStatement added in v0.1.0

func NewStatement(query string, args ...interface{}) *Statement

NewStatement creates a new SQL statement

type StreamParser added in v0.1.0

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

StreamParser handles streaming SQL parsing

func NewStreamParser added in v0.1.0

func NewStreamParser(config StreamParserConfig) *StreamParser

NewStreamParser creates a new stream parser

func (*StreamParser) ParseStream added in v0.1.0

func (sp *StreamParser) ParseStream(ctx context.Context, reader io.Reader) error

ParseStream parses SQL statements from a stream

func (*StreamParser) SetErrorHandler added in v0.1.0

func (sp *StreamParser) SetErrorHandler(handler func(error))

SetErrorHandler sets the error handler function

func (*StreamParser) SetMaxRetries added in v0.1.0

func (sp *StreamParser) SetMaxRetries(maxRetries int)

SetMaxRetries sets the maximum number of retries

func (*StreamParser) SetTimeout added in v0.1.0

func (sp *StreamParser) SetTimeout(timeout time.Duration)

SetTimeout sets the timeout for parsing operations

type StreamParserConfig added in v0.1.0

type StreamParserConfig struct {
	Workers      int           // Number of concurrent workers
	BatchSize    int           // Size of each batch in bytes
	BufferSize   int           // Size of read buffer
	Timeout      time.Duration // Timeout for parsing operations
	MaxRetries   int           // Maximum number of retries for failed operations
	ErrorHandler func(error)   // Custom error handler
	MemOptimizer *MemoryOptimizer
}

StreamParserConfig represents parser configuration

type Table added in v0.1.0

type Table struct {
	Schema      string
	Name        string
	Columns     []*Column
	Constraints []*Constraint
	PrimaryKey  *Constraint
	ForeignKeys []*Constraint
}

Table represents a database table

type Task added in v0.1.0

type Task struct {
	ID        string
	Statement *Statement
	Priority  int
	Timeout   time.Duration
	Status    TaskStatus
	StartTime time.Time
	EndTime   time.Time
	Error     error
}

Task represents a unit of work

type TaskStatus added in v0.1.0

type TaskStatus int32

TaskStatus represents the status of a task

const (
	// Task statuses
	TaskPending TaskStatus = iota
	TaskRunning
	TaskCompleted
	TaskFailed
)

type TransactionManager added in v0.1.0

type TransactionManager interface {
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
	Commit(ctx context.Context) error
	Rollback(ctx context.Context) error
}

TransactionManager transaction operations interface

type TypeConverter

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

TypeConverter handles data type conversions between different database systems

func NewTypeConverter

func NewTypeConverter(sourceDialect, targetDialect string) *TypeConverter

NewTypeConverter creates a new type converter

func (*TypeConverter) AddCustomMapping

func (tc *TypeConverter) AddCustomMapping(sourceType, targetType string)

AddCustomMapping adds a custom type mapping

func (*TypeConverter) Convert

func (tc *TypeConverter) Convert(sourceType string) (string, error)

Convert converts a data type from source dialect to target dialect

func (*TypeConverter) GetSupportedTypes

func (tc *TypeConverter) GetSupportedTypes(dialect string) []string

GetSupportedTypes returns a list of supported types for a given dialect

type TypeMapping added in v0.1.0

type TypeMapping struct {
	SourceType     string
	SourceVersion  *Version
	TargetType     string
	TargetVersion  *Version
	ConversionFunc func(interface{}) (interface{}, error)
	Constraints    []string
}

TypeMapping represents data type mapping between databases

type Version added in v0.1.0

type Version struct {
	Major    int
	Minor    int
	Patch    int
	Metadata string
}

Version represents a database version

type WorkerConfig added in v0.1.0

type WorkerConfig struct {
	Workers      int
	QueueSize    int
	ErrHandler   func(error)
	MemOptimizer *MemoryOptimizer
}

WorkerConfig represents worker pool configuration

type WorkerMetrics added in v0.1.0

type WorkerMetrics struct {
	ActiveWorkers   int32
	CompletedTasks  int32
	FailedTasks     int32
	AverageLatency  time.Duration
	ProcessingTasks int32
	QueueLength     int32
	// contains filtered or unexported fields
}

WorkerMetrics holds worker pool metrics

type WorkerPool added in v0.1.0

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

WorkerPool manages a pool of workers

func NewWorkerPool added in v0.1.0

func NewWorkerPool(config WorkerConfig) *WorkerPool

NewWorkerPool creates a new worker pool

func (*WorkerPool) GetMetrics added in v0.1.0

func (wp *WorkerPool) GetMetrics() *WorkerMetrics

GetMetrics returns current worker pool metrics

func (*WorkerPool) Results added in v0.1.0

func (wp *WorkerPool) Results() <-chan Result

Results returns the results channel

func (*WorkerPool) Start added in v0.1.0

func (wp *WorkerPool) Start(ctx context.Context)

Start starts the worker pool

func (*WorkerPool) Stop added in v0.1.0

func (wp *WorkerPool) Stop()

Stop stops the worker pool

func (*WorkerPool) Submit added in v0.1.0

func (wp *WorkerPool) Submit(task Task) error

Submit submits a task to the pool

func (*WorkerPool) WaitForTasks added in v0.1.0

func (wp *WorkerPool) WaitForTasks(ctx context.Context) error

WaitForTasks waits for all submitted tasks to complete

Jump to

Keyboard shortcuts

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