Queries executed
It is now possible to query (in a very simple sense) a database from within a SLinks program. Please read on for more details. Tomorrow, I will start with the optimisation part.
Here is how a database-enabled session looks (notice that the developer has to give the type of the table):? def ^conn = {#name="gilles",#user="gilles"};;
Defined conn as {#name="gilles",#user="gilles"} : {#name:pre(string), #user:pre(string)}
? def ^db = database conn;;
Defined db as (database gilles from gilles@localhost:5432) : database
? table "tata" with [bag {#a:pre(int),#b:pre(string),#c:pre(float)}] from db;;
[bag {#a=1,#b="cool",#c=2.2}, {#a=2,#b="super",#c=3.5}] : [bag {#a:pre(int), #b:pre(string), #c:pre(float)}]
The 'table' operator really is a hidden 'SELECT' statement, in this case 'SELECT a, b, c FROM tata'. By 'optimisation part', I mean completing this statement with conditions from SLinks comprehensions applied to it.
Type safety is only guaranteed if the type of the table provided by the developer is correct. Testing it during type inference would be nice (at least for an interpreter) but is problematic because one needs to have the database connection already, which is not the case during type inference. I haven't found a good way to solve this yet (currently, a runtime error is raised when there is a type incompatibility between the developer-provided type and the table).