bindings

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpenReadWrite = C.SQLITE_OPEN_READWRITE
	OpenReadOnly  = C.SQLITE_OPEN_READONLY
	OpenCreate    = C.SQLITE_OPEN_CREATE
)

Open modes.

View Source
const (
	Integer = C.SQLITE_INTEGER
	Float   = C.SQLITE_FLOAT
	Text    = C.SQLITE_TEXT
	Blob    = C.SQLITE_BLOB
	Null    = C.SQLITE_NULL
)

SQLite datatype codes

View Source
const (
	UnixTime = C.DQLITE_UNIXTIME
	ISO8601  = C.DQLITE_ISO8601
	Boolean  = C.DQLITE_BOOLEAN
)

Special data types for time values.

View Source
const (
	ErrError               = C.SQLITE_ERROR
	ErrInternal            = C.SQLITE_INTERNAL
	ErrNoMem               = C.SQLITE_NOMEM
	ErrInterrupt           = C.SQLITE_INTERRUPT
	ErrBusy                = C.SQLITE_BUSY
	ErrIoErr               = C.SQLITE_IOERR
	ErrIoErrNotLeader      = C.SQLITE_IOERR_NOT_LEADER
	ErrIoErrLeadershipLost = C.SQLITE_IOERR_LEADERSHIP_LOST
)

Error codes.

View Source
const (
	LogDebug = C.DQLITE_LOG_DEBUG
	LogInfo  = C.DQLITE_LOG_INFO
	LogWarn  = C.DQLITE_LOG_WARN
	LogError = C.DQLITE_LOG_ERROR
)

Logging levels.

View Source
const (
	RequestLeader    = C.DQLITE_REQUEST_LEADER
	RequestClient    = C.DQLITE_REQUEST_CLIENT
	RequestHeartbeat = C.DQLITE_REQUEST_HEARTBEAT
	RequestOpen      = C.DQLITE_REQUEST_OPEN
	RequestPrepare   = C.DQLITE_REQUEST_PREPARE
	RequestExec      = C.DQLITE_REQUEST_EXEC
	RequestQuery     = C.DQLITE_REQUEST_QUERY
	RequestFinalize  = C.DQLITE_REQUEST_FINALIZE
	RequestExecSQL   = C.DQLITE_REQUEST_EXEC_SQL
	RequestQuerySQL  = C.DQLITE_REQUEST_QUERY_SQL
	RequestInterrupt = C.DQLITE_REQUEST_INTERRUPT
)

Request types.

View Source
const (
	ResponseFailure = C.DQLITE_RESPONSE_FAILURE
	ResponseServer  = C.DQLITE_RESPONSE_SERVER
	ResponseWelcome = C.DQLITE_RESPONSE_WELCOME
	ResponseServers = C.DQLITE_RESPONSE_SERVERS
	ResponseDb      = C.DQLITE_RESPONSE_DB
	ResponseStmt    = C.DQLITE_RESPONSE_STMT
	ResponseResult  = C.DQLITE_RESPONSE_RESULT
	ResponseRows    = C.DQLITE_RESPONSE_ROWS
	ResponseEmpty   = C.DQLITE_RESPONSE_EMPTY
)

Response types.

WAL checkpoint modes

View Source
const ProtocolVersion = uint64(C.DQLITE_PROTOCOL_VERSION)

ProtocolVersion is the latest dqlite server protocol version.

Variables

View Source
var ErrServerStopped = fmt.Errorf("server was stopped")

ErrServerStopped is returned by Server.Handle() is the server was stopped.

Functions

func AssertNoMemoryLeaks

func AssertNoMemoryLeaks(t *testing.T)

AssertNoMemoryLeaks is a test helper asserting that current allocation count and used memory are both zero.

func ErrorCode

func ErrorCode(err error) int

ErrorCode extracts a SQLite error code from a Go error.

func Init

func Init() error

Init initializes dqlite global state.

func StatusMallocCount

func StatusMallocCount(reset bool) (int, int, error)

StatusMallocCount returns the current and highest number of memory allocations performed with sqlite3_malloc.

func StatusMemoryUsed

func StatusMemoryUsed(reset bool) (int, int, error)

StatusMemoryUsed returns the current and highest allocation size.

Types

type Cluster

type Cluster C.dqlite_cluster

Cluster is a Go wrapper around the associated dqlite's C type.

func NewCluster

func NewCluster(methods ClusterMethods) (*Cluster, error)

NewCluster creates a new Cluster object set with the given method hooks..

func (*Cluster) Close

func (c *Cluster) Close()

Close releases all memory associated with the cluster object.

type ClusterMethods

type ClusterMethods interface {
	// Return the address of the current cluster leader, if any. If not
	// empty, the address string must a be valid network IP or hostname,
	// that clients can use to connect to a dqlite service.
	Leader() string

	// If this driver is the current leader of the cluster, return the
	// addresses of all other servers. Each address must be a valid IP or
	// host name name, that clients can use to connect to the relevant
	// dqlite service , in case the current leader is deposed and a new one
	// is elected.
	//
	// If this driver is not the current leader of the cluster, an error
	// implementing the Error interface below and returning true in
	// NotLeader() must be returned.
	Servers() ([]ServerInfo, error)

	Register(*Conn)
	Unregister(*Conn)

	Barrier() error

	Recover(token uint64) error

	Checkpoint(*Conn) error
}

ClusterMethods implements the interface required by the various hooks dqlite_cluster.

type Conn

type Conn C.sqlite3

Conn is a Go wrapper around a SQLite database handle.

func Open

func Open(name string, vfs string) (*Conn, error)

Open a SQLite connection.

func (*Conn) Close

func (c *Conn) Close() error

Close the connection.

func (*Conn) ConfigNoCkptOnClose

func (c *Conn) ConfigNoCkptOnClose(flag bool) (bool, error)

ConfigNoCkptOnClose switches on or off the automatic WAL checkpoint when a connection is closed.

func (*Conn) Exec

func (c *Conn) Exec(query string) error

Exec executes a query.

func (*Conn) Filename

func (c *Conn) Filename() string

Filename of the underlying database file.

func (*Conn) Query

func (c *Conn) Query(query string) (*Rows, error)

Query the database.

func (*Conn) WalCheckpoint

func (c *Conn) WalCheckpoint(schema string, mode WalCheckpointMode) (int, int, error)

WalCheckpoint triggers a WAL checkpoint on the given database attached to the connection. See https://sqlite.org/c3ref/wal_checkpoint_v2.html

func (*Conn) WalReplicationFollower

func (c *Conn) WalReplicationFollower() error

WalReplicationFollower switches the given SQLite connection to follower WAL replication mode. In this mode no regular operation is possible, and the connection should be driven with the WalReplicationFrames, and WalReplicationUndo APIs.

func (*Conn) WalReplicationFrames

func (c *Conn) WalReplicationFrames(info WalReplicationFrameInfo) error

WalReplicationFrames writes the given batch of frames to the write-ahead log linked to the given connection.

This method must be called with a "follower" connection, meant to replicate the "leader" one.

func (*Conn) WalReplicationLeader

func (c *Conn) WalReplicationLeader(name string) error

WalReplicationLeader switches the SQLite connection to leader WAL replication mode.

func (*Conn) WalReplicationUndo

func (c *Conn) WalReplicationUndo() error

WalReplicationUndo rollbacks a write transaction in the given sqlite connection. This should be called with a "follower" connection, meant to replicate the "leader" one.

type Error

type Error struct {
	Code    int
	Message string
}

Error holds information about a SQLite error.

func (Error) Error

func (e Error) Error() string

type FrameNumber

type FrameNumber C.unsigned

FrameNumber identifies a single frame in the WAL.

type Logger

type Logger C.dqlite_logger

Logger is a Go wrapper around the associated dqlite's C type.

func NewLogger

func NewLogger(f logging.Func) *Logger

NewLogger creates a new Logger object set with the given log function.

func (*Logger) Close

func (l *Logger) Close()

Close releases all memory associated with the logger object.

type PageNumber

type PageNumber C.unsigned

PageNumber identifies a single database or WAL page.

type Rows

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

Rows represents a result set.

func (*Rows) Close

func (r *Rows) Close() error

Close finalizes the underlying statement.

func (*Rows) Next

func (r *Rows) Next(values []driver.Value) error

Next fetches the next row of a result set.

type Server

type Server C.dqlite_server

Server is a Go wrapper arround dqlite_server.

func NewServer

func NewServer(cluster *Cluster) (*Server, error)

NewServer creates a new Server instance.

func (*Server) Close

func (s *Server) Close()

Close the server releasing all used resources.

func (*Server) Handle

func (s *Server) Handle(conn net.Conn) error

Handle a new connection.

func (*Server) Ready

func (s *Server) Ready() bool

Ready waits for the server to be ready to handle connections.

func (*Server) Run

func (s *Server) Run() error

Run the server.

After this method is called it's possible to invoke Handle().

func (*Server) SetLogger

func (s *Server) SetLogger(logger *Logger)

SetLogger sets the server logger.

func (*Server) SetVfs

func (s *Server) SetVfs(name string)

SetVfs sets the name of the VFS to use for new connections.

func (*Server) SetWalReplication

func (s *Server) SetWalReplication(name string)

SetWalReplication sets the name of the WAL replication to use for new connections.

func (*Server) Stop

func (s *Server) Stop() error

Stop the server.

type ServerInfo

type ServerInfo struct {
	ID      uint64
	Address string
}

ServerInfo is the Go equivalent of dqlite_server_info.

type Vfs

type Vfs C.sqlite3_vfs

Vfs is a Go wrapper around dqlite's in-memory VFS implementation.

func NewVfs

func NewVfs(name string, logger *Logger) (*Vfs, error)

NewVfs registers an in-memory VFS instance under the given name.

func (*Vfs) Close

func (v *Vfs) Close() error

Close unregisters this in-memory VFS instance.

func (*Vfs) Name

func (v *Vfs) Name() string

Name returns the registration name of the vfs.

func (*Vfs) ReadFile

func (v *Vfs) ReadFile(filename string) ([]byte, error)

ReadFile returns the content of the given filename.

func (*Vfs) WriteFile

func (v *Vfs) WriteFile(filename string, bytes []byte) error

WriteFile write the content of the given filename, overriding it if it exists.

type WalCheckpointMode

type WalCheckpointMode int

WalCheckpointMode defines all valid values for the "checkpoint mode" parameter of the WalCheckpointV2 API. See https://sqlite.org/c3ref/wal_checkpoint_v2.html.

type WalReplication

type WalReplication C.sqlite3_wal_replication

WalReplication is a Go wrapper around the associated SQLite's C type.

func NewWalReplication

func NewWalReplication(name string, methods WalReplicationMethods) (*WalReplication, error)

NewWalReplication registers a WAL replication instance under the given name.

func (*WalReplication) Close

func (r *WalReplication) Close() error

Close unregisters and destroys this WAL replication instance.

func (*WalReplication) Name

func (r *WalReplication) Name() string

Name returns the registration name of the Wal replication.

type WalReplicationFrameInfo

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

WalReplicationFrameInfo information about a single batch of WAL frames that are being replicated by a follower connection.

func (*WalReplicationFrameInfo) IsBegin

func (i *WalReplicationFrameInfo) IsBegin(flag bool)

IsBegin sets the C isBegin parameter for sqlite3_wal_replication_frames.

func (*WalReplicationFrameInfo) IsCommit

func (i *WalReplicationFrameInfo) IsCommit(flag bool)

IsCommit sets the isCommit parameter for sqlite3_wal_replication_frames.

func (*WalReplicationFrameInfo) IsCommitGet

func (i *WalReplicationFrameInfo) IsCommitGet() bool

func (*WalReplicationFrameInfo) Len

func (i *WalReplicationFrameInfo) Len(n int)

Len sets the C nFrame parameter for sqlite3_wal_replication_frames.

func (*WalReplicationFrameInfo) PageSize

func (i *WalReplicationFrameInfo) PageSize(size int)

PageSize sets the C szPage parameter for sqlite3_wal_replication_frames.

func (*WalReplicationFrameInfo) Pages

func (i *WalReplicationFrameInfo) Pages(numbers []PageNumber, data unsafe.Pointer)

Pages sets the C aPgno and aPage parameters for sqlite3_wal_replication_frames.

func (*WalReplicationFrameInfo) Truncate

func (i *WalReplicationFrameInfo) Truncate(truncate uint)

Truncate sets the nTruncate parameter for sqlite3_wal_replication_frames.

type WalReplicationFrameList

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

WalReplicationFrameList holds information about a single batch of WAL frames that are being dispatched for replication by a leader connection.

They map to the parameters of the sqlite3_wal_replication.xFrames API

func (*WalReplicationFrameList) Frame

Frame returns information about the i'th frame in the batch.

func (*WalReplicationFrameList) IsCommit

func (l *WalReplicationFrameList) IsCommit() bool

IsCommit returns whether this batch of WAL frames concludes a transaction.

func (*WalReplicationFrameList) Len

func (l *WalReplicationFrameList) Len() int

Len returns the number of WAL frames in this batch.

func (*WalReplicationFrameList) PageSize

func (l *WalReplicationFrameList) PageSize() int

PageSize returns the page size of this batch of WAL frames.

func (*WalReplicationFrameList) Truncate

func (l *WalReplicationFrameList) Truncate() uint

Truncate returns the size of the database in pages after this batch of WAL frames is applied.

type WalReplicationMethods

type WalReplicationMethods interface {
	// Begin a new write transaction. The implementation should check
	// that the database is eligible for starting a replicated write
	// transaction (e.g. this node is the leader), and perform internal
	// state changes as appropriate.
	Begin(*Conn) int

	// Abort a write transaction. The implementation should clear any
	// state previously set by the Begin hook.
	Abort(*Conn) int

	// Write new frames to the write-ahead log. The implementation should
	// broadcast this write to other nodes and wait for a quorum.
	Frames(*Conn, WalReplicationFrameList) int

	// Undo a write transaction. The implementation should broadcast
	// this event to other nodes and wait for a quorum. The return code
	// is currently ignored by SQLite.
	Undo(*Conn) int

	// End a write transaction. The implementation should update its
	// internal state and be ready for a new transaction.
	End(*Conn) int
}

WalReplicationMethods implements the interface required by the various hooks of sqlite3_wal_replication.

Jump to

Keyboard shortcuts

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