Documentation
¶
Overview ¶
Package cloudflare adapts the SQLite storage of a Cloudflare Durable Object to the portable Chord SQLite facade. It is the Go counterpart of Pi's `@earendil-works/chord/sqlite/cloudflare` and links no SQLite driver or Workers binding: the caller supplies the Durable Object's `ctx.storage` as a DurableObjectSqliteStorage.
Index ¶
- type DurableObjectSql
- type DurableObjectSqlCursor
- type DurableObjectSqlValue
- type DurableObjectSqliteDatabase
- func (database *DurableObjectSqliteDatabase) All(sql string, params ...chordsqlite.SqliteValue) (rows []chordsqlite.SqliteRow, err error)
- func (database *DurableObjectSqliteDatabase) Close() error
- func (database *DurableObjectSqliteDatabase) Exec(sql string) error
- func (database *DurableObjectSqliteDatabase) Get(sql string, params ...chordsqlite.SqliteValue) (row chordsqlite.SqliteRow, err error)
- func (database *DurableObjectSqliteDatabase) Run(sql string, params ...chordsqlite.SqliteValue) error
- func (database *DurableObjectSqliteDatabase) Transaction(callback func(transaction chordsqlite.SqliteExecutor) error) error
- type DurableObjectSqliteStorage
- type RangeError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DurableObjectSql ¶
type DurableObjectSql interface {
// Exec runs one statement with positional bindings; without bindings it may run several statements.
Exec(query string, bindings ...DurableObjectSqlValue) (DurableObjectSqlCursor, error)
}
DurableObjectSql is the `ctx.storage.sql` of a SQLite-backed Durable Object.
type DurableObjectSqlCursor ¶
type DurableObjectSqlCursor interface {
// Next returns the next result row keyed by column name, and false once there are no more. Get reads no further.
Next() (row map[string]DurableObjectSqlValue, ok bool, err error)
// ToArray returns the result rows not yet read keyed by column name; empty for a statement that returns none.
ToArray() ([]map[string]DurableObjectSqlValue, error)
}
DurableObjectSqlCursor is the result of one statement.
type DurableObjectSqlValue ¶
type DurableObjectSqlValue = any
DurableObjectSqlValue is a value a Durable Object SQL binding accepts and returns: []byte (an ArrayBuffer), string, a number (float64 or any Go integer), or nil.
type DurableObjectSqliteDatabase ¶
type DurableObjectSqliteDatabase struct {
// contains filtered or unexported fields
}
DurableObjectSqliteDatabase is the SqliteDatabase adapter for the SQLite storage of a Cloudflare Durable Object. Adapters given the same storage object share a queue; direct calls to the underlying storage bypass it. Integers are numbers; binding an integer outside the safe integer range is a RangeError.
func NewDurableObjectSqliteDatabase ¶
func NewDurableObjectSqliteDatabase(storage DurableObjectSqliteStorage) *DurableObjectSqliteDatabase
NewDurableObjectSqliteDatabase adapts the `ctx.storage` of a SQLite-backed Durable Object.
func (*DurableObjectSqliteDatabase) All ¶
func (database *DurableObjectSqliteDatabase) All(sql string, params ...chordsqlite.SqliteValue) (rows []chordsqlite.SqliteRow, err error)
All returns every result row.
func (*DurableObjectSqliteDatabase) Close ¶
func (database *DurableObjectSqliteDatabase) Close() error
Close waits for queued work. The Durable Object owns its storage, so nothing else closes.
func (*DurableObjectSqliteDatabase) Exec ¶
func (database *DurableObjectSqliteDatabase) Exec(sql string) error
Exec runs SQL text without bindings behind every earlier operation.
func (*DurableObjectSqliteDatabase) Get ¶
func (database *DurableObjectSqliteDatabase) Get(sql string, params ...chordsqlite.SqliteValue) (row chordsqlite.SqliteRow, err error)
Get returns the first result row, or nil when there is none.
func (*DurableObjectSqliteDatabase) Run ¶
func (database *DurableObjectSqliteDatabase) Run(sql string, params ...chordsqlite.SqliteValue) error
Run executes one statement with positional bindings behind every earlier operation.
func (*DurableObjectSqliteDatabase) Transaction ¶
func (database *DurableObjectSqliteDatabase) Transaction(callback func(transaction chordsqlite.SqliteExecutor) error) error
Transaction runs callback in `ctx.storage.Transaction`, which commits when the callback returns nil and rolls back when it fails. The handle the callback receives is invalid once the callback returns.
type DurableObjectSqliteStorage ¶
type DurableObjectSqliteStorage interface {
Sql() DurableObjectSql
// Transaction runs closure, committing when it returns nil and rolling back when it returns an error, which
// Transaction returns.
Transaction(closure func() error) error
}
DurableObjectSqliteStorage is the parts of a SQLite-backed Durable Object's `ctx.storage` this adapter uses.
type RangeError ¶
type RangeError struct{ Value int64 }
RangeError reports a binding that Durable Object SQL cannot keep exactly: it binds numbers as doubles, so an integer outside the safe integer range would lose precision.
func (*RangeError) Error ¶
func (err *RangeError) Error() string