Files
tainagustului/UI_V2/dbActions/netopia.py

33 lines
1.1 KiB
Python

import sqlite3
from typing import Optional
class Netopia:
def __init__(self, db_path="instance/app_database.db"):
self.db_path = db_path
self._create_netopia_table()
def _create_netopia_table(self):
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS netopia (
id INTEGER PRIMARY KEY AUTOINCREMENT,
order_id TEXT,
netopia_id TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
""")
conn.commit()
def add_netopia_card(self, order_id, netopia_id):
try:
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute("""
INSERT INTO netopia (order_id, netopia_id)
VALUES (?, ? )
""", (order_id, netopia_id))
conn.commit()
return True
except sqlite3.IntegrityError:
return False