Knowledgebase

Connecting a Web Application to a Database Print

  • python, database, migration, performance, errors, troubleshooting, guide, howto
  • 0

Persistence.

WHAT TO SET UP

Database credentials in configuration, not code A connection approach suited to a persistent application

WHAT TO BE CAREFUL WITH

Opening a connection per request without pooling Holding a connection open indefinitely Connections not closed on error

WHAT TO USE

Your framework's database integration, or a connection pool.

WHAT TO ALWAYS DO

Parameterise queries.

WHAT TO CONSIDER

Whether an ORM suits the project.

WHAT AN ORM GIVES YOU

Working with objects rather than rows Portability between databases Migrations for schema changes

WHAT IT COSTS

A layer of abstraction, and queries that are sometimes inefficient.

WHAT TO WATCH FOR

Queries issued inside a loop, producing one query per item.

That is the commonest performance problem in database-backed applications.

WHAT TO DO ABOUT IT

Fetch what you need in one query.

WHAT TO MONITOR

Query count and duration.

WHAT TO PLAN

Schema changes, with a way to apply them repeatably.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot