Documentation
¶
Overview ¶
gorqlite A golang database/sql 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 licese as rqlite.
Project home page: https://github.com/raindo308/gorqlite
Learn more about rqlite at: https://github.com/rqlite/rqlite
Index ¶
- func EscapeString(value string) string
- func TraceOff()
- func TraceOn(w io.Writer)
- type Connection
- func (conn *Connection) Close()
- func (conn *Connection) ConsistencyLevel() (string, error)
- func (conn *Connection) Leader() (string, error)
- func (conn *Connection) Peers() ([]string, error)
- func (conn *Connection) Query(sqlStatements []string) (results []QueryResult, err error)
- func (conn *Connection) QueryOne(sqlStatement string) (qr QueryResult, err error)
- func (conn *Connection) SetConsistencyLevel(levelDesired string) error
- func (conn *Connection) Write(sqlStatements []string) (results []WriteResult, err error)
- func (conn *Connection) WriteOne(sqlStatement string) (wr WriteResult, err error)
- type PreparedStatement
- type QueryResult
- func (qr *QueryResult) Columns() []string
- func (qr *QueryResult) Map() (map[string]interface{}, error)
- func (qr *QueryResult) Next() bool
- func (qr *QueryResult) NumRows() int64
- func (qr *QueryResult) RowNumber() int64
- func (qr *QueryResult) Scan(dest ...interface{}) error
- func (qr *QueryResult) Types() []string
- type WriteResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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.
Types ¶
type Connection ¶
type Connection struct { ID string // generated in init() // contains filtered or unexported fields }
func Open ¶
func Open(connURL string) (Connection, error)
*****************************************************************
Open() creates and returns a "connection" to rqlite.
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 (*Connection) Close ¶
func (conn *Connection) Close()
func (*Connection) ConsistencyLevel ¶
func (conn *Connection) ConsistencyLevel() (string, error)
func (*Connection) Leader ¶
func (conn *Connection) Leader() (string, error)
func (*Connection) Peers ¶
func (conn *Connection) Peers() ([]string, error)
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 vars.
func (*Connection) QueryOne ¶
func (conn *Connection) QueryOne(sqlStatement string) (qr QueryResult, err error)
QueryOne() is a convenience method that wraps Query() into a single-statement method.
func (*Connection) SetConsistencyLevel ¶
func (conn *Connection) SetConsistencyLevel(levelDesired string) error
func (*Connection) Write ¶
func (conn *Connection) Write(sqlStatements []string) (results []WriteResult, err error)
Write() is used to perform DDL/DML in the database. ALTER, CREATE, DELETE, DROP, INSERT, UPDATE, etc. all go through Write().
Write() takes an array of SQL statements, and returns an equal-sized array of WriteResults, each corresponding to the SQL statement that produced it.
All statements are executed as a single transaction.
Write() 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, it will return a generic "there were %d statement errors" and you'll have to look at the individual statement's Err for more info.
func (*Connection) WriteOne ¶
func (conn *Connection) WriteOne(sqlStatement string) (wr WriteResult, err error)
type PreparedStatement ¶
type PreparedStatement struct {
// contains filtered or unexported fields
}
PreparedStatement is a simple wrapper around fmt.Sprintf for prepared SQL statements.
func NewPreparedStatement ¶
func NewPreparedStatement(body string) PreparedStatement
NewPreparedStatement takes a sprintf syntax SQL query for later binding of parameters.
func (PreparedStatement) Bind ¶
func (p PreparedStatement) Bind(args ...interface{}) string
Bind takes arguments and SQL-escapes them, then calling fmt.Sprintf.
type QueryResult ¶
A QueryResult type holds the results of a call to Query(). You could think of it as a rowset.
So if you were to query:
SELECT id, name FROM some_table;
then a QueryResult would hold any errors from that query, a list of columns and types, and the actual row values.
Query() returns an array of QueryResult vars, while QueryOne() returns a single variable.
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 (as advanced by Next()) as a map[string]interface{}
The key is a string corresponding to a column name. The value is the corresponding column.
Note that only json values are supported, so you will need to type the interface{} accordingly.
func (*QueryResult) Next ¶
func (qr *QueryResult) Next() bool
Next() positions the QueryResult result pointer so that Scan() or Map() is ready.
You should call Next() first, but gorqlite will fix it if you call Map() or Scan() before the initial Next().
A common idiom:
rows := conn.Write(something) for rows.Next() { // your Scan/Map and processing here. }
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() takes a list of pointers and then updates them to reflect he current row's data.
Note that only the following data types are used, and they are a subset of the types JSON uses:
string, for JSON strings float64, for JSON numbers int64, as a convenient extension nil for JSON null
booleans, JSON arrays, and JSON objects are not supported, since sqlite does not support them.
func (*QueryResult) Types ¶
func (qr *QueryResult) Types() []string
Types() returns an array of the column's types.
Note that sqlite will repeat the type you tell it, but in many cases, it's ignored. So you can initialize a column as CHAR(3) but it's really TEXT. See https://www.sqlite.org/datatype3.html
This info may additionally conflict with the reality that your data is being JSON encoded/decoded.
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 }
A WriteResult holds the result of a single statement sent to Write().
Write() returns an array of WriteResult vars, while WriteOne() returns a single WriteResult.