๐
Work SQLite
When we want to work with database sqlite we use sqlite3 module
- Note: If you want to manage the SQLite with the graphical interface you can use SQLite browser
python
import sqlite3import jsonfrom pathlib import Pathmovies = json.loads(Path("movies.json").read_text())with sqlite3.connect("db.sqlite3") as conn:command = "INSERT INTO Movies VALUES(?,?,?)"for movie in movies:conn.execute(command,tuple(movie.values()))conn.commit()
python
import sqlite3with sqlite3.connect("db.sqlite3") as conn:command = "SELECT * FROM Movies"cursor = conn.execute(command)movies = coursor.fetchall()print(movies)
