Skip to main content

Module database

Module database 

Source
Expand description

database: connections, and the queries made on them.

The Language Card lists the database among the operations that are typed Host APIs, and examples/callbacks/main.cove shows the shape it expects:

let repository = database.connect("bookings")?
repository.query("insert into bookings ...")?

That is a host resource handle: connect hands back a name, and later calls are made on that name rather than on the module. ADR 0013 is what makes one possible — crate::host::ResourceHandle is the value, and Connection in this module’s crate::schema::ResourceSchema is what says which operations it answers and that it may cross a task boundary.

What a connection is stays here, on the host’s side. A handle carries a number and nothing else, so the only way to learn anything through one is to call an operation the schema declares, and a handle whose connection has been closed finds nothing to call: that is a reported error, not a call on whatever occupies the slot now.

There is still no real implementation, and this module does not pretend otherwise. Connecting to a database means speaking a wire protocol to a server, and the runtime depends on nothing but the standard library, which cannot. What exists is the pair the Language Card promises for the ones that cannot be real: Database::recorded, a fake whose connections answer from a table of canned rows, and Database::denied, which refuses to connect and says why. The CLI installs the denied one, so a program that asks for database is told that this host has none rather than being told that database does not exist.

Structs§

Database
database: querying a database, when the host has one.