|Summary||SQL-aware type checker|
Wortel defers the actual type-checking of queries to the DBMS, unlike quotation-based approaches. This allows for a simpler implementation, easier support for multiple vendors, and future compatibility with new SQL extensions. It does however require that you have a DBMS running, available for the type checker to connect to.
To tell the type checker how to connect to the DBMS, you must give it a mapping from schema names to connection strings. Schema names can then be used in Wortel code to decide which schema to use for a particular query. Database connections are tagged with a schema as well. This makes sure you don't run a query against the wrong database.
Type-checking SQL queries
When the type checker encounters a SQL query, it connects to the DBMS and issues the following statement:
SELECT t.* FROM (<original query>) AS t LIMIT 0
For query parameters, the type checker fills in
NULL :: <type>. Now the type checker knows the result type of the query.
- It is undesirable to have
NULLbe an inhabitant of every type. However, SQL queries may return
NULLat any time.
- It may be desirable to allow the programmer to define custom mappings between their types and SQL types.
- Wadler, P. "Everything Old is New Again: Quoted Domain Specific Languages." https://www.youtube.com/watch?v=DlBwJ4rvz5c