This repository was archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatabase.py
More file actions
53 lines (37 loc) · 1.25 KB
/
database.py
File metadata and controls
53 lines (37 loc) · 1.25 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from sqlalchemy import create_engine, Column, Integer, String, Boolean
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Document(Base):
__tablename__ = 'documents'
id = Column(Integer, primary_key=True)
url = Column(String, nullable=False)
file = Column(Boolean, default=None)
preview = Column(Boolean, default=None)
title = Column(String)
user = Column(String)
description = Column(String)
course = Column(String)
date = Column(String)
pages = Column(Integer)
type = Column(String)
cached = Column(String, default="Not cached")
file_name = Column(String)
class Counter(Base):
__tablename__ = 'counters'
id = Column(String, primary_key=True)
count = Column(Integer, default=0)
class Download(Base):
__tablename__ = 'downloads'
id = Column(String, primary_key=True)
document_id = Column(Integer, nullable=False)
expires = Column(Integer, nullable=False)
def create_session():
engine = create_engine('sqlite:///studydrive.db')
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
return Session()
def init_db():
session = create_session()
session.close()
init_db()