liveBook · Manning

Database connection

As explained in Practices of the Python Pro

A database connection is an active communication link through which software sends commands to and receives data from a database.

A database connection is the active link software uses to execute SQL statements against a database and work with returned results. In Python, sqlite3.connect() opens a SQLite database file and creates the file when it does not yet exist. section 6.3.1

Store a connection in a database manager

class DatabaseManager: def __init__(self, database_filename): self.connection = sqlite3.connect(database_filename) def __del__(self): self.connection.close() Keeping the connection on the manager lets separate persistence operations reuse it, while cleanup closes it when the manager is destroyed. section 6.3.1

A connection supports persistence-layer operations by enabling:

  • Adding, deleting, selecting, sorting, and counting records through SQL statements. section 6.3.1

How Practices of the Python Pro covers it

How deep it goes
Defines creation, cursor execution, context management, and cleanup, then applies connections to CRUD operations.
Examples
Uses a SQLite database file, a DatabaseManager class, cursors, and parameterized INSERT, DELETE, and SELECT statements.
What it assumes
Assumes basic Python and SQL familiarity while introducing database access through Python’s built-in sqlite3 module.
What you can do after
Operate/configure a SQLite connection and use it to execute parameterized queries through a small database manager.
How it connects
Connects the persistence layer with SQLite, SQL statements, cursors, and CRUD operations.

Also explained in

Compare how 6 books explain database connection →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Practices of the Python Pro. The section links point to the parts of the book it draws on.