Package: voxsql
voxsqlGenerates application artifacts from documented SQL code.Use CasesUse cases for this library include but are not limited to:Automatic generation of human-friendly documentation of SQL excerpts.Automatic generation of application-level bindings (Learn more).Instrumentation of test code to extend coverage analysis to SQL excerpts.Getting Startedpip install voxsqlBasic Conceptsvoxsqlworks on annotated SQL files. Annotations are provided as Javadoc-like comments, and only properly framed SQL segments are considered by the library when parsing files. Below is an example:/*** Adds a contact to the database.** @dialect postgresql* @name add_contact* @param contact_name: string - the target contact's name* @retmode record* @retval name: string*/{insertintocontacts(name)values(%(contact_name)s)returningname;}Save the snippet above tosample.sqlto run the examples below.CLI UsageTo digest the SQL file above using the CLI:voxsqlsample.sqlFor more information runvoxsql --help.Direct Library UsageBelow is an example on how you can manipulate the file above using the Python library directly:fromvoxsqlimportparseframes=parse(open('sample.sql').read())assertframes[0].header.name=='add_contact'assertframes[0].body.source.startswith('insert into contacts')Design Goals and Inspirationvoxsqlstrives to promote SQL as a first-class language within application-centric projects.As opposed to ORMs,voxsqldoes not try to encapsulate SQL within higher-level application-level abstractions, nor does it try to rewrite or adapt provided SQL for greater portability. The premise here is that directly writing and maintaing SQL code has some interesting advantages, such as a lower barrier to the usage of more advanced SQL features, easier inspection of queries, and the possibility to reduce application footprint and complexity. It is a fair statement to assumevoxsqlpromotes simplicity at the cost of flexibility.Some of the typically recognized drawbacks of a SQL-heavy design, like the lack of query composability, the difficulty to promote code reuse, and the lack of cross-engine portability are notvoxsql's focus, and for that reason, it is considered unsuitable for projects that really need to support an unpredictably complex persistence layer, which might not be as representative of current reality as common sense assumes to be the case these days.Here are a few projects that promote SQL for application development in slightly different ways:HugSQL: DSL-based SQL-bindings generation for ClojureYesql: DSL-based SQL-bindings generation for Clojureanosql: inspired byYesql, for Python.Listed below are references to material that positively influenced ideas contained invoxsql:Mastering PostgreSQL In Application Development, by Dimitri Fontaine.ContributingThis is how you run tests locally:maketest.start.d
pytestRoadmapAutomate exception handling by means of a new@errortag.Raise spec mismatch during executionAdd support to@retmode columnsAdd support to@retmode columnAdd support to mandatory/optional parameter annotationSolve design question about passing default column values as parametersSolve design question about skipping reseting columns to avoid select-before-update issueAdd support to@dialect sqliteAdd support to@dialect mysqlAdd support to@dialect xyz:versionAdd sphinx docsAdd cli command for lanching the interpreter with bindings preloaded.