SQLite is a portable database that stores data in a single file. A Python sqlite3 connection can create a missing database file, making it easy to start over during development. section 6.3.1
Within a persistence layer, SQLite receives application data through SQL statements. A DatabaseManager can isolate connections and database operations from the rest of the application. section 6.3.1
A SQLite database can support the main CRUD tasks:
- Create tables and initialize the database. section 6.3.1
- Add, delete, list, select, sort, and count records. section 6.3.1
- Use placeholders and values when inserting or filtering records. section 6.3.1
Bookmarks database
A bookmarks table can store an automatically generated ID, required title and URL fields, optional notes, and a required date_added value. Records can then be inserted, selected by ID, sorted by title, or deleted by criteria. section 6.3.1
import sqlite3
class DatabaseManager:
def __init__(self, database_filename):
self.connection = sqlite3.connect(database_filename) #1
def __del__(self):
self.connection.close() #2
Connect to a database file when creating DatabaseManager, then close the connection when the manager is destroyed. section 6.3.1














