Documentation
¶
Index ¶
Constants ¶
const Version = "0.1.0"
Version is the adapter version reported by Adapter().
Variables ¶
var ( // ErrNotSupported is returned by an operation this read-only checkpoint // does not implement. It is always returned before any I/O. ErrNotSupported = errors.New("dalgo2libsql: operation not supported by this read-only adapter") // ErrInvalidConfig is returned by NewDB for a configuration it refuses. ErrInvalidConfig = errors.New("dalgo2libsql: invalid configuration") // ErrUnsafeTarget is returned when a database URL is not an HTTPS (or // explicitly allowed loopback HTTP) base URL. ErrUnsafeTarget = errors.New("dalgo2libsql: unsafe database URL") // ErrUnsupportedResponse is returned when the endpoint answers in a way // the adapter refuses to interpret. ErrUnsupportedResponse = errors.New("dalgo2libsql: unsupported endpoint response") )
Package-level failures. They are safe to test with errors.Is; their text never contains a URL, a credential, SQL text or a response body.
var ErrBackend = errors.New("dalgo2libsql: the read failed")
ErrBackend reports a read that failed for a reason this adapter does not classify. It deliberately carries no server text, SQL, URL or transport detail.
Functions ¶
func NewDB ¶
NewDB validates cfg, normalizes the database URL, and returns a read-only DALgo database over a private libSQL pool. It performs no I/O: the first read (or a schema read) is the connection test, and it runs under that caller's context.
A native libsql:// URL is normalized to https://. A URL with credentials, a query, a fragment, or an API suffix is refused; so is plain HTTP for a non-loopback host. Redirects are never followed.
Types ¶
type Config ¶
type Config struct {
// URL is the base URL of the libSQL server, for example
// https://db.example.com or libsql://db.example.com. A libsql:// URL is
// normalized to https://. A path, when present, is kept as the server's
// base path. Credentials, a query, a fragment, and an API suffix such as
// /v3/pipeline are refused. Plain HTTP is accepted only for a loopback
// host and only when AllowLoopbackHTTP is true.
URL string
// ID is the identifier ID() reports. It defaults to the host and path of
// URL, without credentials (URL cannot carry any).
ID string
// Headers supplies credentials per request. The provider is called for
// every request with the operation's context, before the per-request
// deadline is applied, so it can refresh an expiring token.
Headers HeaderProvider
// HTTPClient optionally supplies the client. NewDB copies it, refuses
// redirects on the copy and clones an *http.Transport; the caller's
// client is never mutated.
HTTPClient *http.Client
// AllowLoopbackHTTP permits plain HTTP for localhost, 127.0.0.0/8 and
// ::1 only. It exists for local development against a fixture.
AllowLoopbackHTTP bool
// Recordsets declares the recordset (table) name and its single primary
// key column, for keyed reads. A key is never assumed to be "id": a
// collection that is not declared here refuses keyed reads, and a
// declaration is checked against the live schema before it is used.
// Structured reads discover their key from the SQLite catalog themselves
// and do not need a declaration.
//
// A keyed read target must be map record data: the delegate preserves the
// native SQLite value of every column, and a struct target is refused
// before a statement because a field type could force a conversion.
Recordsets map[string]string
// MaxOpenConns bounds the private pool. Default 1: schema probes and the
// statement they inform then share one connection, which is what makes
// per-connection SQLite settings consistent.
MaxOpenConns int
// Timeout bounds one HTTP request and, as one operation deadline, the
// whole public call: every internal catalog probe, header refresh and data
// statement of one Get or reader shares it. Default 30s.
Timeout time.Duration
// MaxRequestBytes bounds one encoded request body. Default 1 MiB.
MaxRequestBytes int64
// MaxResponseBytes bounds one encoded response body. Default 4 MiB.
MaxResponseBytes int64
// MaxOperationBytes bounds the response bytes of one DALgo operation,
// internal metadata probes included. Default 16 MiB.
MaxOperationBytes int64
// MaxOperationRequests bounds the pipeline calls of one operation.
// Default 32.
MaxOperationRequests int
// MaxRows bounds the rows of one statement result. Default 10000.
MaxRows int
// MaxOperationRows bounds the rows decoded across one operation.
// Default 50000.
MaxOperationRows int
// MaxColumns bounds the columns of one result. Default 256.
MaxColumns int
// MaxValueBytes bounds one text or blob value. Default 1 MiB.
MaxValueBytes int
// MaxArgs bounds the bound arguments of one statement. Default 256.
MaxArgs int
}
Config configures one adapter instance for one existing libSQL database. The adapter opens a private HTTPS connection pool; it does not create tables, run migrations, or use an account or a management API.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
readonly
command
Command readonly reads one record from an existing libSQL table through the dalgo2libsql adapter.
|
Command readonly reads one record from an existing libSQL table through the dalgo2libsql adapter. |
|
internal
|
|
|
hrana
Package hrana is a bounded client for the official libSQL Hrana 3 pipeline protocol.
|
Package hrana is a bounded client for the official libSQL Hrana 3 pipeline protocol. |