Documentation
¶
Overview ¶
Package dbimp holds the code that the dbimp database/sql drivers share, such as the HTTP client and the adapters that encode and decode values.
Each driver is its own package under this module, such as github.com/xo/dbimp/<driver>. A driver registers itself from init under the name of its package, which the scheme of github.com/xo/dburl returns as its Driver (D28 and D98). A consumer imports the driver package directly. There is no registry of drivers.
Index ¶
- Constants
- func Any(v jsontext.Value) (any, error)
- func Assign(scanCtx driver.ScanContext, dest, src any) error
- func Bool(v jsontext.Value) (bool, error)
- func CheckStatus(res *http.Response) error
- func Decimal(v jsontext.Value) (*apd.Decimal, error)
- func Float64(v jsontext.Value) (float64, error)
- func Int64(v jsontext.Value) (int64, error)
- func IsNull(v jsontext.Value) bool
- func IsOption[T any](v any) bool
- func MarshalParams(v any, params map[string]any) ([]byte, error)
- func NewClient(rt http.RoundTripper, redirects bool) *http.Client
- func NewTransport(cfg *tls.Config) *http.Transport
- func Number(v jsontext.Value) (any, error)
- func ParseURL(name, dsn string) (*url.URL, error)
- func Resolve[T any](ctx context.Context, dsn T, args []driver.NamedValue) (T, []driver.NamedValue)
- func Send(c *http.Client, req *http.Request) (*http.Response, error)
- func SetAuth(req *http.Request, auth, scheme, user, secret string)
- func String(v jsontext.Value) (string, error)
- func Unsupported(option string) error
- func WithOptions[T any](ctx context.Context, opts ...Option[T]) context.Context
- type Affinity
- type ArrayRows
- type CBORDecoder
- func (d *CBORDecoder) More(h CBORHead, n uint64) (bool, error)
- func (d *CBORDecoder) PeekHead() (CBORHead, error)
- func (d *CBORDecoder) ReadHead() (CBORHead, error)
- func (d *CBORDecoder) ReadRaw() ([]byte, error)
- func (d *CBORDecoder) ReadString(h CBORHead) ([]byte, error)
- func (d *CBORDecoder) ReadText() (string, error)
- func (d *CBORDecoder) Skip() error
- type CBOREncoder
- func (e *CBOREncoder) Array(n int)
- func (e *CBOREncoder) Bool(b bool)
- func (e *CBOREncoder) ByteString(b []byte)
- func (e *CBOREncoder) Bytes() []byte
- func (e *CBOREncoder) Float(f float64)
- func (e *CBOREncoder) Head(m CBORMajor, arg uint64)
- func (e *CBOREncoder) Int(i int64)
- func (e *CBOREncoder) Map(n int)
- func (e *CBOREncoder) Null()
- func (e *CBOREncoder) Raw(b []byte)
- func (e *CBOREncoder) Tag(num uint64)
- func (e *CBOREncoder) Text(s string)
- func (e *CBOREncoder) Uint(u uint64)
- type CBORHead
- type CBORMajor
- type Date
- type Error
- type Interval
- type LocalDateTime
- type LocalTime
- type ObjectRows
- type OffsetTime
- type Option
- type Placeholder
- type Query
- func (q Query) Auth(key string) (string, error)
- func (q Query) Bool(key string, def bool) (bool, error)
- func (q Query) Duration(key string, def time.Duration) (time.Duration, error)
- func (q Query) Has(key string) bool
- func (q Query) Int(key string, def int) (int, error)
- func (q Query) String(key, def string) string
- type StatusError
- type Stream
- type Syntax
- type Vector
- type VectorElement
Constants ¶
const ( // AuthBasic sends the user and the secret with basic authentication. It // is the default. AuthBasic = "basic" // AuthBearer sends the secret as a token, such as a JWT, and no user. AuthBearer = "bearer" )
The values of the key auth of a DSN, which say how a driver sends the secret of its URL, the password (D94 and D110).
Variables ¶
This section is empty.
Functions ¶
func Any ¶
Any returns v as a Go value: nil, bool, string, a number as Number returns it, []any, or map[string]any. It is for a whole document, by rule 3 of D18. A map has no order, so a driver never returns the columns of a row through Any.
func Assign ¶
func Assign(scanCtx driver.ScanContext, dest, src any) error
Assign stores src in dest, for the ScanColumn method of a driver that implements driver.RowsColumnScanner. It stores src itself in a *any, and an *apd.Decimal in an *apd.Decimal. It hands every other pair to sql.ConvertAssign, and it hands a decimal to it as text, which is the form that a *string, a *float64 and the Scan method of apd.Decimal take.
func CheckStatus ¶
CheckStatus returns nil if the status of res is 2xx. Otherwise it reads at most 64 KiB of the body, closes the body, and returns a *StatusError.
func Decimal ¶
Decimal returns v as a new *apd.Decimal (D33). It takes a JSON number, and a JSON string that holds a number, because some servers send a decimal as a string to keep its digits.
func Int64 ¶
Int64 returns the JSON number v as an int64. It returns an error for a number with a fraction or an exponent, and for a number out of range.
func IsOption ¶ added in v0.6.0
IsOption reports whether v is an Option of a driver whose options are T. CheckNamedValue of the driver keeps such a value, so that database/sql hands it to the statement, and Resolve takes it out there. A connection then holds no option between two statements.
func MarshalParams ¶ added in v0.6.0
MarshalParams returns v, which encodes as a JSON object, with the keys of params, which WithParameter of a driver sets (D109). A key of params replaces the key of v with the same name, as it does in Couchbase (D40). The keys of v keep their order, and the keys of params follow in the order of their names.
func NewClient ¶
func NewClient(rt http.RoundTripper, redirects bool) *http.Client
NewClient returns a client for rt with no timeout, because the context of each request sets its deadline. If redirects is false, the client returns a redirect as the response and does not follow it. A driver decides in step 9 of docs/DRIVER.md whether it follows a redirect. When a client follows one to another host, net/http drops the Authorization header.
func NewTransport ¶
NewTransport returns the transport for one connector. It takes a proxy from the environment, and it bounds the dial and the TLS handshake. It sets no timeout for the headers of a response, because a server can send them only after a long query ends. The context of each request sets its deadline. The transport asks for gzip and decompresses it, because no driver sets Accept-Encoding itself.
func Number ¶
Number returns the JSON number v as the Go value that holds it exactly, for a server that sends no type with a number. An integer that fits is an int64. A larger integer is an *apd.Decimal. A number with a fraction or an exponent is a float64, because a JSON number that is not an integer is a double in every product that sends no type.
func ParseURL ¶
ParseURL parses dsn with net/url, and returns an error if its scheme is not name (D27 and D35). A driver registers one name, so it takes one scheme. An error never holds the DSN, because the DSN can hold a password.
func Resolve ¶ added in v0.6.0
func Resolve[T any](ctx context.Context, dsn T, args []driver.NamedValue) (T, []driver.NamedValue)
Resolve returns dsn, which holds the options of the DSN, with the options of ctx and then the Option arguments of args applied to it, in that order, so that a later one wins. It returns the other arguments, numbered again from 1, as database/sql numbers them when it removes an argument.
func Send ¶
Send sends req with c. It sends each request once, and never again after it can have reached the server (D8).
If c made no connection for the request, such as when the dial or the TLS handshake failed, the error wraps driver.ErrBadConn, so that database/sql can try a new connection. If the context of req ended, the error wraps the error of the context, and never driver.ErrBadConn. The error never holds a password, because net/http removes it from the URL of the error.
func SetAuth ¶ added in v0.6.0
SetAuth sets the credentials on req, as auth says. AuthBasic sends user and secret with basic authentication. AuthBearer sends the header Authorization with scheme and secret, and no user. scheme is "Bearer" for most servers, and "Token" for InfluxDB 2, which refuses Bearer (D110). With no user and no secret, it sends nothing, for a server that runs with authentication off.
func Unsupported ¶ added in v0.6.0
Unsupported returns the error of an option that the server of a driver cannot honor, so that a caller never believes that it holds (D109).
func WithOptions ¶ added in v0.6.0
WithOptions returns a context that carries opts, after the options that ctx carries. Each statement and each transaction that starts with the context applies them after the options of the DSN.
Types ¶
type Affinity ¶ added in v0.9.0
type Affinity int
Affinity is how a driver of the SQLite family, such as rqlite or libSQL, reads the values of a column, from the type that the table declares for it (D140 and D147). The first five are the affinities of SQLite. BOOLEAN, DATE, DATETIME and TIMESTAMP are their own, because the drivers read them as a bool, a date and a time.
const ( // AffinityNone is the affinity of a column with no type that the drivers // support, such as ANY or a column of an expression. Each value reads by // its own storage class (D140). AffinityNone Affinity = iota AffinityInteger AffinityReal AffinityText AffinityBlob AffinityNumeric AffinityBoolean AffinityDate AffinityDateTime AffinityTimestamp )
The affinities of a declared type.
func AffinityOf ¶ added in v0.9.0
AffinityOf returns the affinity of the declared type decl, such as "bigint" or "VARCHAR(10)" (D140). BOOLEAN, DATE, DATETIME and TIMESTAMP are their own affinities. Every other name follows the rules of affinity of SQLite, in their order: a name with INT, then CHAR, CLOB or TEXT, then BLOB, then REAL, FLOA or DOUB, and NUMERIC for any other. ANY and the empty name have none.
type ArrayRows ¶
type ArrayRows struct {
// contains filtered or unexported fields
}
ArrayRows reads a JSON array of arrays as rows, by rule 1 of D18. The server names the columns elsewhere in the response, and each row is an array with one value for each column.
func NewArrayRows ¶
NewArrayRows reads the start of an array of rows of n columns from dec.
type CBORDecoder ¶ added in v0.2.0
type CBORDecoder struct {
// contains filtered or unexported fields
}
CBORDecoder reads CBOR items from a reader, one at a time.
func NewCBORDecoder ¶ added in v0.2.0
func NewCBORDecoder(r io.Reader) *CBORDecoder
NewCBORDecoder returns a decoder that reads from r.
func (*CBORDecoder) More ¶ added in v0.2.0
func (d *CBORDecoder) More(h CBORHead, n uint64) (bool, error)
More reports whether the container whose head is h has another item, when n items of it were read. For an item of indefinite length, it reads the break that ends it.
func (*CBORDecoder) PeekHead ¶ added in v0.2.0
func (d *CBORDecoder) PeekHead() (CBORHead, error)
PeekHead returns the head of the next item, and reads nothing.
func (*CBORDecoder) ReadHead ¶ added in v0.2.0
func (d *CBORDecoder) ReadHead() (CBORHead, error)
ReadHead reads the head of the next item. For a string, an array, a map or a tag, the content follows, and the caller reads it.
func (*CBORDecoder) ReadRaw ¶ added in v0.2.0
func (d *CBORDecoder) ReadRaw() ([]byte, error)
ReadRaw reads the next item whole, and returns its bytes, which the caller owns.
func (*CBORDecoder) ReadString ¶ added in v0.2.0
func (d *CBORDecoder) ReadString(h CBORHead) ([]byte, error)
ReadString reads the content of the byte string or the text string whose head is h, including each chunk of one of indefinite length.
func (*CBORDecoder) ReadText ¶ added in v0.2.0
func (d *CBORDecoder) ReadText() (string, error)
ReadText reads the next item, which must be a text string.
func (*CBORDecoder) Skip ¶ added in v0.2.0
func (d *CBORDecoder) Skip() error
Skip reads the next item whole, and keeps none of it.
type CBOREncoder ¶ added in v0.2.0
type CBOREncoder struct {
// contains filtered or unexported fields
}
CBOREncoder appends CBOR items to a buffer.
func (*CBOREncoder) Array ¶ added in v0.2.0
func (e *CBOREncoder) Array(n int)
Array appends the head of an array of n items, which the caller appends.
func (*CBOREncoder) Bool ¶ added in v0.2.0
func (e *CBOREncoder) Bool(b bool)
Bool appends true or false.
func (*CBOREncoder) ByteString ¶ added in v0.2.0
func (e *CBOREncoder) ByteString(b []byte)
ByteString appends a byte string.
func (*CBOREncoder) Bytes ¶ added in v0.2.0
func (e *CBOREncoder) Bytes() []byte
Bytes returns what the encoder holds.
func (*CBOREncoder) Float ¶ added in v0.2.0
func (e *CBOREncoder) Float(f float64)
Float appends a float64.
func (*CBOREncoder) Head ¶ added in v0.2.0
func (e *CBOREncoder) Head(m CBORMajor, arg uint64)
Head appends the head of an item of major type m with the argument arg, in its shortest form.
func (*CBOREncoder) Int ¶ added in v0.2.0
func (e *CBOREncoder) Int(i int64)
Int appends an integer.
func (*CBOREncoder) Map ¶ added in v0.2.0
func (e *CBOREncoder) Map(n int)
Map appends the head of a map of n pairs, which the caller appends.
func (*CBOREncoder) Raw ¶ added in v0.2.0
func (e *CBOREncoder) Raw(b []byte)
Raw appends an item that is already encoded.
func (*CBOREncoder) Tag ¶ added in v0.2.0
func (e *CBOREncoder) Tag(num uint64)
Tag appends the tag num, whose item the caller appends.
func (*CBOREncoder) Text ¶ added in v0.2.0
func (e *CBOREncoder) Text(s string)
Text appends a text string.
func (*CBOREncoder) Uint ¶ added in v0.2.0
func (e *CBOREncoder) Uint(u uint64)
Uint appends an unsigned integer.
type CBORHead ¶ added in v0.2.0
type CBORHead struct {
// Major is the major type.
Major CBORMajor
// Info is the additional information of the first byte, from 0 to 31.
Info byte
// Arg is the argument. It is the value of an integer, the length of a
// string, an array or a map, the number of a tag, the bits of a float,
// or the number of a simple value. It is 0 for an item of indefinite
// length.
Arg uint64
}
CBORHead is the head of one CBOR item: its major type and its argument.
func (CBORHead) Bool ¶ added in v0.2.0
Bool reports whether the item is true or false, and returns it.
func (CBORHead) Break ¶ added in v0.2.0
Break reports whether the head is the break that ends an item of indefinite length.
func (CBORHead) Indefinite ¶ added in v0.2.0
Indefinite reports whether the item has an indefinite length, which a break ends.
type CBORMajor ¶ added in v0.2.0
type CBORMajor byte
CBORMajor is the major type of a CBOR item.
const ( CBORUint CBORMajor = 0 CBORNegInt CBORMajor = 1 CBORBytes CBORMajor = 2 CBORText CBORMajor = 3 CBORArray CBORMajor = 4 CBORMap CBORMajor = 5 CBORTag CBORMajor = 6 // CBORSimple holds false, true, null, undefined, the floats and the // break that ends an item of indefinite length. CBORSimple CBORMajor = 7 )
The major types of CBOR, from section 3.1 of RFC 8949.
type Date ¶ added in v0.7.0
Date is a day of the calendar, with no time and no zone, such as 2026-09-30.
func ParseDate ¶ added in v0.7.0
ParseDate reads a date as String writes it, such as 2026-09-30, -0044-03-15 or +10000-01-01.
func (Date) In ¶ added in v0.7.0
In returns the time.Time of midnight at the start of the date in loc.
func (Date) IsValid ¶ added in v0.7.0
IsValid reports whether the date is a day of the calendar, which February 30 is not.
type Error ¶
type Error string
Error is an error of this package.
const ( // ErrNotSupported is the error for a feature that the database does not // have, such as a transaction (D20). ErrNotSupported Error = "not supported" // ErrScheme is the error for a DSN whose scheme is not the name of the // driver (D35). ErrScheme Error = "wrong scheme" // ErrUnknownKey is the error for a key in the query of a DSN that the // driver does not know (D27). ErrUnknownKey Error = "unknown key" // ErrRepeatedKey is the error for a key that appears more than once in // the query of a DSN (D27). ErrRepeatedKey Error = "repeated key" // ErrInvalidValue is the error for a value that has the wrong form. ErrInvalidValue Error = "invalid value" // ErrExtraColumn is the error for a row that has a column that the first // row does not have (D18). ErrExtraColumn Error = "column not in the first row" // ErrColumnCount is the error for a row that has the wrong number of // columns. ErrColumnCount Error = "wrong number of columns" // ErrIncomplete is the error for a result set that failed, or that the // server cut short, after at least one of its rows reached the caller // (D21 and D107). A failure before the first row does not wrap it. ErrIncomplete Error = "result is incomplete" // ErrUnterminated is the error for a statement that ends inside a // literal, a quoted identifier or a comment. ErrUnterminated Error = "unterminated literal or comment" // ErrArguments is the error for arguments that do not match the // placeholders of a statement (D34). ErrArguments Error = "arguments do not match the placeholders" )
Error values.
type Interval ¶ added in v0.7.0
Interval is a length of the calendar: months, days, and an exact time, as PostgreSQL and the Arrow type Interval(MonthDayNano) keep it. A month and a day have no fixed length, so the three parts stay apart. Each part carries its own sign.
func ParseInterval ¶ added in v0.7.0
ParseInterval reads an interval in ISO 8601, such as P1Y2M3DT4H5M6.5S, P2W, PT-1.5S or -P1D. Each part can have a sign, and a sign before the P turns every part around.
type LocalDateTime ¶ added in v0.7.0
LocalDateTime is a date and a time of day, with no zone, such as 2026-09-30T12:30:00.5. It names no instant until a caller names a location.
func LocalDateTimeOf ¶ added in v0.7.0
func LocalDateTimeOf(t time.Time) LocalDateTime
LocalDateTimeOf returns the date and the time of day of t, in the location of t.
func ParseLocalDateTime ¶ added in v0.7.0
func ParseLocalDateTime(s string) (LocalDateTime, error)
ParseLocalDateTime reads a date and a time as String writes it, such as 2026-09-30T12:30:00.5. It takes a space in place of the T too, as SQL writes a timestamp.
func (LocalDateTime) In ¶ added in v0.7.0
func (dt LocalDateTime) In(loc *time.Location) time.Time
In returns the time.Time of the date and the time in loc. A time that loc skips, as a zone does when its clock moves forward, moves as time.Date moves it.
func (LocalDateTime) IsValid ¶ added in v0.7.0
func (dt LocalDateTime) IsValid() bool
IsValid reports whether the date and the time are both valid.
func (LocalDateTime) String ¶ added in v0.7.0
func (dt LocalDateTime) String() string
String writes the date and the time in ISO 8601, joined by a T.
type LocalTime ¶ added in v0.7.0
LocalTime is a time of day, with no date and no zone, such as 12:30:00.5. Hour is from 0 to 23.
func LocalTimeOf ¶ added in v0.7.0
LocalTimeOf returns the time of day of t, in the location of t.
func ParseLocalTime ¶ added in v0.7.0
ParseLocalTime reads a time of day as String writes it, such as 12:30, 12:30:00 or 12:30:00.123456789.
func (LocalTime) In ¶ added in v0.7.0
In returns the time.Time of the time of day on 0000-01-01 in loc, as lib/pq gives a time of day.
func (LocalTime) IsValid ¶ added in v0.7.0
IsValid reports whether each part of the time is in its range.
type ObjectRows ¶
type ObjectRows struct {
// contains filtered or unexported fields
}
ObjectRows reads a JSON array of objects as rows, by rule 2 of D18.
The columns are the keys of the first object, in the order that they arrive, or the columns that the server named. A key that a later object lacks is a nil value. A key that only a later object has is an error, and never a new column. A JSON null is the value "null", so a driver can tell a null from a missing key if its product has both.
func ContinueObjectRows ¶
func ContinueObjectRows(dec *jsontext.Decoder, cols []string) (*ObjectRows, error)
ContinueObjectRows is NewObjectRows for a caller that has read the start of the array, such as to peek at the kind of the first row.
func NewObjectRows ¶
func NewObjectRows(dec *jsontext.Decoder, cols []string) (*ObjectRows, error)
NewObjectRows reads the start of an array of objects from dec. If cols is nil, it reads the first object to learn the columns, and Next returns that object first.
func (*ObjectRows) Columns ¶
func (r *ObjectRows) Columns() []string
Columns returns the columns of the rows.
type OffsetTime ¶ added in v0.7.0
OffsetTime is a time of day with an offset from UTC and no date, such as 12:30:00.5+01:00, as the TIME of Neo4j and the TIME WITH TIME ZONE of SQL hold it (D139). Offset is in seconds east of UTC.
func OffsetTimeOf ¶ added in v0.7.0
func OffsetTimeOf(t time.Time) OffsetTime
OffsetTimeOf returns the time of day of t and the offset of its zone.
func ParseOffsetTime ¶ added in v0.7.0
func ParseOffsetTime(s string) (OffsetTime, error)
ParseOffsetTime reads a time of day and an offset as String writes it, such as 12:30:00Z, 12:30:00.5+01:00 or 12:30-05:30:15.
func (OffsetTime) IsValid ¶ added in v0.7.0
func (t OffsetTime) IsValid() bool
IsValid reports whether the time of day is valid, and the offset is less than 24 hours.
func (OffsetTime) String ¶ added in v0.7.0
func (t OffsetTime) String() string
String writes the time of day and the offset in ISO 8601, with Z for an offset of zero, and the seconds of an offset only when it has them.
func (OffsetTime) ToTime ¶ added in v0.7.0
func (t OffsetTime) ToTime() time.Time
ToTime returns the time.Time of the time of day on 0000-01-01, in a fixed zone of the offset, as lib/pq gives a TIMETZ.
type Option ¶ added in v0.6.0
type Option[T any] func(*T)
Option sets one option of a statement or of a transaction of a driver, whose options are the struct T (D109). A driver names it as its own type, such as type Option = dbimp.Option[options], so that the options of two drivers cannot be mixed.
type Placeholder ¶
type Placeholder struct {
// Offset is the byte offset of the placeholder in the statement.
Offset int
// Len is the length of the placeholder in bytes.
Len int
// Name is the name of an @name placeholder without the @, and "" for a ?.
Name string
// Double is true for an @@name placeholder, which only a Syntax with
// DoubleAt returns.
Double bool
}
Placeholder is one placeholder in a statement.
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query holds the keys of the query of a DSN. NewQuery refuses a key that is unknown or repeated, so a value that Query returns is the only value of its key.
func NewQuery ¶
NewQuery reads the query of u. It returns an error for a key that is not in known, and for a key that appears more than once (D27).
func (Query) Auth ¶ added in v0.6.0
Auth returns the value of the key key, AuthBasic or AuthBearer, and AuthBasic if the query does not hold it.
func (Query) Bool ¶
Bool returns the value of key as a bool, or def if the query does not hold key. It takes the forms that strconv.ParseBool takes.
func (Query) Duration ¶
Duration returns the value of key as a time.Duration, or def if the query does not hold key. It takes the forms that time.ParseDuration takes.
type StatusError ¶
type StatusError struct {
// Code is the status code of the response.
Code int
// Body is the start of the body of the response, at most 64 KiB.
Body string
}
StatusError is the error for a response whose status is not 2xx. HTTP 429 and HTTP 503 are a StatusError too, and nothing retries them (D8).
func (*StatusError) Error ¶
func (err *StatusError) Error() string
Error satisfies the error interface.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream reads the body of a response one token at a time (D36). It holds the body and a jsontext.Decoder that reads from it, and no other buffer, because the decoder keeps its own.
A driver reads the rows through Decoder, and calls End after the last value of the response. Close before End closes the body and reads nothing more, so a large result is never drained. Close after End closes a body that is at EOF, so the connection goes back to the pool.
func NewStream ¶
func NewStream(body io.ReadCloser) *Stream
NewStream returns a Stream that reads body.
func (*Stream) Close ¶
Close closes the body. It reads nothing more from it. It can run more than once, and returns the same error each time.
type Syntax ¶
type Syntax struct {
// Quotes holds each character that opens and closes a literal or a quoted
// identifier, such as `'"` or "'\"`". Inside one, the character written
// twice stands for itself.
Quotes string
// Backslash is true if a backslash inside a quote escapes the character
// after it.
Backslash bool
// DashComments is true if -- starts a comment that ends at a new line.
DashComments bool
// HashComments is true if # starts a comment that ends at a new line.
HashComments bool
// BlockComments is true if /* starts a comment that ends at */.
BlockComments bool
// SlashComments is true if // starts a comment that ends at a new line,
// as in AQL.
SlashComments bool
// DoubleAt is true if @@name is a placeholder of its own, whose Double is
// true, as a parameter that names a collection in AQL (D104). Without it,
// @@name is no placeholder, as @@version is not in MySQL.
DoubleAt bool
// DigitNames is true if a name can start with a digit, as @1 in AQL.
DigitNames bool
}
Syntax says how a product writes literals, quoted identifiers and comments, so that the parser for placeholders can skip them (D34). The zero value knows no quote and no comment.
func (Syntax) Bind ¶
func (s Syntax) Bind(query string, args []driver.NamedValue, lit func(v any) (string, error)) (string, error)
Bind writes each argument into query as a literal, for a server that binds no arguments (D34). A ? takes the next argument that has no name, in order, and an @name takes the argument with that name. lit writes one value as a literal of the product, and each driver supplies its own, because each product quotes in its own way. Bind returns an error if an argument is missing, or if an argument is left over.
func (Syntax) Placeholders ¶
func (s Syntax) Placeholders(query string) ([]Placeholder, error)
Placeholders returns each ? and each @name in query, in order. It skips literals, quoted identifiers and comments. An @ that another @ follows, as in @@version, is not a placeholder, unless the Syntax has DoubleAt. It returns an error if query ends inside a literal, a quoted identifier or a comment.
type Vector ¶ added in v0.7.0
type Vector[T VectorElement] []T
Vector is a vector: numbers of one type, for a search by similarity, such as the VECTOR of Neo4j and of Databend (D139). It is a slice, so it scans into a slice of its elements too. A driver sends a Vector as a vector, and a plain slice as a list.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package arangodb is a database/sql driver for ArangoDB, which runs AQL over the cursor API of HTTP.
|
Package arangodb is a database/sql driver for ArangoDB, which runs AQL over the cursor API of HTTP. |
|
Package avatica is a database/sql driver for Apache Calcite Avatica, which carries the calls of JDBC over HTTP to a server that runs them on a database behind it.
|
Package avatica is a database/sql driver for Apache Calcite Avatica, which carries the calls of JDBC over HTTP to a server that runs them on a database behind it. |
|
Package couchbase is a database/sql driver for the query service of Couchbase Server, which runs SQL++ (N1QL) over HTTP.
|
Package couchbase is a database/sql driver for the query service of Couchbase Server, which runs SQL++ (N1QL) over HTTP. |
|
Package databend is a database/sql driver for Databend, which runs SQL over the query API of HTTP.
|
Package databend is a database/sql driver for Databend, which runs SQL over the query API of HTTP. |
|
Package dbimptest holds the test helpers that every driver in github.com/xo/dbimp shares.
|
Package dbimptest holds the test helpers that every driver in github.com/xo/dbimp shares. |
|
cmd/record
command
Command record sends the requests of step 6 of docs/DRIVER.md to a real server, as the administrator and as the ordinary user, and writes each exchange and the manifest into testdata/<driver>/.
|
Command record sends the requests of step 6 of docs/DRIVER.md to a real server, as the administrator and as the ordinary user, and writes each exchange and the manifest into testdata/<driver>/. |
|
Package influxdb is a database/sql driver for InfluxDB 1, InfluxDB 2, and InfluxDB 3 and later (D78).
|
Package influxdb is a database/sql driver for InfluxDB 1, InfluxDB 2, and InfluxDB 3 and later (D78). |
|
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.
|
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. |
|
Package neo4j is a database/sql driver for Neo4j, which runs Cypher over the Query API of HTTP.
|
Package neo4j is a database/sql driver for Neo4j, which runs Cypher over the Query API of HTTP. |
|
Package pinot is a database/sql driver for Apache Pinot, which runs SQL on a Broker over HTTP.
|
Package pinot is a database/sql driver for Apache Pinot, which runs SQL on a Broker over HTTP. |
|
Package rqlite is a database/sql driver for rqlite, which runs SQLite on each node of a cluster, and takes SQL over HTTP.
|
Package rqlite is a database/sql driver for rqlite, which runs SQLite on each node of a cluster, and takes SQL over HTTP. |
|
Package surrealdb is a database/sql driver for SurrealDB, which runs SurrealQL over HTTP.
|
Package surrealdb is a database/sql driver for SurrealDB, which runs SurrealQL over HTTP. |