3 ms·
Ask HN: SQL Query Generators?
I'm looking for a SQL query generator that will construct and execute a SQL query from just the SELECT and WHERE fields passed to a function. I am working on a text based video game and coding in python and leaning heavily on relational data (e.g. I use integer IDs where ever possible to save space, like using an integer ID for eye color in the Unit table).
I have spent hours looking into ORMs and I dont think they provide the functionality I require?
The goal would be to have one function call where param1 is the SELECT fields, and param2 is the WHERE fields+filters. From there, it essentially builds the FROM statement with all the JOINs and ON statements (as well as the SELECT/WHERE). If I pass five SELECT fields from five different tables, the code should figure out how to JOIN all the tables together. If I pass a field in the WHERE param, it should figure out if it that table needs to be JOINed as well. I have also built in an option to 'LEFT OUTER JOIN' the SELECT and WHERE fields such that any table in the WHERE fields that is not in the SELECT fields is excluded from the JOINs, which reduces code customization for my purposes.
I have built my own library to do what I want, and it works, but I know I have not covered all edge cases. I'd like to replace it with something that has been battle tested.