Skip to content

Chapter 6

Chapter 6

  • SQL Database
  • SQLite - sqlite3, MySQL - mysqlclient/pymysql, PostgreSQL - psycopg
  • Async SQLite: aiosqlite, MYSql: aiomysql
  • SQLAlchemy & ORM (object-relational mappers): the ORM techique helps in converting data between these incompatible type systems. The word Object in ORM referes to he object of a Python class. You may recall that, in the theory of relational databases, a table is called a relation. A Python class is mapped to a table of corresponding structure in the database. As a result, each object of the mapped class reflects as a row in the database table.
    • SQLAlchemy is a very popular SQL toolkit and an ORM API.
    • databases module provides functions for connecting to a database, executing queries, and fetching table data. These functions support async/await. This module provides asyncio support for PostgreSQL, MySQL, and SQLite. It uses the SQLAlchemy Core Expression Language to construct SQL queries.
    • you need to install asyncpg and aiopg for PostgreSQL
    • you need to install aiomysql and asyncmy for MySql
    • you need to install aiosqlite for SQLite
  • No-Sql Database
  • MongoDB is a schemaless, document-oriented, NoSQL database. It stores semistructured documents in BSON format -- a binary serialization of JSON-like documents.
  • motor provides async/await feature for mongo.