rqlite

package
v4.0.0-...-cd40650 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 11 Imported by: 0

README

rqlite

rqlite://admin:secret@server1.example.com:4001/?level=strong&timeout=5

The rqlite url scheme is used for both secure and insecure connections. If connecting to an insecure database, pass x-connect-insecure in your URL query, or use WithInstance to pass an established connection.

The migrations table name is configurable through the x-migrations-table URL query parameter, or by using WithInstance and passing MigrationsTable through Config.

Other connect parameters are directly passed through to the database driver. For examples of connection strings, see https://github.com/rqlite/gorqlite#examples.

URL Query WithInstance Config Description
x-connect-insecure n/a: set on instance Boolean to indicate whether to use an insecure connection. Defaults to false.
x-migrations-table MigrationsTable Name of the migrations table. Defaults to schema_migrations.

Notes

Documentation

Index

Constants

View Source
const (
	// DefaultMigrationsTable defines the default rqlite migrations table
	DefaultMigrationsTable = "schema_migrations"

	// DefaultConnectInsecure defines the default setting for connect insecure
	DefaultConnectInsecure = false
)

Variables

View Source
var ErrBadConfig = fmt.Errorf("bad parameter")

ErrBadConfig is returned if configuration was invalid

View Source
var ErrNilConfig = fmt.Errorf("no config")

ErrNilConfig is returned if no configuration was passed to WithInstance

Functions

func OpenURL

func OpenURL(url string) (database.Driver, error)

OpenURL creates a rqlite database driver from a connect URL

func WithInstance

func WithInstance(instance *gorqlite.Connection, config *Config) (database.Driver, error)

WithInstance creates a rqlite database driver with an existing gorqlite database connection and a Config struct

Types

type Config

type Config struct {
	// ConnectInsecure sets whether the connection uses TLS. Ineffectual when using WithInstance
	ConnectInsecure bool
	// MigrationsTable configures the migrations table name
	MigrationsTable string
}

Config defines the driver configuration

type Rqlite

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

func (*Rqlite) Close

func (r *Rqlite) Close() error

Close closes the underlying database instance managed by the driver. Migrate will call this function only once per instance.

func (*Rqlite) Drop

func (r *Rqlite) Drop() error

Drop deletes everything in the database. Note that this is a breaking action, a new call to Open() is necessary to ensure subsequent calls work as expected.

func (*Rqlite) Lock

func (r *Rqlite) Lock() error

Lock should acquire a database lock so that only one migration process can run at a time. Migrate will call this function before Run is called. If the implementation can't provide this functionality, return nil. Return database.ErrLocked if database is already locked.

func (*Rqlite) Open

func (r *Rqlite) Open(url string) (database.Driver, error)

Open returns a new driver instance configured with parameters coming from the URL string. Migrate will call this function only once per instance.

func (*Rqlite) Run

func (r *Rqlite) Run(migration io.Reader) error

Run applies a migration to the database. migration is guaranteed to be not nil.

func (*Rqlite) SetVersion

func (r *Rqlite) SetVersion(version int, dirty bool) error

SetVersion saves version and dirty state. Migrate will call this function before and after each call to Run. version must be >= -1. -1 means NilVersion.

func (*Rqlite) Unlock

func (r *Rqlite) Unlock() error

Unlock should release the lock. Migrate will call this function after all migrations have been run.

func (*Rqlite) Version

func (r *Rqlite) Version() (version int, dirty bool, err error)

Version returns the currently active version and if the database is dirty. When no migration has been applied, it must return version -1. Dirty means, a previous migration failed and user interaction is required.

Jump to

Keyboard shortcuts

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