python_bot/sqdb.py

72 lines
1.9 KiB
Python

from sqlalchemy import create_engine, MetaData, Table, Integer, String, BIGINT, \
Column, DateTime, ForeignKey, Numeric
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, relationship
from sqlalchemy import select, update
engine = create_engine('postgresql+psycopg2://postgres:postgres@postgres.vdk2ch.ru:5432/jack_bot', echo=True)
Session = sessionmaker(bind=engine)
session = Session()
Base = declarative_base()
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
user_id = Column(Integer)
date_created = (Column(DateTime))
user_fullname = Column(String)
date_updated = (Column(DateTime))
dick_requests = relationship("DickRequest", back_populates="user")
dicks = relationship("UserDick", back_populates="user")
class UserDick(Base):
__tablename__ = 'user_dicks'
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey("users.user_id"))
dick_size = (Column(Integer))
chat_id = Column(BIGINT)
user = relationship("User", back_populates="dick_requests")
class DickRequest(Base):
__tablename__ = 'dick_requests'
id = Column(Integer, primary_key=True)
size_change = Column(Integer)
user_id = Column(Integer, ForeignKey("users.user_id"))
user = relationship("User", back_populates="dick_requests")
date_changed = (Column(DateTime))
session.close()
engine.dispose()
# top = session.query(user.user_fullname, user.dick_size)
# .order_by(user.dick_size.desc())
# .filter(user.chat_id == user.chat_id).limit(10).all()
# print(top)
#Base.metadata.create_all(engine)
# int_table = user(user_id = 12345678, user_fullname = 'test', dick_size = 10) #импортирую юзер из sqdb
# session.add(int_table)
# session.commit()
# select user_id, name from employees limit 10
# def adding():
# session.add()
# session.commit()