Documentation.

This commit is contained in:
Nuno Cruces
2023-03-10 15:50:11 +00:00
parent dbaed53b9a
commit f61d430e65
5 changed files with 30 additions and 9 deletions

View File

@@ -30,8 +30,10 @@ For non-WAL databases, `NORMAL` locking mode can be activated with
[`PRAGMA locking_mode=NORMAL`](https://www.sqlite.org/pragma.html#pragma_locking_mode).
Because connection pooling is incompatible with `EXCLUSIVE` locking mode,
the `database/sql` driver defaults to `NORMAL` locking mode,
and WAL databases are not supported.
the `database/sql` driver defaults to `NORMAL` locking mode.
To open WAL databases, or use `EXCLUSIVE` locking mode,
disable connection pooling by calling
[`db.SetMaxOpenConns(1)`](https://pkg.go.dev/database/sql#DB.SetMaxOpenConns).
#### Open File Description Locks

View File

@@ -3,6 +3,7 @@ package sqlite3
import (
"context"
"database/sql/driver"
"errors"
"fmt"
"net/url"
"runtime"
@@ -91,8 +92,11 @@ func (c *Conn) openDB(filename string, flags OpenFlag) (uint32, error) {
pragmaPtr := c.arena.string(pragmas.String())
r := c.call(c.api.exec, uint64(handle), uint64(pragmaPtr), 0, 0, 0)
if err := c.module.error(r[0], handle, pragmas.String()); err != nil {
if errors.Is(err, ERROR) {
err = fmt.Errorf("sqlite3: invalid _pragma: %w", err)
}
c.closeDB(handle)
return 0, fmt.Errorf("sqlite3: invalid _pragma: %w", err)
return 0, err
}
}
return handle, nil

View File

@@ -96,6 +96,7 @@ var (
// Ensure these interfaces are implemented:
_ driver.ExecerContext = conn{}
_ driver.ConnBeginTx = conn{}
_ driver.Validator = conn{}
_ sqlite3.DriverConn = conn{}
)
@@ -103,6 +104,11 @@ func (c conn) Close() error {
return c.conn.Close()
}
func (c conn) IsValid() (valid bool) {
r, err := c.conn.Pragma("locking_mode")
return err == nil && len(r) == 1 && r[0] == "normal"
}
func (c conn) Begin() (driver.Tx, error) {
return c.BeginTx(context.Background(), driver.TxOptions{})
}

15
embed/README.md Normal file
View File

@@ -0,0 +1,15 @@
# Embeddable WASM build of SQLite
This folder includes an embeddable WASM build of SQLite 3.41.0 for use with
[`github.com/ncruces/go-sqlite3`](https://pkg.go.dev/github.com/ncruces/go-sqlite3).
The following optional features are compiled in:
- math functions
- FTS3/4/5
- JSON
- R*Tree
- GeoPoly
See the [configuration options](../sqlite3/sqlite_cfg.h).
Built using [`zig`](https://ziglang.org/) version 0.10.1.

View File

@@ -4,12 +4,6 @@
// with an appropriate build of SQLite:
//
// import _ "github.com/ncruces/go-sqlite3/embed"
//
// The following optional features are compiled in:
// math functions, JSON, FTS3/4/5, R*Tree, GeoPoly.
//
// You can obtain this build of SQLite from:
// https://github.com/ncruces/go-sqlite3/tree/main/embed
package embed
import (