developer_analysis/recipe.py

39 lines
912 B
Python

import sqlite3
from uuid import uuid4
class Recipe :
def __init__ (self, conn) :
self.conn = conn
self.cursor = conn.cursor()
def uuid (self) :
return str(uuid4())
def get (self, name) :
query = "SELECT recipe_id FROM recipes WHERE (name = LOWER(?)) LIMIT 1;"
res = self.cursor.execute(query, (name,))
return self.cursor.fetchone()
def exists (self, name) :
recipe = self.get(name)
if recipe is not None:
return recipe[0]
return ''
def create (self, name) :
id = self.uuid()
query = "INSERT OR IGNORE INTO recipes (recipe_id, name) VALUES (?, LOWER(?));"
self.cursor.execute(query, (id, name,))
self.conn.commit()
return id
def table (self) :
query = "SELECT * FROM recipes;"
res = self.cursor.execute(query, ())
for row in self.cursor.fetchall() :
print(row)
if __name__ == '__main__' :
con = sqlite3.connect('developers.sqlite')
r = Recipe(con)
r.table()