inkytonik / cooma

The Cooma project is investigating secure programming language design based on fine-grained object capabilities.
Mozilla Public License 2.0
3 stars 2 forks source link

Typed database columns #60

Closed nhweston closed 3 years ago

nhweston commented 3 years ago

This PR allows the columns of database tables to be ascribed types other than String.

Overview

Columns can be ascribed one of the following Cooma types:

There are rules regarding which Cooma types are compatible with which SQL types:

This at least roughly reflects types in SQLite 3.

Column type compatibility is checked at load time.

Implementation

Extensive changes have been made to Database::dbConfigure and Database::dbTableAll, the former involving compatibility checking, and the latter ensuring that values are returned as the correct Cooma type.

I initially attempted to compile database type information into records accessible at runtime. It is currently not possible for the IR to contain an arbitrary record, it must be constructed. The Cooma compiler and IR implements the continuation-passing style described in Kennedy 2007, which requires that all values must be bound to a variable before use. This makes generating code to construct a record rather difficult.

For now, the type information is converted to JSON, encoded to Base64, and made part of the capability name. I may reattempt a runtime record-based solution at a later time.

I have also added the dbInsert and toQuery methods to Database which I will use for database insertion in a later PR. (I thought I might be able to quickly add it to this PR, but I was biting off more than I could chew!)