HackerTrans
TopNewTrendsCommentsPastAskShowJobs

pgjones

no profile record

Submissions

Show HN: SQL-tString a t-string SQL builder in Python

github.com
85 points·by pgjones·tahun lalu·35 comments

Tell HN: Flask and Quart have now partially merged

20 points·by pgjones·3 tahun yang lalu·7 comments

Tips and techniques for modern Flask apps

pgjones.dev
2 points·by pgjones·3 tahun yang lalu·0 comments

Faster Routing for Flask and Quart

pgjones.dev
4 points·by pgjones·4 tahun yang lalu·0 comments

comments

pgjones
·tahun lalu·discuss
The `sql_context` feature is meant to protect against SQL injection. I think for your usecase you would need to supply all columns, but you could used nested t-strings included based on whatever logic you need.
pgjones
·tahun lalu·discuss
It does parse the SQL. At the moment an expression is defined as all the text between the appropriate separators given the clause.
pgjones
·tahun lalu·discuss
Sorry that is a typo, I meant,

    with sql_context(columns={"x"}):
pgjones
·tahun lalu·discuss
Thank you! My Google foo did not find this.
pgjones
·tahun lalu·discuss
The presence of Absent removes the entire expression, and if that removal results in an empty clause (or group) it will remove that as well. For example if `a = Absent` `WHERE a = {a}` will remove everything, whereas `WHERE a = {a} AND b = {b}` will result in `WHERE b = {b}`.

> Do you support templating a sql tstring into an sql tstring for composition?

Yep
pgjones
·tahun lalu·discuss
Thanks, do you have a reference for SQL grammar - I've had no success finding an official source.
pgjones
·tahun lalu·discuss
If you want to see a usage for this I've built, and use, [SQL-tString](https://github.com/pgjones/sql-tstring) as an SQL builder.
pgjones
·2 tahun yang lalu·discuss
Quart, the ASGI version of Flask, also has background tasks, https://quart.palletsprojects.com/en/latest/how_to_guides/ba..., and there is an extension Quart-Tasks, https://github.com/pgjones/quart-tasks, to run them on a schedule. Via

    @tasks.cron("*/5 * * * *")  # every 5 minutes
    async def infrequent_task():
        ...
In addition Hypercorn, https://github.com/pgjones/hypercorn, (a ASGI and WSGI) also does not use gunicorn, having migrated many years ago.
pgjones
·2 tahun yang lalu·discuss
It is a shame GCRA is not more well known and used for rate limiting. It is, in my view, a better algorithm.

https://medium.com/smarkets/implementing-gcra-in-python-5df1... https://en.m.wikipedia.org/wiki/Generic_cell_rate_algorithm
pgjones
·3 tahun yang lalu·discuss
Yes, I've written about this comparison in detail https://pgjones.dev/blog/fastapi-flask-quart-2022/.
pgjones
·3 tahun yang lalu·discuss
There are new logos for all the Pallets projects and Pallets itself, based on a common theme.
pgjones
·3 tahun yang lalu·discuss
https://pgjones.dev

I blog mostly about Python web developed, especially Flask, Quart and Hypercorn related aspects.
pgjones
·3 tahun yang lalu·discuss
I've three things :),

1. Quart, https://quart.palletsprojects.com, an ASGI (async/await) re-implementation of the Python web MicroFramework Flask. It is now maintained alongside, by the same people, as Flask.

2. Hypercorn, https://hypercorn.readthedocs.io, an ASGI/WSGI server that supports HTTP/1, HTTP/2, and HTTP/3.

3. My book "A Blueprint for Production-Ready Web Applications", which uses both of the above and shows a beginner how to build a full stack app (React frontend) running on AWS. See https://pgjones.dev/tozo/ for details, code, and link to the example app.
pgjones
·4 tahun yang lalu·discuss
It is also easier to manage for Flask - it is very mature and we fixed most of the issues present in FastAPI many years ago.
pgjones
·4 tahun yang lalu·discuss
Flask supports async, see https://flask.palletsprojects.com/en/2.1.x/async-await/.

Also see Quart https://github.com/pgjones/quart (which is Flask re-implemented with async-await) and Quart-Schema, https://github.com/pgjones/quart-schema for swagger docs.
pgjones
·5 tahun yang lalu·discuss
Or Hypercorn https://gitlab.com/pgjones/hypercorn if you want HTTP/1, HTTP/2, and HTTP/3.
pgjones
·5 tahun yang lalu·discuss
You can already do this using Hypothesis with the Pydantic plugin, https://pydantic-docs.helpmanual.io/hypothesis_plugin/. Here is an example for Quart-Schema (similar setup to FastAPI) https://pgjones.dev/blog/automatic-api-testing-2021.