websoft9/appmanage/api/service/db.py

49 lines
1.7 KiB
Python
Raw Normal View History

2023-08-27 00:16:30 +08:00
import sqlite3
2023-06-30 10:34:44 +08:00
from api.exception.command_exception import CommandException
from api.utils import const
2023-08-27 00:16:30 +08:00
2023-06-29 17:52:15 +08:00
2023-06-30 09:59:08 +08:00
def dict_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d
2023-06-29 17:52:15 +08:00
def AppUpdateUser(user_name, password):
2023-08-17 16:05:24 +08:00
conn = sqlite3.connect('/usr/src/app/db/database.sqlite')
2023-06-30 09:59:08 +08:00
cursor = conn.cursor()
cursor.execute("UPDATE user SET password=? WHERE user_name=?", ( password,user_name,))
2023-06-29 17:52:15 +08:00
conn.commit()
2023-06-30 09:59:08 +08:00
conn.close()
2023-06-29 17:52:15 +08:00
2023-08-18 16:38:40 +08:00
def AppUpdatePreview(preview):
conn = sqlite3.connect('/usr/src/app/db/database.sqlite')
cursor = conn.cursor()
cursor.execute("UPDATE app_preview SET preview=? WHERE module='appstore'", ( preview,))
conn.commit()
conn.close()
def AppSearchPreview():
conn = sqlite3.connect('/usr/src/app/db/database.sqlite')
conn.row_factory = dict_factory
cursor = conn.cursor()
2023-08-18 16:55:32 +08:00
cursor.execute("SELECT preview FROM app_preview WHERE module='appstore'")
2023-08-18 16:38:40 +08:00
rows = cursor.fetchone()
conn.close()
return rows
2023-06-29 17:52:15 +08:00
def AppSearchUsers(user_type):
2023-06-30 10:41:09 +08:00
if user_type == None or user_type == "undefine":
raise CommandException(const.ERROR_CLIENT_PARAM_BLANK, "This plugin is blank!", "This plugin is blank!")
if user_type != "nginx" and user_type != "portainer":
2023-06-30 10:34:44 +08:00
raise CommandException(const.ERROR_CLIENT_PARAM_NOTEXIST, "This plugin doesn't exist!", "This plugin doesn't exist!")
2023-08-17 16:05:24 +08:00
conn = sqlite3.connect('/usr/src/app/db/database.sqlite')
2023-06-30 09:59:08 +08:00
conn.row_factory = dict_factory
cursor = conn.cursor()
cursor.execute("SELECT user_name,password,nick_name FROM user WHERE user_type=?", (user_type,))
rows = cursor.fetchone()
conn.close()
return rows