driver

package
v0.0.0-...-cdc0bb7 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 30 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package driver is CockroachDB's implementation of the driver contract in github.com/bytebase/omni/driver: it connects through pgx, the wire protocol CockroachDB speaks, syncs a server's catalogs into omni/metadata, dumps the server's own DDL, and runs interactive queries and change scripts.

CockroachDB is not an alias of pg. Its wire protocol is PostgreSQL's, but what it stores, reports and plans with is its own: pg_database has no owner in the sync, system databases are postgres and system rather than template0/template1, pg_relation_size does not exist, pg_matviews is populated by CockroachDB's materialized views, indexes come from pg_indexes, and EXPLAIN has CockroachDB's option list (DISTSQL) rather than PostgreSQL's FORMAT. Its EXPLAIN also carries the only machine-readable plan it publishes behind the diagram link it prints, so the query path decodes that. The sync, stats and query code here is therefore its own, not pg's, even though Bytebase dispatches the engine as a pg-family engine for parsing.

Open does not reach the server; Ping does.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExplainFormats

func ExplainFormats() []string

ExplainFormats returns the QueryOptions.ExplainFormat values Session.Query plans in, in the order a caller offers them.

func SyncDatabase

func SyncDatabase(ctx context.Context, db *sql.DB, databaseName string) (*metadatapb.DatabaseSchemaMetadata, error)

SyncDatabase reads the schema of databaseName through db, a connection to it the caller opened. The Driver method is this on its own pool; a caller that owns a connection, such as a catalog fidelity test, calls this.

Types

type Driver

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

Driver is an open CockroachDB driver: a pool of connections to one database.

func Open

func Open(_ context.Context, cfg driver.Config) (*Driver, error)

Open returns a driver for the server and database cfg names. Open does not reach the server; Ping does.

func (*Driver) Activity

func (d *Driver) Activity(ctx context.Context, applicationName string) (*driver.Activity, error)

Activity reads the query running under applicationName from CockroachDB's own catalog. Its pg_stat_activity view answers no rows and it has no pg_blocking_pids, so PostgreSQL's query does not apply.

func (*Driver) Close

func (d *Driver) Close() error

Close closes the driver's connections.

func (*Driver) CountAffectedRows

func (d *Driver) CountAffectedRows(ctx context.Context, statement string) (int64, error)

CountAffectedRows returns the optimizer's estimate of the rows the statement modifies. A search path that Bytebase put before the statement ("SET LOCAL search_path TO ...;\n") is set for the EXPLAIN.

func (*Driver) Dump

Dump writes the database's DDL as CockroachDB states it. The server's own SHOW CREATE answers are the only DDL CockroachDB publishes for its objects, and the caller's metadata narrows nothing: the parameter is the contract's, not a source of text. Zone configurations are cluster configuration, which SHOW CREATE ALL TABLES leaves out and neither the dump nor the sync keeps.

func (*Driver) Execute

func (d *Driver) Execute(ctx context.Context, script string, opts driver.ExecuteOptions) (int64, error)

Execute runs script under opts.Transaction, reporting each step to opts.Log when non-nil and returning the total affected rows.

func (*Driver) GetCurrentDatabaseOwner

func (d *Driver) GetCurrentDatabaseOwner(ctx context.Context) (string, error)

GetCurrentDatabaseOwner gets the role of the current database.

func (*Driver) Ping

func (d *Driver) Ping(ctx context.Context) error

Ping reaches the server.

func (*Driver) Session

func (d *Driver) Session(ctx context.Context) (driver.Session, error)

Session opens one server connection held until Close, so session state such as search_path and TimeZone persists across Query calls.

func (*Driver) SyncDatabase

func (d *Driver) SyncDatabase(ctx context.Context) (*metadatapb.DatabaseSchemaMetadata, error)

SyncDatabase reads the schema of the database the driver is connected to.

func (*Driver) SyncInstance

func (d *Driver) SyncInstance(ctx context.Context) (*driver.Instance, error)

SyncInstance reads the server version, its databases other than the system ones, and its roles.

Jump to

Keyboard shortcuts

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