forked from gchacaltana/PythonMvcMySQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBook.py
More file actions
26 lines (21 loc) · 807 Bytes
/
Copy pathBook.py
File metadata and controls
26 lines (21 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# -*- coding: utf-8 *-*
__author__ = 'Gonzalo Chacaltana Buleje'
from MySQLConnection import MySQLConnection
class Book:
def __init__(self):
self.id_book = 0
self.id_category = ''
self.title = ''
self.price = ''
self.date_created = 'NOW()'
self.db = MySQLConnection()
def create(self):
"""create a new record"""
query = "INSERT INTO books (id_book, id_category,name,price,date_created) values (null, %s, %s, %s, NOW())"
values = (self.id_category, self.title, self.price)
self.db.execute(query, values)
self.db.commit(query)
def read_all(self):
query = "SELECT id_book,id_category,name FROM books;"
self.db.execute(query)
return self.db.get_fetch_rows()