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 ¶
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 ¶
Delete removes a database's file, and the files SQLite keeps beside it. Close it first.
func Open ¶
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.