Lenses are a popular approach to bidirectional transformations, a generalisation of the view update problem in databases, in which we wish to make changes to source tables to effect a desired change on a view. However, perhaps surprisingly, lenses have seldom actually been used to implement updatable views in databases. Bohannon, Pierce and Vaughan proposed an approach to updatable views called relational lenses, but to the best of our knowledge this proposal has not been implemented or evaluated to date. We propose incremental relational lenses, that equip relational lenses with change-propagating semantics that map small changes to the view to (potentially) small changes to the source tables. We also present a language-integrated implementation of relational lenses and a detailed experimental evaluation, showing orders of magnitude improvement over the non-incremental approach. Our work shows that relational lenses can be used to support expressive and efficient view updates at the language level, without relying on updatable view support from the underlying database. A typical web application is based on a three-tier architecture with user interaction on the client (web browser), application logic on the server, and data stored in a (typically relational) database. Relational databases employ SQL query and update expressions, including projections, selections and joins, which correspond closely to familiar list comprehension operations in functional languages. Relational databases offer data persistence and high performance and are flexible enough for a range of applications. However, the impedance mismatch between database queries and conventional programming makes even simple programming tasks challenging [Copeland and Maier 1984] . Languages such as C# [Meijer et al. 2006], F# [Syme 2006; Cheney et al. 2013], Links [Cooper et al. 2006], and Ur/Web [Chlipala 2015], and libraries such as Database-Supported Haskell [Ulrich and Grust 2015], have partly overcome this challenge using language-integrated query, in which query expressions are integrated into the host language and type system. This work is licensed under a Creative Commons Attribution 4.0 International License. Rudi Horn, Roly Perera, and James Cheney 1 Information such as the hostname, port, username and password needed to access the database also needs to be provided; this can be included in the database expression or, as here, in a separate configuration file. 2 Such constraints are not currently checked in our implementation, but this is straightforward and an orthogonal concern. Lemma 4.5. If ∆M is minimal for M then M ⊕ ∆M = (M − ∆M − ) ∪ ∆M + = (M ∪ ∆M + ) − ∆M − . Definition 4.6 (Delta negate). For any ∆M : ∆U , define ⊖∆M : ∆U def = (∆M − , ∆M + ). Definition 4.7 (Delta difference). For any ∆M, ∆N : ∆U , define (M ⊖ N ) : ∆U def = M ⊕ (⊖N ).
Incremental Relational Lenses on the other hand take the updated view and compute a delta which is then translated into a delta to the source tables REF .
Incremental relational lenses
PACMPL
Computer Science