Consider a module that stores queries in a separate file. It would be APSW and SQLite specific and be similar to this but with differences:
Also have a look at mayim. The general gist is you can define a dataclass and reference a query and a method automagically combines them to produce the dataclass as a result of the query with provided parameters. The method type signature can be inspected to figure out the return, and we have a way of referencing the query above.
Look at this because it should be possible to replace all those hard coded SQL and be way more ergonomic
Some code thoughts:
# assuming example.sql contains queries in the following
# an import hook?
from . import example
example.query1.....
# usage of queries - auto async if db is async?
example.query1.execute(db, bindings)
example.query1.executemany(db, iterable)
# ?db as contextvar so
example.query1.execute(bindings)
# derive from str so
db.execute(example.query1, bindings)
Consider a module that stores queries in a separate file. It would be APSW and SQLite specific and be similar to this but with differences:
Also have a look at mayim. The general gist is you can define a dataclass and reference a query and a method automagically combines them to produce the dataclass as a result of the query with provided parameters. The method type signature can be inspected to figure out the return, and we have a way of referencing the query above.
Look at this because it should be possible to replace all those hard coded SQL and be way more ergonomic
Some code thoughts: