Documentation
¶
Overview ¶
Package solr is a database/sql driver for Apache Solr, which runs SQL on a collection over HTTP, as Parallel SQL. It registers the one name "solr", and takes a DSN of the form solr://user:pass@host:8983/collection (D166).
db, err := sql.Open("solr", "solr://admin:pass@localhost:8983/books")
The driver reads only. The SQL of Solr refuses INSERT, UPDATE and DELETE, and the driver returns that refusal (D163). The server binds no argument, so the driver writes each one into the statement as a literal (D166). The answer names no type, so the driver reads the type of each column from metadata.COLUMNS and from the luke handler, once for each table and connection, and decodes each value by it (D166). Each request asks for the first tuple that names the columns, and the driver reads the tuples one at a time, to the tuple EOF. Solr has no transactions, and no way to stop a statement of /sql. docs/SOLR.md holds what the driver knows about the server.
Index ¶
Constants ¶
const ErrCut dbimp.Error = "the answer was cut short"
ErrCut is the error of an answer that ends before its tuple EOF. The server ends an answer so when the connection breaks, and after some rows it comes wrapped with dbimp.ErrIncomplete (D107 and D166).
const ModeFacet = "facet"
ModeFacet is the only value of the key mode. It is the aggregationMode that the server uses by default, and it gives every group of a GROUP BY.
const Name = "solr"
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 server.
Host string
// Port is the port of the server, 8983 by default.
Port int
// TLS is true to speak HTTPS.
TLS bool
// User and Password are the credentials, which the driver sends with
// basic authentication.
User string
Password string
// Collection is the collection whose /sql handler takes each statement.
// FROM names the table, and any collection that the user can read serves
// (D166). It is empty for a DSN with no path, and then each statement
// needs WithDatabase.
Collection string
// Mode is the aggregationMode of each statement. It is ModeFacet by
// default, and the only value that the driver takes (D166).
Mode string
}
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 server. 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, and fills each field that is zero with its default.
type Driver ¶
type Driver struct{}
Driver is the database/sql driver for Apache Solr.
type Error ¶
type Error struct {
// HTTPStatus is the status code of the response. It is 200 for an
// exception that came in the body.
HTTPStatus int
// Message is EXCEPTION, or the title of the page of HTML, or the status
// text of the response when it has neither.
Message string
// contains filtered or unexported fields
}
Error is an error that Solr reported. A statement that fails answers HTTP 200 with the tuple EOF that holds EXCEPTION, before any row or after some (measured). A wrong password is HTTP 401, a request that the role does not allow is HTTP 403, and a statement that the SQL layer cannot plan can be HTTP 500, each with a page of HTML (measured).
type Option ¶
Option sets an option of one statement (D109). 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 WithDatabase ¶
WithDatabase names the collection whose /sql handler takes the statement, in place of the collection of the DSN (D166). FROM still names the table.
func WithParameter ¶
WithParameter sets a field of the form of POST /solr/<collection>/sql by its name, such as "numWorkers". A string is sent as it is, a []string as one field for each element, and any other value as its text. A field named here replaces one that the driver sets itself, such as "includeMetadata" or "aggregationMode". So WithParameter("aggregationMode", "map_reduce") turns on the mode that the DSN refuses, and WithParameter("includeMetadata", "false") makes the answer name no column before its rows.
func WithReadonly ¶
WithReadonly asks that the statement write nothing. The SQL of Solr takes no write of any kind (D163), so every statement is read-only, and the option changes nothing.
func WithTimeout ¶
WithTimeout cannot give the server a time for the statement. The server has no setting that honors one: timeAllowed cut nothing (measured), so a statement with a timeout other than zero fails with dbimp.ErrNotSupported. The deadline of the context stops the request.