requires that all database tables have an integer primary key named id,
significantly refactors existing code for database capabilities.
New methods
A new method is introduced to retrieve a single row by its primary key. Methods are also added for insertion, update, and deletion.
These methods require rows to be identified by their primary key. There is now a requirement that all tables have a column named id, and that this column be a primary key, non-nullable, and of integer type. See #21 for further discussion.
The mutations (insert, update, and delete) return Either(DbError, Int). If the mutation succeeds, a Right is returned with the number of rows affected. If an error occurs, a Left is returned containing the error code and a message.
The new methods are:
getById: (Int) Option(A) accepts an ID and returns the row with that ID, if it exists.
insert: (A) Either(DbError, Int) accepts a row and inserts the row into the table.
update: (A) Either(DbError, Int) accepts a row and updates an existing row in the table. The id column is used to identify which row to update. All other columns are set to the corresponding field. (Any rows in the actual table excluded in the table type are left unchanged.)
delete: (DbError, Int) accepts an ID and deletes the row with that ID, if it exists.
Refactoring
There are several forms of data involved in the database capability that need to be converted between each other:
AST nodes,
JSON,
runtime values,
SQL,
Java SQL results.
The Metadata, DbType, and DbValue classes serve as intermediate representations of databases, types, and values (respectively), with methods provided to convert to and from these different forms.
Metadata essentially contains the table types of a database, made available at runtime. The compiler converts the type information to a metadata object (Metadata.fromCooma), which is then converted to a JSON encoded in Base64 (Metadata::toSpec) and attached to the capability name. At load time, this is converted back into a Metadata object (Metadata.fromSpec).
DbType forms a part of Metadata to express a Cooma type accepted as the type of a column. The nullability of a column is also expressed in DbType.
DbValue represents a database value. Methods are provided to convert to and from Cooma runtime values and SQL values.
Query contains methods to execute queries.
Validation validates (at load-time) that a database type is compatible with the actual database.
This PR:
id
,New methods
A new method is introduced to retrieve a single row by its primary key. Methods are also added for insertion, update, and deletion.
These methods require rows to be identified by their primary key. There is now a requirement that all tables have a column named
id
, and that this column be a primary key, non-nullable, and of integer type. See #21 for further discussion.The mutations (
insert
,update
, anddelete
) returnEither(DbError, Int)
. If the mutation succeeds, aRight
is returned with the number of rows affected. If an error occurs, aLeft
is returned containing the errorcode
and amessage
.The new methods are:
getById: (Int) Option(A)
accepts an ID and returns the row with that ID, if it exists.insert: (A) Either(DbError, Int)
accepts a row and inserts the row into the table.update: (A) Either(DbError, Int)
accepts a row and updates an existing row in the table. Theid
column is used to identify which row to update. All other columns are set to the corresponding field. (Any rows in the actual table excluded in the table type are left unchanged.)delete: (DbError, Int)
accepts an ID and deletes the row with that ID, if it exists.Refactoring
There are several forms of data involved in the database capability that need to be converted between each other:
The
Metadata
,DbType
, andDbValue
classes serve as intermediate representations of databases, types, and values (respectively), with methods provided to convert to and from these different forms.Metadata
essentially contains the table types of a database, made available at runtime. The compiler converts the type information to a metadata object (Metadata.fromCooma
), which is then converted to a JSON encoded in Base64 (Metadata::toSpec
) and attached to the capability name. At load time, this is converted back into a Metadata object (Metadata.fromSpec
).DbType
forms a part ofMetadata
to express a Cooma type accepted as the type of a column. The nullability of a column is also expressed inDbType
.DbValue
represents a database value. Methods are provided to convert to and from Cooma runtime values and SQL values.Query
contains methods to execute queries.Validation
validates (at load-time) that a database type is compatible with the actual database.