Criando minha primeira tabela no SQLite3 (DBeaver opcional)
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user