embedded

package module
v0.0.0-...-ffb2190 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: Apache-2.0 Imports: 20 Imported by: 2

README

Dolt Database Driver

This package provides a driver to be used with the database/sql package for database access in Golang. For details of the database/sql package see this tutorial. Below I will cover things that are specific to using dolt with this database driver.

Ways to Set up a Dolt Database

Create a directory to house one or more dolt databases. Once this is created we'll create a directory for our first database using the dolt cli

mkdir dbs
mkdir dbs/testdb
cd dbs/testdb
dolt init

Alternatively you could clone a database from dolthub or a different remote:

mkdir dbs
cd dbs
dolt clone <REMOTE URL>

Finally you can create the dbs directory as shown above and then create the database in code using a SQL CREATE TABLE statement

Connecting to the Database

First we'll import the dolt driver so that it will be registered

_ "github.com/dolthub/driver"

Then we will open a connection to the database:

db, err := sql.Open("dolt", "file:///path/to/dbs?commitname=Your%20Name&commitemail=your@email.com&database=databasename")

Now you can use your db as you would normally, however you have access to all of dolt's special features as well.

Dolt Data Source Names

The Dolt driver requires a DSN containing the directory where your databases live, and the name and email that are used in the commit log.

commitname - The name of the committer seen in the dolt commit log
commitemail - The email of the committer seen in the dolt commit log
database - The initial database to connect to
Example DSN

file:///path/to/dbs?commitname=Your%20Name&commitemail=your@email.com&database=databasename

Documentation

Index

Constants

View Source
const (
	DoltDriverName = "dolt"

	CommitNameParam      = "commitname"
	CommitEmailParam     = "commitemail"
	DatabaseParam        = "database"
	MultiStatementsParam = "multistatements"
)

Variables

This section is empty.

Functions

func LoadMultiEnvFromDir

func LoadMultiEnvFromDir(
	ctx context.Context,
	cfg config.ReadWriteConfig,
	fs filesys.Filesys,
	path, version string,
) (*env.MultiRepoEnv, error)

LoadMultiEnvFromDir looks at each subfolder of the given path as a Dolt repository and attempts to return a MultiRepoEnv with initialized environments for each of those subfolder data repositories. subfolders whose name starts with '.' are skipped.

Types

type DoltConn

type DoltConn struct {
	DataSource *DoltDataSource
	// contains filtered or unexported fields
}

DoltConn is a driver.Conn implementation that represents a connection to a dolt database located on the filesystem

func (*DoltConn) Begin deprecated

func (d *DoltConn) Begin() (driver.Tx, error)

Begin starts and returns a new transaction.

Deprecated: Use BeginTx instead

func (*DoltConn) BeginTx

func (d *DoltConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error)

BeginTx starts and returns a new transaction. If the context is canceled by the user the sql package will call Tx.Rollback before discarding and closing the connection.

func (*DoltConn) Close

func (d *DoltConn) Close() error

Close releases the resources held by the DoltConn instance

func (*DoltConn) Prepare

func (d *DoltConn) Prepare(query string) (driver.Stmt, error)

Prepare returns a prepared statement, bound to this connection.

type DoltDataSource

type DoltDataSource struct {
	Directory string
	Params    map[string][]string
}

DoltDataSource provides access to the data provided by the connection string

func ParseDataSource

func ParseDataSource(dataSource string) (*DoltDataSource, error)

ParseDataSource takes the connection string and parses out the parameters and the local filesys directory where the dolt database lives

func (*DoltDataSource) ParamIsTrue

func (ds *DoltDataSource) ParamIsTrue(paramName string) bool

type QuerySplitter

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

func NewQuerySplitter

func NewQuerySplitter(str string) *QuerySplitter

func (*QuerySplitter) HasMore

func (qs *QuerySplitter) HasMore() bool

func (*QuerySplitter) Next

func (qs *QuerySplitter) Next() (string, error)

type RuneStack

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

RuneStack is a simple stack of runes

func NewByteStack

func NewByteStack() *RuneStack

NewByteStack returns a new RuneStack object

func (*RuneStack) Peek

func (bs *RuneStack) Peek() rune

Peek returns the value at the top of the stack

func (*RuneStack) Pop

func (bs *RuneStack) Pop() rune

Pop takes the top value of the top of the stack and returns it

func (*RuneStack) Push

func (bs *RuneStack) Push(b rune)

Push pushes a new rune on the stack

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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