{"modulePath":"github.com/xo/dbimp","version":"v0.26.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package libsql\n\nPackage libsql is a database/sql driver for libSQL, the fork of SQLite by Turso, which its server sqld and Turso Cloud serve over the Hrana protocol on HTTP. It registers the one name \"libsql\", and takes a DSN of the form libsql://user:token@host:port?key=value (D148). dburl names turso as an alias.\n\n\tdb, err := sql.Open(\"libsql\", \"libsql://:token@mydb-myorg.turso.io\")\n\nTLS is on unless tls=false, and the token goes as Bearer (D148). A query reads its rows from /v3/cursor one token at a time, and Exec runs on /v3/pipeline (D149). A transaction lives on a stream of Hrana, which its baton holds across requests (D150). The server binds each argument as a typed value (D152). A value has the Go type of the affinity of its declared type, and a value of another storage class keeps its own Go type (D140 and D147). docs/LIBSQL.md holds what the driver knows about the server.\n\n## Constants\n\n```go\nconst (\n\t// AuthBearer sends the password as a Bearer token. It is the default.\n\tAuthBearer = dbimp.AuthBearer\n\t// AuthBasic sends the user and the password with basic authentication,\n\t// for sqld with SQLD_HTTP_AUTH.\n\tAuthBasic = dbimp.AuthBasic\n)\n```\nThe values of the key auth, which say how the driver sends the password (D94 and D148).\n\n```go\nconst (\n\t// CodeStreamExpired is the code of a stream that had no request for 10\n\t// seconds. The server rolled back its transaction (measured).\n\tCodeStreamExpired = \"STREAM_EXPIRED\"\n)\n```\nThe codes of Hrana that the driver reads (docs/LIBSQL.md, Errors).\n\n```go\nconst Name = \"libsql\"\n```\nName is the name that the driver registers with database/sql, and the scheme of its DSN.\n\n## Functions\n\n```go\nfunc WithOptions(ctx context.Context, opts ...Option) context.Context\n```\nWithOptions returns a context that carries opts. Each statement started with the context applies them after the options of the DSN.\n\n## Types\n\n```go\ntype Config struct {\n\t// Host is the host of the server.\n\tHost string\n\t// Port is the port of the server, 443 by default with TLS.\n\tPort int\n\t// NoTLS is true to speak HTTP, which the key tls=false asks for. TLS is\n\t// on by default (D148).\n\tNoTLS bool\n\t// User and Password are the credentials. The password is the token\n\t// (D94).\n\tUser     string\n\tPassword string\n\t// Auth is AuthBearer or AuthBasic (D94).\n\tAuth string\n\t// Namespace is the namespace of each request, sent as x-namespace, or \"\"\n\t// for the default one.\n\tNamespace string\n}\n```\nConfig is the configuration of a connector, which the DSN holds. The caller owns it (D7).\n\n```go\nfunc ParseDSN(dsn string) (*Config, error)\n```\nParseDSN parses a DSN of the form libsql://user:token@host:port?key=value (D27, D35 and D148). A DSN with a path is refused, and so is a DSN with tls=false and no port.\n\n```go\nfunc (cfg *Config) FormatDSN() string\n```\nFormatDSN returns the DSN of cfg. ParseDSN reads it back as cfg, for a Config that ParseDSN or NewConnector filled.\n\n```go\ntype Connector struct {\n\t// contains filtered or unexported fields\n}\n```\nConnector 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.\n\n```go\nfunc NewConnector(cfg Config) *Connector\n```\nNewConnector returns a Connector for cfg. The connector keeps a copy of cfg, and fills each field that is zero with its default.\n\n```go\nfunc (c *Connector) Close() error\n```\nClose closes the idle connections of the transport.\n\n```go\nfunc (c *Connector) Connect(context.Context) (driver.Conn, error)\n```\nConnect satisfies driver.Connector. A connection holds nothing on the server until a transaction opens a stream, so it sends no request.\n\n```go\nfunc (c *Connector) Driver() driver.Driver\n```\nDriver satisfies driver.Connector.\n\n```go\ntype Driver struct{}\n```\nDriver is the database/sql driver for libSQL.\n\n```go\nfunc (Driver) Open(string) (driver.Conn, error)\n```\nOpen satisfies driver.Driver. database/sql opens a connection through OpenConnector, and Open returns an error, because opening a connection needs a context.\n\n```go\nfunc (Driver) OpenConnector(dsn string) (driver.Connector, error)\n```\nOpenConnector satisfies driver.DriverContext. It parses the DSN.\n\n```go\ntype Error struct {\n\t// HTTPStatus is the status code of the response.\n\tHTTPStatus int\n\t// Code is the code of Hrana or of SQLite, or \"\" when the server sent\n\t// none.\n\tCode string\n\t// Message is the message of the server.\n\tMessage string\n\t// contains filtered or unexported fields\n}\n```\nError is an error that libSQL reported. An error of a statement arrives with HTTP 200, as a result of the type error with a message and a code, such as SQL\\_PARSE\\_ERROR or SQLITE\\_CONSTRAINT (measured). A request that the server refused arrives with another status: HTTP 400 for a fault of the protocol, as text, or for an expired stream, HTTP 401 for a token that is not valid, and HTTP 403 for a write with a token that can only read (measured).\n\n```go\nfunc (err *Error) AuthenticationRefused() bool\n```\nAuthenticationRefused reports whether the server refused the credential. It returns what Is reports for dbimp.ErrAuthentication, and a caller that does not import this module reads it through an interface of its own (D227).\n\n```go\nfunc (err *Error) ErrVerbose(_ string) string\n```\nErrVerbose returns the error as psql writes it for \\\\errverbose: the code and the message on the first line, and then each field that the server sent, one on each line with its name in upper case. A caller that does not import this module reads it through an interface of its own (D231).\n\n```go\nfunc (err *Error) Error() string\n```\nError satisfies the error interface.\n\n```go\nfunc (err *Error) Is(target error) bool\n```\nIs reports whether err matches target. It matches dbimp.ErrAuthentication for HTTP 401, which is the answer for a token that is not valid (recorded: \"a wrong password\"). HTTP 403, for a token that cannot write, is a missing permission and does not match (D197).\n\n```go\nfunc (err *Error) Unwrap() error\n```\nUnwrap returns the \\*dbimp.StatusError of a response whose status is not 2xx, or nil.\n\n```go\ntype Option = dbimp.Option[options]\n```\nOption 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.\n\n```go\nfunc WithDatabase(name string) Option\n```\nWithDatabase sets the namespace of the statement, as WithNamespace does. A namespace is the database of libSQL.\n\n```go\nfunc WithNamespace(name string) Option\n```\nWithNamespace sets the namespace of the statement, sent as x-namespace, as the key namespace of the DSN does (D148). A statement of a transaction runs in the namespace of the transaction.\n\n```go\nfunc WithParameter(name string, value any) Option\n```\nWithParameter sets any key of the statement of Hrana by its name, such as \"want\\_rows\". The value is encoded with json/v2. A key named here replaces one that the driver sets itself, such as \"sql\" or \"args\".\n\n```go\nfunc WithReadonly(readonly bool) Option\n```\nWithReadonly would make the server refuse a write. The server keeps no statement or transaction read-only: it took an INSERT inside BEGIN TRANSACTION READONLY (measured). So WithReadonly(true) fails with dbimp.ErrNotSupported. A token with the claim ro is read-only.\n\n```go\nfunc WithTimeout(d time.Duration) Option\n```\nWithTimeout ends the request of the statement after d. The server stops a statement when its client leaves (measured), and Hrana has no timeout of its own, so the end of the request stops the statement. Zero sets no timeout.\n\n","path":"github.com/xo/dbimp/libsql","name":"libsql","synopsis":"Package libsql is a database/sql driver for libSQL, the fork of SQLite by Turso, which its server sqld and Turso Cloud serve over the Hrana protocol on HTTP.","isRedistributable":true}
