db

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package db provides the interfaces and libraries for database driver plugins.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(dbType storepb.Engine, f driverFunc)

Register makes a database driver available by the provided type. If Register is called twice with the same name or if driver is nil, it panics.

Types

type ColumnKey

type ColumnKey struct {
	Schema string
	Table  string
	Column string
}

ColumnKey is the map key for table metadata.

type ConnectionConfig

type ConnectionConfig struct {
	DataSource        *storepb.DataSource
	ConnectionContext ConnectionContext
	Password          string
}

ConnectionConfig is the configuration for connections.

type ConnectionContext

type ConnectionContext struct {
	EnvironmentID string
	InstanceID    string
	EngineVersion string
	// UseDatabaseOwner is used by Postgres for using role of database owner.
	UseDatabaseOwner bool
	DatabaseName     string
	// It's only set for Redshift datashare database.
	DataShare bool
	// ReadOnly is only supported for Postgres at the moment.
	ReadOnly bool
}

ConnectionContext is the context for connection. It's not used for establishing the db connection, but is useful for logging.

type ConstraintKey

type ConstraintKey struct {
	Schema     string
	Constraint string
}

type Driver

type Driver interface {
	// General execution
	// A driver might support multiple engines (e.g. MySQL driver can support both MySQL and TiDB),
	// So we pass the dbType to tell the exact engine.
	Open(ctx context.Context, dbType storepb.Engine, config ConnectionConfig) (Driver, error)
	// Remember to call Close to avoid connection leak
	Close(ctx context.Context) error
	Ping(ctx context.Context) error
	GetDB() *sql.DB

	// Sync schema
	// SyncInstance syncs the instance metadata.
	SyncInstance(ctx context.Context) (*InstanceMetadata, error)
	// SyncDBSchema syncs a single database schema. A database the target no
	// longer has must be reported as common.NotFound (not as a plain error), so a
	// caller can mirror the target's inventory instead of guessing from the
	// message; every other failure keeps its own error.
	SyncDBSchema(ctx context.Context) (*storepb.DatabaseSchemaMetadata, error)
}

Driver is the interface for database driver.

func Open

func Open(ctx context.Context, dbType storepb.Engine, connectionConfig ConnectionConfig) (Driver, error)

Open opens a database specified by its database driver type and connection config without verifying the connection.

type IndexKey

type IndexKey struct {
	Schema string
	Table  string
	Index  string
}

IndexKey is the map key for table metadata.

type InstanceMetadata

type InstanceMetadata struct {
	Version string
	// Simplified database metadata.
	Databases []*storepb.DatabaseSchemaMetadata
	Metadata  *storepb.Instance
}

InstanceMetadata is the metadata for an instance.

type MigrationStatus

type MigrationStatus string

MigrationStatus is the status of migration.

const (
	// Pending is the migration status for PENDING.
	Pending MigrationStatus = "PENDING"
	// Done is the migration status for DONE.
	Done MigrationStatus = "DONE"
	// Failed is the migration status for FAILED.
	Failed MigrationStatus = "FAILED"
)

type ObjectDefinitionReader

type ObjectDefinitionReader interface {
	// GetObjectDefinition returns the DDL of the named object. ok is false when
	// this engine has no definition for that object type; the caller then falls
	// back to reconstruction.
	GetObjectDefinition(ctx context.Context, objectType storepb.MetaType, name string) (definition string, ok bool, err error)
}

ObjectDefinitionReader is an optional capability: a driver that implements it can return the engine's own DDL for an object instead of having it reconstructed from metadata. Reconstruction is lossy for engines whose DDL carries properties the metadata does not model (StarRocks distribution, properties, partitioning), so the syncer prefers this when available.

type SequenceKey

type SequenceKey struct {
	Schema   string
	Sequence string
}

type TableKey

type TableKey struct {
	Schema string
	Table  string
}

TableKey is the map key for table metadata.

type TableKeyWithColumns

type TableKeyWithColumns struct {
	Schema  string
	Table   string
	Columns []*storepb.ColumnMetadata
}

Directories

Path Synopsis
Package mssql is the plugin for MSSQL driver.
Package mssql is the plugin for MSSQL driver.
Package mysql is the plugin for MySQL driver.
Package mysql is the plugin for MySQL driver.
Package pg is the plugin for PostgreSQL driver.
Package pg is the plugin for PostgreSQL driver.
Package starrocks is the plugin for the StarRocks and Doris drivers.
Package starrocks is the plugin for the StarRocks and Doris drivers.

Jump to

Keyboard shortcuts

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