Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

complete source code generation #19

Open
jayvdb opened this issue Jan 29, 2019 · 4 comments
Open

complete source code generation #19

jayvdb opened this issue Jan 29, 2019 · 4 comments
Labels

Comments

@jayvdb
Copy link

jayvdb commented Jan 29, 2019

I would like to use this with https://github.com/moban to convert a template containing a few custom queries with preset data into a db-specific rendered file, each enclosed in a method which receives extra params and returns the cursor and bound output cols where possible.

A little more voodoo is needed for this tool to process a string containing multiple queries, such as expanding the params in generated wrapping code. That could be done manually in jinja, but it would be a shame to do it that way as this tool is so close.

Moban allows plugins, so some extra init and per file steps can be done in the plugin to make this workable, but ideally most of the voodoo is in this project so it is reusable.

@sripathikrishnan
Copy link
Owner

I am not sure if there is a specific feature request described here, and the link to moban doesn't really provide any insight. Do you mind providing some additional details for us to consider?

@jayvdb
Copy link
Author

jayvdb commented May 27, 2020

Sorry, the link should have been to @moremoban

Unfortunately a long time has passed since I created this issue, and the exact use-case I had has now escaped my brain.

The main part of it that I remember was I was trying to process a python file which contained several queries in it.

I didnt want to run jinjaSQL at runtime - I wanted instead to run it at build time, to convert a template into a database specific python file.

Processing a template with multiple queries was the key problem - especially the variable binding was problematic, perhaps because it was using %s instead of {name} ... ?

@clayadavis
Copy link

I think I understand the idea here: applying the templates in a build step and generating rendered .sql queries, similar to Frozen-Flask generating static HTML from templates + data.

Frozen-Flask is an instructive example though in that I think this usecase would probably be best as a separate tool that uses JinjaSQL, as opposed to being built into JinjaSQL itself. This article illustrates some of the steps that could get you there, specifically the section entitled "From a template to the final SQL query."

@jayvdb
Copy link
Author

jayvdb commented Apr 30, 2021

.. rendered .sql queries ..

Well the key is that the input files, .sqljj2 ? ;-), would contain multiple queries, or DDL/DML. Using pyformat, like you did in apply_sql_template, probably makes this easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants