crdbutil

package
v0.0.0-...-4ed88a5 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultPort is the default port on which crdb runs.
	DefaultPort = 26257
	// RootUser is the default user for crdb.
	RootUser = "root"
	// RkOwner is the database user that has DDL access to all DBs
	RkOwner = "rk_owner"
	// RkUser is the database user that has DML access to all DBs
	RkUser = "rk_user"
	// ConnectTimeoutSeconds to establish a connection
	ConnectTimeoutSeconds = "10"
)

Variables

This section is empty.

Functions

func CreateDatabaseIfNotExists

func CreateDatabaseIfNotExists(
	socketAddr SocketAddress, dbName string, certsDir string, insecure bool,
) error

CreateDatabaseIfNotExists creates a fresh database dbName in the DB at socketAddr, if it doesn't already exist. It also grants DDL privileges to rk_owner, and DML privileges to rk_user. It connects to the DB as root user.

func DropAndCreateDatabase

func DropAndCreateDatabase(
	socketAddr SocketAddress, dbName string, certsDir string, insecure bool,
) error

DropAndCreateDatabase creates a fresh database dbName in the DB at socketAddr, dropping any existing database of the same name. It also grants DDL privileges to rk_owner, and DML privileges to rk_user. It connects to the DB as root user.

func NewDBForTest

func NewDBForTest(t *testing.T) (*sql.DB, func())

NewDBForTest creates a testing SQL db connection using cockroachdb testserver. This function assumes that a cockroach binary is present in src/go/bin. Returns a sql *DB instance, and a shutdown function. The caller is responsible for executing the returned shutdown function on exit.

func NewTestServer

func NewTestServer(t *testing.T) (*testserver.TestServer, error)

NewTestServer creates a new TestServer, but does not start it. This function assumes that a cockroach binary is present in src/go/bin.

Types

type DBURLParams

type DBURLParams struct {
	SocketAddr         SocketAddress
	DbName             string
	User               string
	Insecure           bool
	CertsDir           string
	SocketReadTimeout  time.Duration
	SocketWriteTimeout time.Duration
}

DBURLParams captures values for various params required to connect to CockroachDB

func DeclareCockroachDbURLFlags

func DeclareCockroachDbURLFlags(f *flag.FlagSet) *DBURLParams

DeclareCockroachDbURLFlags declares flags necessary for passing all information relevant to connecting to CockroachDB

func (DBURLParams) URL

func (p DBURLParams) URL() (*url.URL, error)

URL returns the url built from p. It performs basic validation on all parameters, and returns an error in case some validation fails.

type SocketAddress

type SocketAddress struct {
	Host string
	Port int
}

A SocketAddress represents the combination of an ip address and a port.

func ParseSocketAddress

func ParseSocketAddress(s string) (SocketAddress, error)

ParseSocketAddress returns the SocketAddress represented by s, which should be formatted as as "<ip>:<port>". If port mapping is not given, default port is assumed

func (SocketAddress) String

func (s SocketAddress) String() string

Jump to

Keyboard shortcuts

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