sqlite

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package sqlite is a SQLite database on the phone, through Go's own database/sql. It uses the SQLite that comes with iOS and Android, so it adds nothing to the app's size and needs no cgo.

nimbus native plugin add sqlite

db, err := sqlite.Open("cafe.db")
_, err = db.ExecContext(ctx, `CREATE TABLE IF NOT EXISTS orders (id INTEGER PRIMARY KEY, item TEXT, total REAL)`)
_, err = db.ExecContext(ctx, `INSERT INTO orders (item, total) VALUES (?, ?)`, "Latte", 180.0)
rows, err := db.QueryContext(ctx, `SELECT id, item FROM orders ORDER BY id DESC`)

The database is a file in the app's own folder on the phone, so it stays there under `nimbus native dev` too, while Go runs on your Mac.

Index

Constants

View Source
const DriverName = "nimbus-sqlite"

DriverName is the name the driver is registered under, for sql.Open: sql.Open(sqlite.DriverName, "cafe.db") is Open without its one-connection limit, which only matters if you change it.

Variables

This section is empty.

Functions

func Delete

func Delete(ctx context.Context, name string) error

Delete removes a database's file, and the files SQLite keeps beside it. Close it first.

func Open

func Open(name string) (*sql.DB, error)

Open opens the database in the app's data folder, making it if needed. name is a file name such as "cafe.db", or ":memory:" for one that's gone when it closes. The *sql.DB holds one connection, so statements run one at a time and a transaction has the database to itself: that's how SQLite works best on a phone.

Types

type Driver

type Driver struct{}

Driver is the database/sql driver. Open and sql.Open use it; you don't need to.

func (Driver) Open

func (Driver) Open(name string) (driver.Conn, error)

Open opens a connection to the named database.

type Error

type Error struct {
	Message string // SQLite's own words, such as "UNIQUE constraint failed: orders.item"
}

Error is SQLite refusing a statement: a syntax error, a constraint, a missing table.

func (*Error) Error

func (e *Error) Error() string

Jump to

Keyboard shortcuts

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