From 4a4b7c0010345f24e29dc798af17695ddc0c901f Mon Sep 17 00:00:00 2001 From: MarkusJoe Date: Fri, 18 Feb 2022 19:32:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/sqlite.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/db/sqlite.py b/db/sqlite.py index 64d8d66..7cfd4cb 100644 --- a/db/sqlite.py +++ b/db/sqlite.py @@ -6,10 +6,7 @@ # @File Name: sqlite.py import sqlite3 - -""" -使用python3自带的Sqlite3进行数据库操作 -""" +from typing import Any def insert_data(name: str) -> None: @@ -95,3 +92,22 @@ def fetch_table() -> list: cursor_temp.close() conn_temp.close() + +def fetch_style_data(style: str) -> list[dict[str, Any]]: + """ + 获取主题数据库内的数据 + :param style: + :return: + """ + conn = sqlite3.connect('./db/style.db', check_same_thread=False) + cursor = conn.cursor() + try: + cursor.execute('select * from %(style_name)s' % {'style_name': style}) + data = cursor.fetchall() + data_set = [] + for i in data: + data_set.append({'index': i[0], 'base64': i[1], 'width': i[2], 'height': i[3]}) + return data_set + finally: + cursor.close() + conn.close()