Skip to content

Instantly share code, notes, and snippets.

@parzibyte

parzibyte/db.py Secret

Created November 10, 2020 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save parzibyte/b048baa079961e33eb92c35eec6fdc5d to your computer and use it in GitHub Desktop.
Save parzibyte/b048baa079961e33eb92c35eec6fdc5d to your computer and use it in GitHub Desktop.
import sqlite3
DATABASE_NAME = "games.db"
def get_db():
conn = sqlite3.connect(DATABASE_NAME)
return conn
def create_tables():
tables = [
"""CREATE TABLE IF NOT EXISTS games(
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
price REAL NOT NULL,
rate INTEGER NOT NULL
)
"""
]
db = get_db()
cursor = db.cursor()
for table in tables:
cursor.execute(table)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment