-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
35 lines (25 loc) · 1 KB
/
main.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
from sqlalchemy import create_engine # начните работу с этой библиотеки
from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey
from sqlalchemy.orm import mapper, sessionmaker
from User import User
db_conn_string = 'postgresql://postgres:123456@localhost/postgres'
engine = create_engine(db_conn_string, echo=False)
metadata = MetaData()
users_table = Table('users', metadata,
Column('id', Integer, primary_key=True),
Column('name', String(50)),
Column('fullname', String(50)),
Column('password', String(50))
)
# metadata.create_all(engine)
mapper(User, users_table)
# user = User('Вася', 'Василий', 'qwerty')
# print(user)
# print(user.id)
Session = sessionmaker()
Session.configure(bind=engine)
session = Session()
# session.add(user)
ourUser = session.query(User).filter_by(name="Вася").first()
ourUser.password = 'new_pass'
print(ourUser, ourUser.id)