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 ¶
- func ExplainFormats() []string
- func SyncDatabase(ctx context.Context, db *sql.DB, databaseName string) (*metadatapb.DatabaseSchemaMetadata, error)
- type Driver
- func (d *Driver) Activity(ctx context.Context, applicationName string) (*driver.Activity, error)
- func (d *Driver) Close() error
- func (d *Driver) CountAffectedRows(ctx context.Context, statement string) (int64, error)
- func (d *Driver) Dump(ctx context.Context, w io.Writer, _ *metadatapb.DatabaseSchemaMetadata) error
- func (d *Driver) Execute(ctx context.Context, script string, opts driver.ExecuteOptions) (int64, error)
- func (d *Driver) GetCurrentDatabaseOwner(ctx context.Context) (string, error)
- func (d *Driver) Ping(ctx context.Context) error
- func (d *Driver) Session(ctx context.Context) (driver.Session, error)
- func (d *Driver) SyncDatabase(ctx context.Context) (*metadatapb.DatabaseSchemaMetadata, error)
- func (d *Driver) SyncInstance(ctx context.Context) (*driver.Instance, error)
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 ¶
Open returns a driver for the server and database cfg names. Open does not reach the server; Ping does.
func (*Driver) Activity ¶
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) CountAffectedRows ¶
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 ¶
func (d *Driver) Dump(ctx context.Context, w io.Writer, _ *metadatapb.DatabaseSchemaMetadata) error
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 ¶
GetCurrentDatabaseOwner gets the role of the current database.
func (*Driver) Session ¶
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.