View create-databasechangelog.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# TAG is a Redshift keyword, so we have to create this table ourselves, and quote TAG | |
# otherwise, you need a custom database class for liquibase | |
# see https://github.com/liquibase/liquibase-redshift | |
CREATE TABLE public.databasechangelog ( | |
ID VARCHAR(255) NOT NULL, | |
AUTHOR VARCHAR(255) NOT NULL, | |
FILENAME VARCHAR(255) NOT NULL, | |
DATEEXECUTED TIMESTAMP WITHOUT TIME ZONE NOT NULL, | |
ORDEREXECUTED INTEGER NOT NULL, |
View fastapi-htmx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# main.py | |
@app.middleware("http") | |
async def set_xhr(request: Request, call_next): | |
request.state.is_xhr = "HX-Request" in request.headers | |
return await call_next(request) | |
# in your Jinja2 template : | |
{% if request.state.is_xhr %} |
View optimistic-locking.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A sample app to show how to use optimistic concurrency / optimistic locking in Flask and SQLAlchemy | |
The trick is to store your entity in session between requests | |
You need to use Flask-Session, so can serialize your entities properly | |
Usage: | |
flask --app optimistic-locking.py run | |
navigate to http://127.0.0.1:5000/edit/1 |
View Jinja.jinja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Jinja Macros can return results (but only if `called`): | |
``` | |
{% macro foo() %} | |
hello from foo | |
{{ caller({"bar":1}) if caller is defined }} | |
{% endmacro %} | |
{% call(result) foo() %} | |
{{result.bar}} |