Packaged-Food-Explorer/app/model.py
2023-05-02 14:41:37 +07:00

13 lines
407 B
Python

import sqlite3
class FoodSearch:
def __init__(self, db_path):
self.conn = sqlite3.connect(db_path)
self.cursor = self.conn.cursor()
def search(self, user_input) -> list:
query = f"SELECT * FROM food_data WHERE product_name LIKE '%{user_input}%'"
self.cursor.execute(query)
results = self.cursor.fetchall()
return results