db.py 798 B

12345678910111213141516171819202122232425262728293031
  1. import pymysql
  2. class db():
  3. DB = "EBA_STOCK"
  4. USER = "root"
  5. PASSWORD = "howdoiturnthison"
  6. def __init__(self):
  7. self.conn = pymysql.connect(unix_socket='/var/run/mysqld/mysqld.sock', user=db.USER, passwd=db.PASSWORD, db=db.DB,cursorclass=pymysql.cursors.DictCursor)
  8. def client(self, _hash):
  9. cur = self.conn.cursor()
  10. cur.execute("SELECT id,nombre,apellido,hash FROM clientes where hash=%s", (_hash,))
  11. res = cur.fetchall()
  12. if len(res) == 0:
  13. return None
  14. return res[0]
  15. def products(self, _id=None):
  16. ret=[]
  17. if _id is None:
  18. cur = self.conn.cursor()
  19. cur.execute("SELECT id,nombre,precio FROM productos where id between 1000 and 2999")
  20. for row in cur.fetchall():
  21. row["cantidad"]=0
  22. ret.append(row)
  23. else:
  24. pass
  25. return ret
  26. def pedido(self, pedido):
  27. return 0