Documentation
¶
Index ¶
- func SanitizeDSN(driver, dsn string) string
- type ConnectionConfig
- type Connector
- type CountRequest
- type DeleteRequest
- type Factory
- type InsertRequest
- type QueryExecutor
- type Registry
- func (r *Registry) CloseAll()
- func (r *Registry) Connect(serviceName string, cfg ConnectionConfig) error
- func (r *Registry) Disconnect(serviceName string) error
- func (r *Registry) Get(serviceName string) (Connector, error)
- func (r *Registry) ListServices() []string
- func (r *Registry) RegisterDriver(driver string, factory Factory)
- type SchemaChange
- type SelectRequest
- type UpdateRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SanitizeDSN ¶
SanitizeDSN ensures that URL-style DSNs (postgres://, sqlserver://) have their userinfo (especially the password) properly percent-encoded. Raw passwords containing @, #, %, or other URL-special characters cause the Go URL parser to mis-split the authority component, leading to connection failures that surface as "Service not found" because the connector never registers in the live registry.
MySQL DSNs are normalized to use the tcp() wrapper required by go-sql-driver. Snowflake uses its own non-URL DSN format and is returned unchanged.
Types ¶
type ConnectionConfig ¶
type ConnectionConfig struct {
Driver string
DSN string
SchemaName string
MaxOpenConns int
MaxIdleConns int
ConnMaxLifetime time.Duration
ConnMaxIdleTime time.Duration
PrivateKeyPath string // Path to PEM-encoded private key file (Snowflake JWT auth)
}
ConnectionConfig holds database connection parameters.
type Connector ¶
type Connector interface {
// Connection management
Connect(cfg ConnectionConfig) error
Disconnect() error
Ping(ctx context.Context) error
DB() *sqlx.DB
BeginTx(ctx context.Context, opts *sql.TxOptions) (*sqlx.Tx, error)
// Schema introspection
IntrospectSchema(ctx context.Context) (*model.Schema, error)
IntrospectTable(ctx context.Context, tableName string) (*model.TableSchema, error)
GetTableNames(ctx context.Context) ([]string, error)
GetStoredProcedures(ctx context.Context) ([]model.StoredProcedure, error)
// Query building (database-specific SQL dialect)
BuildSelect(ctx context.Context, req SelectRequest) (string, []interface{}, error)
BuildInsert(ctx context.Context, req InsertRequest) (string, []interface{}, error)
BuildUpdate(ctx context.Context, req UpdateRequest) (string, []interface{}, error)
BuildDelete(ctx context.Context, req DeleteRequest) (string, []interface{}, error)
BuildCount(ctx context.Context, req CountRequest) (string, []interface{}, error)
// Schema modification
CreateTable(ctx context.Context, def model.TableSchema) error
AlterTable(ctx context.Context, tableName string, changes []SchemaChange) error
DropTable(ctx context.Context, tableName string) error
// Stored procedures
CallProcedure(ctx context.Context, name string, params map[string]interface{}) ([]map[string]interface{}, error)
// Metadata
DriverName() string
QuoteIdentifier(name string) string
SupportsReturning() bool
SupportsUpsert() bool
ParameterPlaceholder(index int) string
}
Connector is the interface that all database connectors must implement.
type CountRequest ¶
CountRequest represents a count query.
type DeleteRequest ¶
DeleteRequest represents a delete operation.
type Factory ¶
type Factory func() Connector
Factory is a function that creates a new Connector instance.
type InsertRequest ¶
InsertRequest represents an insert operation.
type QueryExecutor ¶ added in v0.1.5
type QueryExecutor interface {
QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row
}
QueryExecutor is the common interface satisfied by both *sqlx.DB and *sqlx.Tx, allowing handlers to execute queries transparently inside or outside a transaction.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages connector factories and active connections.
func (*Registry) Connect ¶
func (r *Registry) Connect(serviceName string, cfg ConnectionConfig) error
Connect creates a new connector for the given driver and connects it.
func (*Registry) Disconnect ¶
Disconnect removes and disconnects a service.
func (*Registry) ListServices ¶
ListServices returns active service names.
func (*Registry) RegisterDriver ¶
RegisterDriver registers a connector factory for a driver type.
type SchemaChange ¶
type SchemaChange struct {
Type string // "add_column", "drop_column", "rename_column", "modify_column"
Column string
NewName string // for rename
Definition *model.Column // for add/modify
}
SchemaChange represents a table alteration.
type SelectRequest ¶
type SelectRequest struct {
Table string
Fields []string
Filter string
FilterArgs []interface{}
Order string
Limit int
Offset int
Cursor string
}
SelectRequest represents a query for records.
type UpdateRequest ¶
type UpdateRequest struct {
Table string
Filter string
FilterArgs []interface{}
Record map[string]interface{}
IDs []interface{} // for updating by primary key
}
UpdateRequest represents an update operation.