-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathorm.py
More file actions
33 lines (24 loc) · 728 Bytes
/
Copy pathorm.py
File metadata and controls
33 lines (24 loc) · 728 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
27
28
29
30
31
32
33
# _*_ coding:utf-8 _*_
"""
This file is about approaches of orm(object relational mapper)
in sql alchemy
"""
from basic import get_db_session
from sqlalchemy import Column, String, Integer
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.hybrid import hybrid_property
Base = declarative_base()
class User(Base):
__tablename__ = 'user'
id = Column(Integer, primary_key=True)
nickname = Column(String)
password = Column(String)
@hybrid_property
def name_pwd(self):
return self.nickname + " " + self.password
def query_orm():
session = get_db_session()
user = session.query(User).first()
print user.name_pwd
if __name__ == '__main__':
query_orm()