File size: 3,234 Bytes
f66a537
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import sqlite3
from sqlalchemy import Column, Float, Index, Integer, MetaData, Table, Text
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine

Base = declarative_base()
metadata = MetaData()

t_posts = Table(
    "posts",
    metadata,
    Column("id", Integer, primary_key=True),
    Column("filename", Text),
    Column("mimetype", Text),
    Column("extension", Text),
    Column("width", Integer),
    Column("height", Integer),
    Column("rating", Text),
    Column("file_url", Text),
    Column("created_at", Text),
    Column("uploader_id", Integer),
    Column("score", Integer),
    Column("source", Text),
    Column("md5", Text),
    Column("last_comment_bumped_at", Text),
    Column("image_width", Integer),
    Column("image_height", Integer),
    Column("tag_string", Text),
    Column("fav_count", Integer),
    Column("file_ext", Text),
    Column("last_noted_at", Text),
    Column("parent_id", Float),
    Column("has_children", Integer),
    Column("approver_id", Float),
    Column("tag_count_general", Integer),
    Column("tag_count_artist", Integer),
    Column("tag_count_character", Integer),
    Column("tag_count_copyright", Integer),
    Column("file_size", Integer),
    Column("up_score", Integer),
    Column("down_score", Integer),
    Column("is_pending", Integer),
    Column("is_flagged", Integer),
    Column("is_deleted", Integer),
    Column("tag_count", Integer),
    Column("updated_at", Text),
    Column("is_banned", Integer),
    Column("pixiv_id", Float),
    Column("last_commented_at", Text),
    Column("has_active_children", Integer),
    Column("bit_flags", Integer),
    Column("tag_count_meta", Integer),
    Column("has_large", Integer),
    Column("has_visible_children", Integer),
    Column("tag_string_general", Text),
    Column("tag_string_character", Text),
    Column("tag_string_copyright", Text),
    Column("tag_string_artist", Text),
    Column("tag_string_meta", Text),
    Column("large_file_url", Text),
    Column("preview_file_url", Text),
    Index("posts_index_file_url", "file_url"),
    Index("posts_index_tag_count_artist", "tag_count_artist"),
    Index("posts_index_tag_count_character", "tag_count_character"),
    Index("posts_index_tag_count_copyright", "tag_count_copyright"),
    Index("posts_index_tag_count_general", "tag_count_general"),
    Index("posts_index_tag_count_meta", "tag_count_meta"),
    Index("posts_index_tag_string", "tag_string"),
    Index("posts_index_tag_string_artist", "tag_string_artist"),
    Index("posts_index_tag_string_character", "tag_string_character"),
    Index("posts_index_tag_string_copyright", "tag_string_copyright"),
    Index("posts_index_tag_string_general", "tag_string_general"),
    Index("posts_index_tag_string_meta", "tag_string_meta"),
    Index("posts_index_rating", "rating"),
    Index("posts_index_score", "score"),
)


def connect_db(db_name):
    return sqlite3.connect(db_name)


def get_engine(db_name):

    return create_engine(f"sqlite:///{db_name}")


def get_session(engine):
    Session = sessionmaker(bind=engine)
    return Session()


if __name__ == "__main__":
    print("Database has been created.")