-
-
Notifications
You must be signed in to change notification settings - Fork 118
/
models.py
65 lines (53 loc) · 2.37 KB
/
models.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
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
import os
from sqlalchemy import BINARY, Column, DateTime, Integer, String
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from config import SQLALCHEMY_DATABASE_URL
# 数据库目录不存在的时候自动创建目录。TODO:如果是mysql之类的数据库,这里的代码估计是不兼容的
folder_path = os.path.dirname(SQLALCHEMY_DATABASE_URL.replace("sqlite:///", ""))
if not os.path.exists(folder_path):
os.makedirs(folder_path)
# 本地扫描数据库
BaseModel = declarative_base()
engine = create_engine(
SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False}
)
DatabaseSession = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# PexelsVideo数据库
BaseModelPexelsVideo = declarative_base()
engine_pexels_video = create_engine(
'sqlite:///./PexelsVideo.db',
connect_args={"check_same_thread": False}
)
DatabaseSessionPexelsVideo = sessionmaker(autocommit=False, autoflush=False, bind=engine_pexels_video)
def create_tables():
"""
创建数据库表
"""
BaseModel.metadata.create_all(bind=engine)
BaseModelPexelsVideo.metadata.create_all(bind=engine_pexels_video)
class Image(BaseModel):
__tablename__ = "image"
id = Column(Integer, primary_key=True)
path = Column(String(4096), index=True) # 文件路径
modify_time = Column(DateTime) # 文件修改时间
features = Column(BINARY) # 文件预处理后的二进制数据
class Video(BaseModel):
__tablename__ = "video"
id = Column(Integer, primary_key=True)
path = Column(String(4096), index=True) # 文件路径
frame_time = Column(Integer, index=True) # 这一帧所在的时间
modify_time = Column(DateTime) # 文件修改时间
features = Column(BINARY) # 文件预处理后的二进制数据
class PexelsVideo(BaseModelPexelsVideo):
__tablename__ = "PexelsVideo"
id = Column(Integer, primary_key=True)
title = Column(String(128)) # 标题
description = Column(String(256)) # 视频描述
duration = Column(Integer, index=True) # 视频时长,单位秒
view_count = Column(Integer, index=True) # 视频播放量
thumbnail_loc = Column(String(256), index=True) # 视频缩略图链接
content_loc = Column(String(256)) # 视频链接
thumbnail_feature = Column(BINARY) # 视频缩略图特征