Skeleton of importing data from the csv
This commit is contained in:
23
data/db_connect.py
Normal file
23
data/db_connect.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import sqlite3
|
||||
|
||||
class Database:
|
||||
def __init__(self, database_file):
|
||||
self.db = sqlite3.connect(database_file)
|
||||
|
||||
def select(self, index):
|
||||
# Query the database for the specified index
|
||||
cursor = self.db.cursor()
|
||||
query = "SELECT name, address FROM people WHERE id = ?"
|
||||
cursor.execute(query, (index,))
|
||||
result = cursor.fetchone()
|
||||
if result:
|
||||
return result
|
||||
else:
|
||||
return None
|
||||
|
||||
def insert(self, name, address):
|
||||
# Insert new entry into the database
|
||||
cursor = self.db.cursor()
|
||||
query = "INSERT INTO people (name, address) VALUES (?, ?)"
|
||||
cursor.execute(query, (name, address))
|
||||
self.db.commit()
|
||||
Reference in New Issue
Block a user