Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .github/workflows/repro.sh

This file was deleted.

31 changes: 0 additions & 31 deletions .github/workflows/repro.yml

This file was deleted.

39 changes: 11 additions & 28 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ jobs:
shell: bash
run: |
go work init .
go work use -r embed/bcw2 gormlite
go test ./embed/bcw2 ./gormlite
go work use -r gormlite
go test ./gormlite

- name: Test GORM
shell: bash
Expand Down Expand Up @@ -104,6 +104,7 @@ jobs:
- name: illumos
action: omnios
version: 'r151056'
tflags: '-test.short'
- name: openbsd
version: '7.8'
tflags: '-test.short'
Expand Down Expand Up @@ -144,11 +145,14 @@ jobs:
os:
- name: dragonfly
action: 'vmactions/dragonflybsd-vm@v1'
tflags: '-test.short'
- name: illumos
action: 'vmactions/openindiana-vm@v0'
tflags: '-test.short'
- name: solaris
action: 'vmactions/solaris-vm@v1'
bflags: '-tags sqlite3_dotlk'
tflags: '-test.short'
runs-on: ubuntu-latest
needs: test

Expand All @@ -166,27 +170,6 @@ jobs:
- name: Test
uses: ./.github/actions/vmactions

test-wasip1:
runs-on: ubuntu-latest
needs: test

steps:
- uses: bytecodealliance/actions/wasmtime/setup@v1
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with: { go-version: stable }

- name: Set path
run: echo "$(go env GOROOT)/lib/wasm" >> "$GITHUB_PATH"

- name: Test wasmtime
env:
GOOS: wasip1
GOARCH: wasm
GOWASIRUNTIME: wasmtime
GOWASIRUNTIMEARGS: '--env CI=true'
run: go test -short -tags sqlite3_dotlk -skip Example ./...

test-qemu:
runs-on: ubuntu-latest
needs: test
Expand All @@ -198,15 +181,15 @@ jobs:
with: { go-version: stable }

- name: Test 386 (32-bit)
run: GOARCH=386 go test -short ./...
run: GOARCH=386 go test ./...

- name: Test riscv64 (interpreter)
- name: Test riscv64
run: GOARCH=riscv64 go test -short ./...

- name: Test ppc64le (interpreter)
- name: Test ppc64le
run: GOARCH=ppc64le go test -short ./...

- name: Test loong64 (interpreter)
- name: Test loong64
run: GOARCH=loong64 go test -short ./...

- name: Test s390x (big-endian)
Expand All @@ -225,7 +208,7 @@ jobs:
run: go test ./...

- name: Test arm (32-bit)
run: GOARCH=arm GOARM=7 go test -short ./...
run: GOARCH=arm GOARM=7 go test ./...

test-macintel:
runs-on: macos-15-intel
Expand Down
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Go bindings to SQLite using wazero
# Go bindings to SQLite using wasm2go

[![Go Reference](https://pkg.go.dev/badge/image)](https://pkg.go.dev/github.com/ncruces/go-sqlite3)
[![Go Report](https://goreportcard.com/badge/github.com/ncruces/go-sqlite3)](https://goreportcard.com/report/github.com/ncruces/go-sqlite3)
Expand All @@ -8,9 +8,9 @@ Go module `github.com/ncruces/go-sqlite3` is a `cgo`-free [SQLite](https://sqlit
It provides a [`database/sql`](https://pkg.go.dev/database/sql) compatible driver,
as well as direct access to most of the [C SQLite API](https://sqlite.org/cintro.html).

It wraps a [Wasm](https://webassembly.org/) [build](embed/) of SQLite,
and uses [wazero](https://wazero.io/) as the runtime.\
Go, wazero and [`x/sys`](https://pkg.go.dev/golang.org/x/sys) are the _only_ direct dependencies.
It wraps a [Wasm](https://webassembly.org/) build of SQLite,
and uses [wasm2go](https://github.com/ncruces/wasm2go) to translate it to Go.\
Go and [`x/sys`](https://pkg.go.dev/golang.org/x/sys) are the _only_ direct dependencies.

### Getting started

Expand All @@ -19,7 +19,6 @@ Using the [`database/sql`](https://pkg.go.dev/database/sql) driver:

import "database/sql"
import _ "github.com/ncruces/go-sqlite3/driver"
import _ "github.com/ncruces/go-sqlite3/embed"

var version string
db, _ := sql.Open("sqlite3", "file:demo.db")
Expand All @@ -34,8 +33,6 @@ db.QueryRow(`SELECT sqlite_version()`).Scan(&version)
- [`github.com/ncruces/go-sqlite3/driver`](https://pkg.go.dev/github.com/ncruces/go-sqlite3/driver)
provides a [`database/sql`](https://pkg.go.dev/database/sql) driver
([example](https://pkg.go.dev/github.com/ncruces/go-sqlite3/driver#example-package)).
- [`github.com/ncruces/go-sqlite3/embed`](https://pkg.go.dev/github.com/ncruces/go-sqlite3/embed)
embeds a build of SQLite into your application.
- [`github.com/ncruces/go-sqlite3/vfs`](https://pkg.go.dev/github.com/ncruces/go-sqlite3/vfs)
wraps the [C SQLite VFS API](https://sqlite.org/vfs.html) and provides a pure Go implementation.
- [`github.com/ncruces/go-sqlite3/gormlite`](https://pkg.go.dev/github.com/ncruces/go-sqlite3/gormlite)
Expand Down Expand Up @@ -64,7 +61,6 @@ db.QueryRow(`SELECT sqlite_version()`).Scan(&version)
- [statistics functions](https://pkg.go.dev/github.com/ncruces/go-sqlite3/ext/stats)
- [encryption at rest](vfs/adiantum/README.md)
- [many extensions](ext/README.md)
- [and more…](embed/README.md)

### Caveats

Expand All @@ -79,9 +75,7 @@ memory usage will be higher than alternatives.
### Testing

This project aims for [high test coverage](https://github.com/ncruces/go-sqlite3/wiki/Test-coverage-report).
It also benefits greatly from [SQLite's](https://sqlite.org/testing.html) and
[wazero's](https://tetrate.io/blog/introducing-wazero-from-tetrate/#:~:text=Rock%2Dsolid%20test%20approach)
thorough testing.
It also benefits greatly from [SQLite's](https://sqlite.org/testing.html) thorough testing.

Every commit is tested on:
* Linux: amd64, arm64, 386, arm, riscv64, ppc64le, loong64, s390x
Expand Down
24 changes: 12 additions & 12 deletions backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,22 @@ func (src *Conn) BackupInit(srcDB, dstURI string) (*Backup, error) {
}

func (c *Conn) backupInit(dst ptr_t, dstName string, src ptr_t, srcName string) (*Backup, error) {
defer c.arena.mark()()
dstPtr := c.arena.string(dstName)
srcPtr := c.arena.string(srcName)
defer c.arena.Mark()()
dstPtr := c.arena.String(dstName)
srcPtr := c.arena.String(srcName)

other := dst
if c.handle == dst {
other = src
}

ptr := ptr_t(c.call("sqlite3_backup_init",
stk_t(dst), stk_t(dstPtr),
stk_t(src), stk_t(srcPtr)))
ptr := ptr_t(c.wrp.Xsqlite3_backup_init(
int32(dst), int32(dstPtr),
int32(src), int32(srcPtr)))
if ptr == 0 {
defer c.closeDB(other)
rc := res_t(c.call("sqlite3_errcode", stk_t(dst)))
return nil, c.sqlite.error(rc, dst)
rc := res_t(c.wrp.Xsqlite3_errcode(int32(dst)))
return nil, c.errorFor(dst, rc)
}

return &Backup{
Expand All @@ -97,7 +97,7 @@ func (b *Backup) Close() error {
return nil
}

rc := res_t(b.c.call("sqlite3_backup_finish", stk_t(b.handle)))
rc := res_t(b.c.wrp.Xsqlite3_backup_finish(int32(b.handle)))
b.c.closeDB(b.otherc)
b.handle = 0
return b.c.error(rc)
Expand All @@ -108,7 +108,7 @@ func (b *Backup) Close() error {
//
// https://sqlite.org/c3ref/backup_finish.html#sqlite3backupstep
func (b *Backup) Step(nPage int) (done bool, err error) {
rc := res_t(b.c.call("sqlite3_backup_step", stk_t(b.handle), stk_t(nPage)))
rc := res_t(b.c.wrp.Xsqlite3_backup_step(int32(b.handle), int32(nPage)))
if rc == _DONE {
return true, nil
}
Expand All @@ -120,7 +120,7 @@ func (b *Backup) Step(nPage int) (done bool, err error) {
//
// https://sqlite.org/c3ref/backup_finish.html#sqlite3backupremaining
func (b *Backup) Remaining() int {
n := int32(b.c.call("sqlite3_backup_remaining", stk_t(b.handle)))
n := int32(b.c.wrp.Xsqlite3_backup_remaining(int32(b.handle)))
return int(n)
}

Expand All @@ -129,6 +129,6 @@ func (b *Backup) Remaining() int {
//
// https://sqlite.org/c3ref/backup_finish.html#sqlite3backuppagecount
func (b *Backup) PageCount() int {
n := int32(b.c.call("sqlite3_backup_pagecount", stk_t(b.handle)))
n := int32(b.c.wrp.Xsqlite3_backup_pagecount(int32(b.handle)))
return int(n)
}
Loading
Loading