THE DESIGN OF A TEMPLATING LANGUAGE TO EMBED DATABASE QUERIES INTO DOCUMENTS
Keywords:Templating Language, Preprocessor, SQL, Database, Data Report, User Interface, Separation of Concerns
Presenting information from a database to a human readership is one of the usual tasks in software development. Commonly, an imperative language (such as: PHP, C#, Java, etc.) is used to query a database system and populate with the desired information the application's GUI, a web page or a printed report (referred from now on as Presentation Media).
Virtually all database systems are now capable to format, sort and group the data stored in a database, and last but not least to perform calculations against it. These are most of the time enough to prepare the information that is going to be shown on screen or paper. Thus it leaves just one role for the imperative code: to glue the query results to the Presentation Media. This code tends to become repetitive and grows proportionally with the complexity of the Presentation Media. The need for software developers to write this imperative code can be eliminated thought. Instead, the markup code (HTML, LaTEX, etc) can have the ability to bind its elements directly to the database system. To achieve this ability, I propose mixing the Presentation Media’s markup code with a Templating Language.
This paper elaborates the design of a Templating Language, a declarative language that adds annotations to any markup code regarding what data will be queried and how should it be integrated in document. For this markup code to be consumed, there won't be necessary to implement any database query abilities in the process that renderers it. Instead, a preprocessor will be invoked to interpret the Templating Language, connect to the database system and query the desired data, respectively to generate the final markup code.