Documentation
¶
Overview ¶
Package couchbase is a database/sql driver for the query service of Couchbase Server, which runs SQL++ (N1QL) over HTTP. It registers the one name "couchbase" (D30), and takes a DSN of the form couchbase://user:pass@host:8093/?key=value (D38).
db, err := sql.Open("couchbase", "couchbase://user:pass@localhost:8093/")
The driver sends each argument to the server, which binds it: an argument without a name fills $1 or ?, and sql.Named("x", v) fills $x (D40). A transaction is a transaction of the query service (D41), and the key durability_level sets its durability (D43). A string that scans into a []byte is decoded as base64 (D44). docs/COUCHBASE.md holds what the driver knows about the server.
Index ¶
Constants ¶
const Name = "couchbase"
Name is the name that the driver registers with database/sql, and the scheme of its DSN.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Host is the host of the query service.
Host string
// Port is the port of the query service, 8093 by default, or 18093 with
// TLS.
Port int
// TLS is true to speak HTTPS.
TLS bool
// User and Password are the credentials, sent with basic
// authentication.
User string
Password string
// QueryContext names the bucket and the scope of a collection that a
// statement names alone, such as "default:dbmeta._default".
QueryContext string
// ScanConsistency is "not_bounded" or "request_plus", or "" for the
// default of the server.
ScanConsistency string
// Timeout is the timeout that the server enforces for each statement, or
// zero for none.
Timeout time.Duration
// Durability is the durability of a transaction, or "" for the default
// of the server (D43).
Durability string
// TxTimeout is how long a transaction lasts before the server ends it, or
// zero for the default of the server, which is 15 seconds (D46).
TxTimeout time.Duration
}
Config is the configuration of a connector, which the DSN holds. The caller owns it (D7).
type Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
Connector opens connections to one query service. It owns its transport, and every connection shares it. A caller can build one from a Config and open it with sql.OpenDB.
func NewConnector ¶
NewConnector returns a Connector for cfg. The connector keeps a copy of cfg.
func (*Connector) Close ¶
Close closes the idle connections of the transport. database/sql calls it when the database closes.
type Driver ¶
type Driver struct{}
Driver is the database/sql driver for Couchbase.
type Error ¶
type Error struct {
// Code is the code of the error.
Code int `json:"code"`
// Msg is the message of the error.
Msg string `json:"msg"`
}
Error is one error that the query service reported, such as code 3000 for a syntax error or 12009 for an insert of a key that exists.
type Option ¶
type Option func(*options)
Option sets an option of one statement or one transaction (D40). An option comes from the DSN, then from the context through WithOptions, then from an argument of the statement, and a later one wins.
func WithDurability ¶
WithDurability sets the durability of a transaction, such as "none" or "majority" (D43). It applies to BeginTx and to a statement that runs as a transaction of its own.
func WithParameter ¶
WithParameter sets any parameter of the request by its name, such as "profile" or "client_context_id", as the SDKs of Couchbase do with their raw options. The value is encoded with json/v2. A parameter named here replaces one that the driver sets itself.
func WithQueryContext ¶
WithQueryContext sets the bucket and the scope of a collection that a statement names alone, such as "default:dbmeta._default".
func WithReadonly ¶
WithReadonly makes the server refuse a statement that writes.
func WithScanConsistency ¶
WithScanConsistency sets the scan consistency, "not_bounded" or "request_plus". A read after a write sends "request_plus" to see the write, because Couchbase updates an index after a write.
func WithTimeout ¶
WithTimeout sets the timeout that the server enforces for the statement.
func WithTransactionTimeout ¶
WithTransactionTimeout sets how long a transaction can last before the server ends it. It applies to BeginTx.
type ResponseError ¶
type ResponseError struct {
// HTTPStatus is the status code of the response.
HTTPStatus int
// Status is the status in the body of the response.
Status string
// Errs are the errors, in the order that the server sent them.
Errs []Error
}
ResponseError holds the errors of one response, with its HTTP status and the status that the server reported, such as "fatal" or "stopped". Use errors.As to read an Error of it.
func (*ResponseError) Error ¶
func (err *ResponseError) Error() string
Error satisfies the error interface.
func (*ResponseError) Unwrap ¶
func (err *ResponseError) Unwrap() []error
Unwrap returns each Error, for errors.As and errors.Is.