d1driver

package
v0.1.42 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: AGPL-3.0 Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Rendered for js/wasm

Overview

Package d1driver implements database/sql over a Cloudflare D1 binding. D1 exposes SQLite integers as JavaScript numbers. Values outside the safe integer range (-(2^53-1) through 2^53-1) are rejected to avoid rounding.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrReadInTx marks a query in a buffered D1 transaction. D1 cannot provide
	// an interactive read-then-write transaction.
	ErrReadInTx = errors.New("d1driver: query inside a buffered transaction is not supported")
	// ErrDeferredResult marks result fields that are unavailable before a batch commits.
	ErrDeferredResult = errors.New("d1driver: result is deferred until the transaction commits")
	// ErrUnsafeInteger marks an integer that JavaScript cannot represent exactly.
	ErrUnsafeInteger = errors.New("d1driver: integer exceeds JavaScript's safe integer range")
)

Functions

func Await added in v0.1.26

func Await(ctx context.Context, p js.Value) (js.Value, error)

Await blocks the calling goroutine until a JavaScript promise settles; the edge shell's static-asset reader uses it too. It returns as soon as the context is canceled, even if the promise remains pending.

func Batch

func Batch(ctx context.Context, db js.Value, statements []Statement) error

Batch sends statements in one D1 batch. D1 guarantees the batch is atomic.

func NewConnector

func NewConnector(db js.Value) driver.Connector

NewConnector creates a database/sql connector around a D1 binding.

func Open

func Open(db js.Value) *sql.DB

Open creates a database/sql pool around a D1 binding.

Types

type BatchResult

type BatchResult struct {
	RowsAffected int64
	Rows         [][]any
}

BatchResult is the D1 outcome of one statement after its batch has committed.

func BatchResults

func BatchResults(ctx context.Context, db js.Value, statements []Statement) ([]BatchResult, error)

BatchResults sends statements in one D1 batch and collects metadata and rows for statements marked Returning.

func BatchResultsDB

func BatchResultsDB(ctx context.Context, db *sql.DB, statements []Statement) ([]BatchResult, error)

BatchResultsDB gets the D1 binding from a pooled database/sql connection and executes one native batch, bypassing database/sql's deferred transaction results.

type Statement

type Statement struct {
	Query     string
	Args      []any
	Returning bool
}

Statement is one SQL statement sent as part of an atomic D1 batch.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL