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!)
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:
Boolean
Int
String
Option(Boolean)
Option(Int)
Option(String)
There are rules regarding which Cooma types are compatible with which SQL types:
Boolean
is compatible with any SQL type containingBOOL
orINT
.Int
is compatible with any SQL type containingINT
.String
is compatible with any SQL type.Option
(and must not be if the column is non-nullable).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
andDatabase::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
andtoQuery
methods toDatabase
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!)