sqlclient

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: Apache-2.0 Imports: 10 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(name string, opener Opener, opts ...RegisterOption)

Register registers a client Opener (i.e. creator) with the given name.

Types

type Client

type Client struct {
	// Name used when creating the client.
	Name string

	// DB used for creating the client.
	DB *sql.DB
	// URL holds an enriched url.URL.
	URL *URL

	// A migration driver for the attached dialect.
	migrate.Driver

	// Marshal and Evaluator functions for decoding
	// and encoding the schema documents.
	schemaspec.Marshaler
	schemahcl.Evaluator
	// contains filtered or unexported fields
}

Client provides the common functionalities for working with Atlas from different applications (e.g. CLI and TF). Note, the Client is dialect specific and should be instantiated using a call to Open.

func Open

func Open(ctx context.Context, s string) (*Client, error)

Open opens an Atlas client by its provided url string.

func (*Client) AddClosers

func (c *Client) AddClosers(closers ...io.Closer)

AddClosers adds list of closers to close at the end of the client lifetime.

func (*Client) Close

func (c *Client) Close() (err error)

Close closes the underlying database connection and the migration driver in case it implements the io.Closer interface.

type Opener

type Opener interface {
	Open(ctx context.Context, u *url.URL) (*Client, error)
}

Opener opens a migration driver by the given URL.

func DriverOpener

func DriverOpener(open func(schema.ExecQuerier) (migrate.Driver, error)) Opener

DriverOpener is a helper Opener creator for sharing between all drivers.

type OpenerFunc

type OpenerFunc func(context.Context, *url.URL) (*Client, error)

OpenerFunc allows using a function as an Opener.

func (OpenerFunc) Open

func (f OpenerFunc) Open(ctx context.Context, u *url.URL) (*Client, error)

Open calls f(ctx, u).

type RegisterOption

type RegisterOption func(*registerOptions)

RegisterOption allows configuring the Opener registration using functional options.

func RegisterCodec

RegisterCodec registers static codec for attaching into the client after it is opened.

func RegisterFlavours

func RegisterFlavours(flavours ...string) RegisterOption

RegisterFlavours allows registering additional flavours (i.e. names), accepted by Atlas to open clients.

func RegisterURLParser

func RegisterURLParser(p func(*url.URL) *URL) RegisterOption

RegisterURLParser allows registering a function for parsing the url.URL and attach additional info to the extended URL.

type URL

type URL struct {
	*url.URL

	// The DSN used for opening the connection.
	DSN string

	// The Schema this client is connected to.
	Schema string
}

URL extends the standard url.URL with additional connection information attached by the Opener (if any).

Jump to

Keyboard shortcuts

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