Criando minha primeira tabela no SQLite3 (DBeaver opcional)

This commit is contained in:
Luiz Otávio
2023-03-22 07:56:11 -03:00
parent 5dbdae3ab9
commit 5878ec3e51

View File

@@ -4,11 +4,20 @@ from pathlib import Path
ROOT_DIR = Path(__file__).parent
DB_NAME = 'db.sqlite3'
DB_FILE = ROOT_DIR / DB_NAME
TABLE_NAME = 'customers'
connection = sqlite3.connect(DB_FILE)
cursor = connection.cursor()
# SQL
cursor.execute(
f'CREATE TABLE IF NOT EXISTS {TABLE_NAME}'
'('
'id INTEGER PRIMARY KEY AUTOINCREMENT,'
'name TEXT,'
'weight REAL'
')'
)
connection.commit()
cursor.close()
connection.close()