-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
33 lines (25 loc) · 962 Bytes
/
model.py
File metadata and controls
33 lines (25 loc) · 962 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
# Database model
from sqlalchemy import Column, Integer, String, DateTime, BigInteger
from sqlalchemy.types import Enum as SQLAlchemyEnum
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.engine import Engine
import sys
from strings import Source
Base = declarative_base()
class User(Base):
__tablename__ = 'users'
id = Column(BigInteger, primary_key=True)
sources_mask = Column(BigInteger, default=sys.maxsize)
categories_mask = Column(BigInteger, default=sys.maxsize)
class News(Base):
__tablename__ = 'news'
id = Column(Integer, primary_key=True)
title = Column(String)
link = Column(String)
source = Column(SQLAlchemyEnum(Source, name='source_enum'))
text = Column(String)
neutral_text = Column(String, nullable=True)
categories = Column(Integer, nullable=True)
created_at = Column(DateTime)
def create_all_tables(engine: Engine):
Base.metadata.create_all(bind=engine)