Documentation
¶
Overview ¶
Package db is the server's access to the tables, in Cloudflare D1 or any supported SQL database (PostgreSQL, MySQL, SQLite).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
Config chooses the backend: URL (postgres://, mysql://, sqlite:///path, d1://) or, when it is empty or d1://, the D1 credentials.
type DB ¶
type DB interface {
Dialect() sdk.Dialect
// Name describes the backend for people ("PostgreSQL", "Cloudflare D1").
Name() string
// Query runs a statement the server built. "?" placeholders.
Query(ctx context.Context, query string, args ...any) (*Rows, error)
// QueryUntrusted runs SQL from a person or the model: read-only and
// time-limited wherever the database can enforce it.
QueryUntrusted(ctx context.Context, query string) (*Rows, error)
Exec(ctx context.Context, query string, args ...any) error
ExecScript(ctx context.Context, script string) error
// InsertID runs an INSERT into a table with an "id" key and returns it.
InsertID(ctx context.Context, query string, args ...any) (int64, error)
Close() error
}
type QueryError ¶
type QueryError struct{ Err error }
QueryError is the database rejecting a statement (syntax, unknown column, timeout), as opposed to the database being unreachable. Its message is safe to show and to feed back to the model.
func (*QueryError) Error ¶
func (e *QueryError) Error() string
func (*QueryError) Unwrap ¶
func (e *QueryError) Unwrap() error