gorqlite

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

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 14 Imported by: 64

README

gorqlite — a Go client for rqlite

Circle CI

gorqlite is a Go client for rqlite. It hides the HTTP/JSON details and exposes a small API specialized for rqlite, plus a thin database/sql driver.

The main API mirrors a subset of database/sql semantics — Open(), Query()/QueryOne(), Next()/Scan()/Map(), Write()/WriteOne() — without pretending to be a full database/sql driver.

Looking for an even smaller wrapper? See rqlite/rqlite-go-http.

Status

Used in production by various groups, including Replicated.

Features

  • Speaks rqlite's HTTP API for you: POSTs, JSON, parameterized statements, the unified /db/request endpoint, and queued writes.
  • Iterator with database/sql-style ergonomics (Next(), Scan(), Map()), plus typed Null* wrappers (NullString, NullInt64, …).
  • Per-result metadata: timing, rows affected, last insert id.
  • Cluster discovery: gorqlite probes /status (and /nodes on rqlite 6+) so you only need to point at one node. Failed requests are retried against the rest of the cluster.
  • Disable discovery with ?disableClusterDiscovery=true on the connection URL — useful when a load balancer (e.g. a Kubernetes Service) already handles peer selection.
  • URL-style connection strings with optional credentials, consistency level, and timeout.
  • Context variants of every API method.
  • Leader() / Peers() for cluster introspection; SetConsistencyLevel() / SetExecutionWithTransaction() for tuning.
  • TraceOn(io.Writer) / TraceOff() for verbose request/response tracing.
  • No external dependencies — standard library only.

Install

go get github.com/rqlite/gorqlite

Quick start

conn, err := gorqlite.Open("http://")              // localhost:4001, no auth
conn, err  = gorqlite.Open("https://")             // same, https
conn, err  = gorqlite.Open("https://localhost:4001/")

// With credentials and options.
conn, err  = gorqlite.Open("https://mary:secret2@localhost:4001/")
conn, err  = gorqlite.Open("https://server.example.com:4001/?level=weak")
conn, err  = gorqlite.Open("https://localhost:2265/?level=strong&timeout=30")
conn, err  = gorqlite.Open("https://localhost:2265/?disableClusterDiscovery=true")

// Provide your own *http.Client when you need control over TLS, proxies, etc.
client := &http.Client{}
conn, err = gorqlite.OpenWithClient("https://mary:secret2@localhost:4001/", client)

// Adjust the consistency level after opening.
conn.SetConsistencyLevel(gorqlite.ConsistencyLevelNone)
conn.SetConsistencyLevel(gorqlite.ConsistencyLevelWeak)
conn.SetConsistencyLevel(gorqlite.ConsistencyLevelStrong)
Writes
statements := []string{
    "INSERT INTO secret_agents(id, hero_name, abbrev) VALUES (125718, 'Speed Gibson', 'Speed')",
    "INSERT INTO secret_agents(id, hero_name, abbrev) VALUES (209166, 'Clint Barlow', 'Clint')",
    "INSERT INTO secret_agents(id, hero_name, abbrev) VALUES (44107,  'Barney Dunlap', 'Barney')",
}
results, err := conn.Write(statements)
for n, r := range results {
    fmt.Printf("result %d: %d rows affected\n", n, r.RowsAffected)
    if r.Err != nil {
        fmt.Printf("  error: %s\n", r.Err)
    }
}

// Single statement, with auto-increment.
res, err := conn.WriteOne("INSERT INTO foo (name) VALUES ('bar')")
fmt.Printf("last insert id: %d\n", res.LastInsertID)
Queries

rqlite returns JSON, so numbers come back as float64; gorqlite will convert to int64 for you when you Scan() into one. Other types you handle yourself.

rows, err := conn.QueryOne("SELECT id, name FROM secret_agents WHERE id > 500")
fmt.Printf("query returned %d rows\n", rows.NumRows())

var (
    id   int64
    name string
)
for rows.Next() {
    if err := rows.Scan(&id, &name); err != nil {
        // ...
    }
    fmt.Printf("row %d: id=%d name=%q\n", rows.RowNumber(), id, name)
}

QueryOne takes a single statement; Query([]string) runs many in one transaction and returns []QueryResult.

Map() is an alternative to Scan():

for rows.Next() {
    m, err := rows.Map() // map[columnName]interface{}
    id   := int64(m["id"].(float64)) // JSON numbers decode as float64
    name := m["name"].(string)
    _, _ = id, name
}
Parameterized statements
wr, err := conn.WriteOneParameterized(gorqlite.ParameterizedStatement{
    Query:     "INSERT INTO secret_agents(id, name, secret) VALUES (?, ?, ?)",
    Arguments: []interface{}{7, "James Bond", "not-a-secret"},
})

qr, err := conn.QueryOneParameterized(gorqlite.ParameterizedStatement{
    Query:     "SELECT id, name FROM secret_agents WHERE id > ?",
    Arguments: []interface{}{3},
})

Batch variants: WriteParameterized, QueryParameterized, QueueParameterized. Every method also has a …Context variant that takes a context.Context.

Unified endpoint

Request / RequestParameterized send a mixed batch of reads and writes to rqlite's /db/request. The result for each statement carries either a *QueryResult or a *WriteResult.

results, err := conn.Request([]string{
    "INSERT INTO secret_agents(id, name) VALUES (8, 'Felix')",
    "SELECT COUNT(*) FROM secret_agents",
})
Queued writes

Queued writes are fire-and-forget batched writes. They return a sequence number, not per-statement results.

seq, err := conn.QueueOne("INSERT INTO secret_agents(id, name) VALUES (1, 'Q')")
seq, err  = conn.Queue([]string{ /* ... */ })
Nullable types
var name gorqlite.NullString
rows, err := conn.QueryOne("SELECT name FROM secret_agents WHERE id = 7")
for rows.Next() {
    _ = rows.Scan(&name)
}
if name.Valid {
    // use name.String
}

Also: NullInt64, NullInt32, NullInt16, NullFloat64, NullBool, NullTime.

Cluster info
leader, err := conn.Leader()
fmt.Println("current leader:", leader)

peers, err := conn.Peers()
for n, p := range peers {
    fmt.Printf("peer %d: %s\n", n, p)
}
Tracing
f, err := os.OpenFile("/tmp/gorqlite.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
gorqlite.TraceOn(f)
// ... or to stderr:
gorqlite.TraceOn(os.Stderr)
gorqlite.TraceOff()

Tracing is a package-level switch, so it covers Open() too. Credentials in URLs are redacted in trace output.

Custom HTTP client

Pass your own *http.Client when you need to control TLS, certificate verification, or any other transport detail:

tn := &http.Transport{
    TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tn}
conn, err := gorqlite.OpenWithClient("https://localhost:4001/", client)

Notes

  • If your rqlite cluster has access control enabled, the connecting user needs the status permission in addition to the usual query/execute permissions, so gorqlite can query cluster topology and fail over.
  • rqlite does not stream results — a query returns the entire result set at once. Plan for large datasets accordingly.
  • Leader() and Peers() each refresh cluster info before returning. Calling them in sequence can produce slightly inconsistent answers if the cluster changes between calls.
  • Open() connects immediately (unlike database/sql's Open) so that cluster discovery can run before you submit any work.

database/sql driver

Prefer the native gorqlite API when you can. If you need database/sql, import the side-effect package github.com/rqlite/gorqlite/stdlib:

package main

import (
    "database/sql"

    _ "github.com/rqlite/gorqlite/stdlib"
)

func main() {
    db, err := sql.Open("rqlite", "http://")
    if err != nil {
        panic(err)
    }
    if _, err = db.Exec("CREATE TABLE users (id INTEGER, name TEXT)"); err != nil {
        panic(err)
    }
}

Driver limitations:

  • rqlite supports transactions only as a single submitted batch — there is no open-then-extend-then-commit flow, and no rollback.
  • The SQLite C-level prepare/bind API isn't exposed by rqlite, so true Prepare() doesn't exist.
  • Begin(), Commit(), Rollback(), and Prepare() are therefore no-ops.

Concurrency

*Connection is safe to use from multiple goroutines: all configuration changes (SetConsistencyLevel, SetExecutionWithTransaction, Close) and the request methods are guarded internally.

A *QueryResult is a stateful iterator — Next(), Scan(), Map() mutate the row cursor. Don't share a single QueryResult across goroutines without your own synchronization.

Tests

go test ./.... A running rqlite cluster is required.

Defaults:

url:               http://localhost:4001
table (main):      gorqlite_test
table (stdlib):    gorqlite_test_stdlib

Override via environment:

GORQLITE_TEST_URL=https://user:password@somewhere.example.com:1234
GORQLITE_TEST_TABLE=some_other_table
GORQLITE_TEST_TABLE_STDLIB=some_other_table

Possible future work

  • Backup API support.
  • expvars / debugvars.
  • Node removal API.
  • "none" consistency reads sent to followers (currently always routed to the leader, except during leader discovery).

Documentation

Overview

Package gorqlite provieds a database/sql-like driver for rqlite, the distributed consistent sqlite.

Copyright (c)2016 andrew fabbro (andrew@fabbro.org)

See LICENSE.md for license. tl;dr: MIT. Conveniently, the same license as rqlite.

Project home page: https://github.com/raindo308/gorqlite

Learn more about rqlite at: https://github.com/rqlite/rqlite

Index

Constants

View Source
const (
	// ConsistencyLevelNone provides no consistency to other nodes.
	ConsistencyLevelNone consistencyLevel = iota
	// ConsistencyLevelWeak provides a weak consistency that guarantees the
	// queries are sent to the leader.
	ConsistencyLevelWeak
	// ConsitencyLevelLinearizable provides a linearizable consistency and
	// guarantees that read result will reflect all previous writes.
	ConsistencyLevelLinearizable
	// ConsistencyLevelStrong provides a strong consistency and guarantees
	// that the read result will reflect all previous writes and that all
	// previously commmitted writes in the Raft log have been applied..
	ConsistencyLevelStrong
)

Variables

View Source
var DefaultHTTPClient = &http.Client{
	Timeout: defaultTimeout * time.Second,
}
View Source
var ErrClosed = errors.New("gorqlite: connection is closed")

ErrClosed indicates that the connection was closed.

Functions

func ParseConsistencyLevel

func ParseConsistencyLevel(s string) (consistencyLevel, error)

ParseConsistencyLevel parses a string into a consistencyLevel.

func TraceOff

func TraceOff()

TraceOff turns off tracing output. Once you call TraceOff(), no further info is sent to the io.Writer, unless it is TraceOn'd again.

func TraceOn

func TraceOn(w io.Writer)

TraceOn turns on tracing output to the io.Writer of your choice.

Trace output is very detailed and verbose, as you might expect.

Normally, you should run with tracing off, as it makes absolutely no concession to performance and is intended for debugging/dev use.

Types

type Connection

type Connection struct {
	ID string
	// contains filtered or unexported fields
}

Connection provides the connection abstraction.

Since rqlite is stateless, there is no real connection — this type holds the configuration plus the discovered cluster topology (current leader, peers, scheme, credentials, etc.).

Connections are assigned a "connection ID" — a pseudo-UUID built from 16 crypto/rand bytes — used only for tagging trace output, so concurrent connections can be distinguished.

Connection methods are safe to call concurrently from multiple goroutines. State changes go through a single mutex; the HTTP client is reused as-is so the standard library handles its own concurrency.

func Open

func Open(connURL string) (*Connection, error)

Open creates and returns a "connection" to rqlite, using the default HTTP client.

Since rqlite is stateless, there is no actual connection. Open() creates and initializes a gorqlite Connection type, which represents various config information.

The URL should be in a form like this:

http://localhost:4001

http://     default, no auth, localhost:4001
https://    default, no auth, localhost:4001, using https

http://localhost:1234
http://mary:secret2@localhost:1234

https://mary:secret2@somewhere.example.com:1234
https://mary:secret2@somewhere.example.com // will use 4001

func OpenWithClient

func OpenWithClient(connURL string, client *http.Client) (*Connection, error)

OpenWithClient creates and returns a "connection" to rqlite, and uses the given HTTP client for all connections to rqlite. This allows clients to have complete conntrol over the HTTP communications between this client and the rqlite system.

func (*Connection) Close

func (conn *Connection) Close()

Close marks the connection as closed. Safe to call multiple times.

func (*Connection) ConsistencyLevel

func (conn *Connection) ConsistencyLevel() (string, error)

ConsistencyLevel returns the current consistency level as a string.

func (*Connection) Leader

func (conn *Connection) Leader() (string, error)

Leader returns the current cluster leader's API address. With cluster discovery enabled, calling Leader refreshes the cached topology before returning.

func (*Connection) Peers

func (conn *Connection) Peers() ([]string, error)

Peers returns the current cluster peers, leader first. With cluster discovery enabled, calling Peers refreshes the cached topology before returning.

func (*Connection) Query

func (conn *Connection) Query(sqlStatements []string) (results []QueryResult, err error)

Query is used to perform SELECT operations in the database. It takes an array of SQL statements and executes them in a single transaction, returning an array of QueryResult.

Query uses context.Background() internally; to specify the context, use QueryContext.

func (*Connection) QueryContext

func (conn *Connection) QueryContext(ctx context.Context, sqlStatements []string) (results []QueryResult, err error)

QueryContext is used to perform SELECT operations in the database. It takes an array of SQL statements and executes them in a single transaction, returning an array of QueryResult.

func (*Connection) QueryOne

func (conn *Connection) QueryOne(sqlStatement string) (qr QueryResult, err error)

QueryOne wraps Query into a single-statement method.

QueryOne uses context.Background() internally; to specify the context, use QueryOneContext.

func (*Connection) QueryOneContext

func (conn *Connection) QueryOneContext(ctx context.Context, sqlStatement string) (qr QueryResult, err error)

QueryOneContext wraps Query into a single-statement method.

func (*Connection) QueryOneParameterized

func (conn *Connection) QueryOneParameterized(statement ParameterizedStatement) (qr QueryResult, err error)

QueryOneParameterized wraps QueryParameterized into a single-statement method.

QueryOneParameterized uses context.Background() internally; to specify the context, use QueryOneParameterizedContext.

func (*Connection) QueryOneParameterizedContext

func (conn *Connection) QueryOneParameterizedContext(ctx context.Context, statement ParameterizedStatement) (qr QueryResult, err error)

QueryOneParameterizedContext wraps QueryParameterizedContext into a single-statement method.

func (*Connection) QueryParameterized

func (conn *Connection) QueryParameterized(sqlStatements []ParameterizedStatement) (results []QueryResult, err error)

QueryParameterized is used to perform SELECT operations in the database.

It takes an array of parameterized SQL statements and executes them in a single transaction, returning an array of QueryResult vars.

QueryParameterized uses context.Background() internally; to specify the context, use QueryParameterizedContext.

func (*Connection) QueryParameterizedContext

func (conn *Connection) QueryParameterizedContext(ctx context.Context, sqlStatements []ParameterizedStatement) (results []QueryResult, err error)

QueryParameterizedContext is used to perform SELECT operations in the database.

It takes an array of parameterized SQL statements and executes them in a single transaction, returning an array of QueryResult vars.

func (*Connection) Queue

func (conn *Connection) Queue(sqlStatements []string) (seq int64, err error)

Queue performs asynchronous (queued) writes to the rqlite database, as described in https://rqlite.io/docs/api/queued-writes/. The returned sequence number can be used to wait for the writes to be applied.

Queue uses context.Background() internally; to specify the context, use QueueContext. To use Queue with parameterized queries, use QueueParameterized.

func (*Connection) QueueContext

func (conn *Connection) QueueContext(ctx context.Context, sqlStatements []string) (seq int64, err error)

QueueContext is the context-aware version of Queue.

To use QueueContext with parameterized queries, use QueueParameterizedContext.

func (*Connection) QueueOne

func (conn *Connection) QueueOne(sqlStatement string) (seq int64, err error)

QueueOne wraps Queue into a single-statement method.

QueueOne uses context.Background() internally; to specify the context, use QueueOneContext.

func (*Connection) QueueOneContext

func (conn *Connection) QueueOneContext(ctx context.Context, sqlStatement string) (seq int64, err error)

QueueOneContext wraps QueueContext into a single-statement method.

func (*Connection) QueueOneParameterized

func (conn *Connection) QueueOneParameterized(statement ParameterizedStatement) (seq int64, err error)

QueueOneParameterized wraps QueueParameterized into a single-statement method.

QueueOneParameterized uses context.Background() internally; to specify the context, use QueueOneParameterizedContext.

func (*Connection) QueueOneParameterizedContext

func (conn *Connection) QueueOneParameterizedContext(ctx context.Context, statement ParameterizedStatement) (seq int64, err error)

QueueOneParameterizedContext wraps QueueParameterizedContext into a single-statement method.

func (*Connection) QueueParameterized

func (conn *Connection) QueueParameterized(sqlStatements []ParameterizedStatement) (seq int64, err error)

QueueParameterized performs queued writes with parameter binding.

QueueParameterized uses context.Background() internally; to specify the context, use QueueParameterizedContext.

func (*Connection) QueueParameterizedContext

func (conn *Connection) QueueParameterizedContext(ctx context.Context, sqlStatements []ParameterizedStatement) (seq int64, err error)

QueueParameterizedContext is the context-aware version of QueueParameterized.

func (*Connection) Request

func (conn *Connection) Request(sqlStatements []string) (results []RequestResult, err error)

Request is used to access Unified Endpoint to send read and writes requests in one operation.

func (*Connection) RequestContext

func (conn *Connection) RequestContext(ctx context.Context, sqlStatements []string) (results []RequestResult, err error)

RequestContext is used to access Unified Endpoint to send read and writes requests in one operation.

To use RequestContext with parameterized queries, use RequestParameterizedContext.

func (*Connection) RequestParameterized

func (conn *Connection) RequestParameterized(sqlStatements []ParameterizedStatement) (results []RequestResult, err error)

RequestParameterized returns an error if one is encountered during its operation. If it's something like a call to the rqlite API, then it'll return that error. If one statement out of several has an error, you can look at the individual statement's Err for more info.

RequestParameterized uses context.Background() internally; to specify the context, use RequestParameterizedContext.

func (*Connection) RequestParameterizedContext

func (conn *Connection) RequestParameterizedContext(ctx context.Context, sqlStatements []ParameterizedStatement) (results []RequestResult, err error)

RequestParameterizedContext returns an error if one is encountered during its operation. If it's something like a call to the rqlite API, then it'll return that error. If one statement out of several has an error, you can look at the individual statement's Err for more info.

func (*Connection) SetConsistencyLevel

func (conn *Connection) SetConsistencyLevel(levelDesired consistencyLevel) error

SetConsistencyLevel sets the consistency level used for future queries on this connection.

func (*Connection) SetExecutionWithTransaction

func (conn *Connection) SetExecutionWithTransaction(state bool) error

SetExecutionWithTransaction toggles whether multi-statement queries/writes are wrapped in a single rqlite transaction.

func (*Connection) Write

func (conn *Connection) Write(sqlStatements []string) (results []WriteResult, err error)

Write performs DDL/DML synchronously without parameters.

Write uses context.Background() internally; to specify the context, use WriteContext. To use Write with parameterized queries, use WriteParameterized.

func (*Connection) WriteContext

func (conn *Connection) WriteContext(ctx context.Context, sqlStatements []string) (results []WriteResult, err error)

WriteContext performs DDL/DML synchronously without parameters.

To use WriteContext with parameterized queries, use WriteParameterizedContext.

func (*Connection) WriteOne

func (conn *Connection) WriteOne(sqlStatement string) (wr WriteResult, err error)

WriteOne wraps Write into a single-statement method.

WriteOne uses context.Background() internally; to specify the context, use WriteOneContext.

func (*Connection) WriteOneContext

func (conn *Connection) WriteOneContext(ctx context.Context, sqlStatement string) (wr WriteResult, err error)

WriteOneContext wraps WriteContext into a single-statement method.

func (*Connection) WriteOneParameterized

func (conn *Connection) WriteOneParameterized(statement ParameterizedStatement) (wr WriteResult, err error)

WriteOneParameterized wraps WriteParameterized into a single-statement method.

WriteOneParameterized uses context.Background() internally; to specify the context, use WriteOneParameterizedContext.

func (*Connection) WriteOneParameterizedContext

func (conn *Connection) WriteOneParameterizedContext(ctx context.Context, statement ParameterizedStatement) (wr WriteResult, err error)

WriteOneParameterizedContext wraps WriteParameterizedContext into a single-statement method.

func (*Connection) WriteParameterized

func (conn *Connection) WriteParameterized(sqlStatements []ParameterizedStatement) (results []WriteResult, err error)

WriteParameterized performs DDL/DML synchronously.

It takes a slice of statements and returns a same-length slice of WriteResults; statement N's result lives in results[N]. All statements run in a single rqlite transaction.

The returned error is non-nil when the API call itself failed (and then results contains a single error-bearing element), or when one or more statements failed. Inspect each result's Err for per-statement errors.

WriteParameterized uses context.Background() internally; to specify the context, use WriteParameterizedContext.

func (*Connection) WriteParameterizedContext

func (conn *Connection) WriteParameterizedContext(ctx context.Context, sqlStatements []ParameterizedStatement) (results []WriteResult, err error)

WriteParameterizedContext is the context-aware version of WriteParameterized.

type NullBool

type NullBool struct {
	Bool  bool
	Valid bool // Valid is true if Bool is not NULL
}

NullBool represents a bool that may be null.

type NullFloat64

type NullFloat64 struct {
	Float64 float64
	Valid   bool // Valid is true if Float64 is not NULL
}

NullFloat64 represents a float64 that may be null.

type NullInt16

type NullInt16 struct {
	Int16 int16
	Valid bool // Valid is true if Int16 is not NULL
}

NullInt16 represents an int16 that may be null.

type NullInt32

type NullInt32 struct {
	Int32 int32
	Valid bool // Valid is true if Int32 is not NULL
}

NullInt32 represents an int32 that may be null.

type NullInt64

type NullInt64 struct {
	Int64 int64
	Valid bool // Valid is true if Int64 is not NULL
}

NullInt64 represents an int64 that may be null.

type NullString

type NullString struct {
	String string
	Valid  bool // Valid is true if String is not NULL
}

NullString represents a string that may be null.

type NullTime

type NullTime struct {
	Time  time.Time
	Valid bool // Valid is true if Time is not NULL
}

NullTime represents a time.Time that may be null.

type ParameterizedStatement

type ParameterizedStatement struct {
	Query     string
	Arguments []interface{}
}

type QueryResult

type QueryResult struct {
	Err error

	Timing float64
	// contains filtered or unexported fields
}

QueryResult holds the results of a call to Query — effectively a rowset.

For "SELECT id, name FROM some_table", a QueryResult holds any errors produced by the query, the column names and types, and the rows.

Query returns a slice of QueryResult; QueryOne returns a single one.

func (*QueryResult) Columns

func (qr *QueryResult) Columns() []string

Columns returns a list of the column names for this QueryResult.

func (*QueryResult) Map

func (qr *QueryResult) Map() (map[string]interface{}, error)

Map returns the current row (advanced by Next) as a map[columnName]value.

Date and datetime columns are converted to time.Time; everything else is whatever encoding/json produced — usually float64 for numbers, string for text, nil for NULL.

func (*QueryResult) Next

func (qr *QueryResult) Next() bool

Next advances the result cursor to the next row. The first call positions on row 0; subsequent calls advance by one. It returns false when no more rows remain.

Map, Slice, and Scan all require Next to have been called first; they return an error otherwise.

A common idiom:

rows, err := conn.QueryOne("SELECT ...")
for rows.Next() {
    rows.Scan(&dst)
}

func (*QueryResult) NumRows

func (qr *QueryResult) NumRows() int64

NumRows returns the number of rows returned by the query.

func (*QueryResult) RowNumber

func (qr *QueryResult) RowNumber() int64

RowNumber returns the current row number as Next() iterates through the result's rows.

func (*QueryResult) Scan

func (qr *QueryResult) Scan(dest ...interface{}) error

Scan copies the current row's columns into the destinations supplied.

Each destination must be a pointer to a supported type:

*string, *[]byte
*int, *int64, *float64
*bool (parsed from "1"/"0", "true"/"false", etc.)
*time.Time
*NullString, *NullInt64, *NullInt32, *NullInt16,
*NullFloat64, *NullBool, *NullTime

JSON numbers come back as float64 from the rqlite API; gorqlite converts them to the destination's underlying type for you.

A NULL column is left unchanged for primitive destinations and recorded as Valid=false on Null* destinations.

func (*QueryResult) Slice

func (qr *QueryResult) Slice() ([]interface{}, error)

Slice returns the current row (advanced by Next) as a []interface{}. The slice is freshly allocated; the values inside it are the same references the QueryResult holds, so don't mutate them.

Date and datetime columns are converted to time.Time; everything else is whatever encoding/json produced — usually float64 for numbers, string for text, nil for NULL.

func (*QueryResult) Types

func (qr *QueryResult) Types() []string

Types returns the column types declared by the SELECT — note that SQLite's type affinity rules mean these are advisory and may disagree with the actual stored value. See https://www.sqlite.org/datatype3.html.

type RequestResult

type RequestResult struct {
	Err   error
	Query *QueryResult
	Write *WriteResult
}

RequestResult holds the result of a single statement sent to Unified Endpoint.

If statement failed, Err contains the error, neither Query nor Write is set. If statement succeeded, either of Query or Write is set — depending on the type of the statement. Query.Err and Write.Err are never set.

type StatementErrors

type StatementErrors []error

func (StatementErrors) As

func (errs StatementErrors) As(target interface{}) bool

As returns true if the current error, or one of the statement errors can be assigned to the target error.

func (StatementErrors) Error

func (errs StatementErrors) Error() string

Error returns a string representation of the statement errors.

func (StatementErrors) Is

func (errs StatementErrors) Is(target error) bool

Is returns true if the current error, or one of the statement errors is equal to the target error.

func (StatementErrors) Unwrap

func (errs StatementErrors) Unwrap() []error

Unwrap returns the slice of statement errors.

type WriteResult

type WriteResult struct {
	Err          error // don't trust the rest if this isn't nil
	Timing       float64
	RowsAffected int64 // affected by the change
	LastInsertID int64 // if relevant, otherwise zero value
	// contains filtered or unexported fields
}

WriteResult holds the result of a single statement sent to Write.

Write returns a slice of WriteResult; WriteOne returns a single one.

Directories

Path Synopsis
Package stdlib provides a compatability layer from gorqlite to database/sql.
Package stdlib provides a compatability layer from gorqlite to database/sql.

Jump to

Keyboard shortcuts

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