database.aug
A database with SQLite · Source and specification
Files in this project
Code
// aug-spec: "database.aug.md" explains this file. Read it before changes; refresh with aug spec.
import Database and SqliteError and openMemory and execute and queryScalar from "https://github.com/GreenPandaStudios/aug-sqlite#43d8c33289b6b9310199f8c65fb83d48cd9dc310"
/** Store a bound value in an in-memory SQLite database and read it back. */
storedName() returns string unless SqliteError:
own Database database = openMemory()
borrow database:
execute(
database,
sql="CREATE TABLE users (name TEXT NOT NULL)",
parameters=[]
)
execute(
database,
sql="INSERT INTO users (name) VALUES (?)",
parameters=["August"]
)
return queryScalar(database, sql="SELECT name FROM users", parameters=[])
test storedName:
when "database":
it "inserts_and_queries_bound_data":
assert(storedName() == "August")// aug-spec: "database.aug.md" explains this file. Read it before changes; refresh with aug spec.
import Database and SqliteError and openMemory and execute and queryScalar from "https://github.com/GreenPandaStudios/aug-sqlite#43d8c33289b6b9310199f8c65fb83d48cd9dc310"
/** Store a bound value in an in-memory SQLite database and read it back. */
storedName() returns string unless SqliteError {
own Database database = openMemory()
borrow database {
execute(
database,
sql="CREATE TABLE users (name TEXT NOT NULL)",
parameters=[]
)
execute(
database,
sql="INSERT INTO users (name) VALUES (?)",
parameters=["August"]
)
}
return queryScalar(database, sql="SELECT name FROM users", parameters=[])
}
test storedName {
when "database" {
it "inserts_and_queries_bound_data" {
assert(storedName() == "August")
}
}
}Compiled specification
storedName · source
Store a bound value in an in-memory SQLite database and read it back. Failures can raise SqliteError.
It calls openMemory and stores the result in owned database (Database). With temporary permission to change database, it calls execute with database, sql "CREATE TABLE users (name TEXT NOT NULL)", and parameters from a list with no items; then it calls execute with database, sql "INSERT INTO users (name) VALUES (?)", and parameters from a list containing "August". It returns queryScalar with database, sql "SELECT name FROM users", and parameters from a list with no items. source
test storedName · source
Tests storedName. Each case gets fresh setup and dependencies.
database
The test requires storedName equals "August". source
Dependencies
It uses execute, openMemory, queryScalar, Database, and SqliteError from https://github.com/GreenPandaStudios/aug-sqlite#43d8c33289b6b9310199f8c65fb83d48cd9dc310.
Built-in operations follow the language reference.