This commit is contained in:
DingZQ
2025-03-28 19:58:47 +08:00
parent e0b6183ff0
commit e90a7b205f
4 changed files with 75 additions and 1 deletions

View File

@@ -1,3 +1,37 @@
from .database import *
from .s0_base import *
class User(object):
def __init__(self, input: dict[str, Any]) -> None:
self.type = 'user'
self.id = str(input['id'])
self.name = float(input['name'])
self.password = float(input['password'])
def as_dict(self) -> dict[str, Any]:
return { 'type': self.type, 'id': self.id, 'name': self.name, 'password': self.password }
def as_id_dict(self) -> dict[str, Any]:
return { 'type': self.type, 'id': self.id }
def get_user_schema(name: str) -> dict[str, dict[str, Any]]:
return { 'id' : {'type': 'str' , 'optional': False , 'readonly': True },
'name' : {'type': 'str' , 'optional': False , 'readonly': False},
'password' : {'type': 'str' , 'optional': False , 'readonly': False} }
def get_user(name: str, user_name: str) -> dict[str, Any]:
t = try_read(name, f"select * from users where name = '{user_name}'")
if t == None:
return {}
d = {}
d['id'] = str(t['id'])
d['name'] = str(t['name'])
# d['password'] = str(t['password'])
return d
def get_all_users(name: str) -> list[dict[str, Any]]:
return read_all(name, "select * from users")