Skip to content

Latest commit

 

History

History
34 lines (24 loc) · 782 Bytes

File metadata and controls

34 lines (24 loc) · 782 Bytes

Querying

Raw calls D1 /raw. It returns columns and rows separately.

results, err := client.Raw(ctx, "SELECT id, email FROM users WHERE id = ?", 1)

Query calls D1 /query. It returns object-shaped rows.

results, err := client.Query(ctx, "SELECT id, email FROM users WHERE id = ?", 1)

Both return a slice because D1 can execute multiple statements in one request.

Use metadata:

meta := results[0].Meta
fmt.Println(meta.RowsReadInt64())
fmt.Println(meta.RowsWrittenInt64())
fmt.Println(meta.Duration)

Batch:

results, err := client.BatchRaw(ctx, []d1http.Statement{
    {SQL: "INSERT INTO users (id, email) VALUES (?, ?)", Params: []any{1, "a@example.com"}},
    {SQL: "SELECT * FROM users WHERE id = ?", Params: []any{1}},
})