获取用户信息
(self, user_id: int)
| 187 | conn.close() |
| 188 | |
| 189 | def get_user(self, user_id: int) -> Optional[Dict]: |
| 190 | """获取用户信息""" |
| 191 | conn = self.get_connection() |
| 192 | cursor = conn.cursor(DictCursor) |
| 193 | |
| 194 | try: |
| 195 | cursor.execute("SELECT * FROM users WHERE user_id = %s", (user_id,)) |
| 196 | row = cursor.fetchone() |
| 197 | |
| 198 | if row: |
| 199 | # 创建新字典并转换datetime为ISO格式字符串 |
| 200 | result = dict(row) |
| 201 | if result.get('created_at'): |
| 202 | result['created_at'] = result['created_at'].isoformat() |
| 203 | if result.get('last_checkin'): |
| 204 | result['last_checkin'] = result['last_checkin'].isoformat() |
| 205 | return result |
| 206 | return None |
| 207 | |
| 208 | finally: |
| 209 | cursor.close() |
| 210 | conn.close() |
| 211 | |
| 212 | def user_exists(self, user_id: int) -> bool: |
| 213 | """检查用户是否存在""" |
no test coverage detected