Search results

Matches found for tag 'SQLAlchemy': 7

29 August 2019 Updated 30 August 2019 by Peter
post main image
Objects, it is nice to build an application with them but it has one very big disadvantage: it can be very slow because of the extra CPU-cycles and all the extra memory used. The slowdown of course is very much caused by the extra mapper layers and extra data.  Should you care about performance? Yes! The admin part of an application does not have to be very fast but the frontend pages, the pages ...
Read more
25 August 2019 Updated 30 August 2019 by Peter
post main image
When I started this project, this website, I kept in mind that it had to support multiple languages. But of course I did not really look into database design because of all the other things I had to learn, add and implement. After a certain moment I could display and select multiple languages but that was for the texts in the code and templates and not for the database content items like blog posts ...
Read more
29 July 2019 Updated 29 August 2019 by Peter
post main image
Performance is a never ending story. At a certain moment I noticed that putting the home page on the screen took some 370 milliseconds using the Flask development server with debug messages shown. That seemed far too long! How did I notice this? Because at the bottom of every page I show the time it takes to generate a page. Please note that the timings below are from a more optimized version of the ...
Read more
24 June 2019 Updated 31 August 2019 by Peter
post main image
You will find a lot of SQLAlchemy datetime calculation examples using e.g. Python's timedelta function. Why? I do not understand this except that this is easy. But is it correct?  Assume we we want all user records or objects created two hours ago and the record / object definition is:  class User(Base): __tablename__ = 'user' id = Column(Integer, primary_key=True) created_on ...
Read more
21 June 2019 Updated 29 August 2019 by Peter
post main image
Building on the previous post 'Flask, Jinja2 and SLQAlchemy many-to-many relationship with conditions' I looked for a way to dynamically add filter conditions and if possible also find a solution for the soft delete pattern. Soft delete is not deleting records from a table but instead marking them as deleted. This means that every table must have a deleted flag and all queries must exclude records ...
Read more
17 June 2019 Updated 31 August 2019 by Peter
post main image
Disclaimer: This my first SQLAlchemy project so I am not experienced and may make wrong statements in this post. While working on my first Flask / SQLAchemy project (I do not use Flask-SQLAlchemy) I hit a very high and thick wall. To explain this, consider you have a blog with posts and tags. There is a many-to-many relationship between posts and tags: a post can have many tags and a tag can have ...
Read more
9 March 2019 Updated 28 August 2019 by Peter
post main image
By default Alembic does not change the length of string fields, I noticed this after changing a string field from: description = Column(String(150), server_default='') to: description = Column(String(250), server_default='') No changes were made. It appears that column type change detection is off by default, so you can test it first, and can be turned on by adding 'compare_type=True' to the context. ...
Read more