-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathORMmethods.py~
41 lines (30 loc) · 1.34 KB
/
ORMmethods.py~
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
27
28
29
30
31
32
33
34
35
36
37
38
39
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from ORMdb import User, Base
class ORM():
def __init__(self):
self.path_to_database = 'mydatabase.db'
self.engine = create_engine('sqlite:///'+self.path_to_database, echo=True)
Base.metadata.create_all(self.engine)
self.DBSession = sessionmaker(bind=self.engine)
self.session = self.DBSession()
def insert_userORM(self,username,fullname,email,password):
new_user = User(str(username),str(fullname),str(email), str(password))
self.session.add(new_user)
self.session.commit()
def show_usersORM(self):
data = list()
for row in self.session.query(User.username, User.password, User.email, User.fullname):
data.append(row)
return data
def loginORM(self,username,password):
login = None
(dbuser,dbpass,dbemail,dbfullname) =(None,None,None,None)
for log in self.session.query(User.username, User.password, User.email, User.fullname).\
filter(User.username == username, User.password == password):
(dbuser,dbpass,dbemail,dbfullname) = log
login = True
return (login, dbuser,dbpass,dbemail,dbfullname)
if __name__ == "__main__":
new_insert=ORM()
print new_insert.loginORM("dsfs","fdsdf")