sync: 同步 sql-platform-pro 最新代码 — 权限体系安全修复 v0.8.1
- P0: 实例访问控制全线接入权限组 (829测试) - P1: permissions字段激活 + 操作级权限检查 (843测试) - 前端: 删除数据权限页面, 权限组合并为唯一入口 - 新增: CodeMirror编辑器 + 查询模板 + 慢查询分析 - 新增: MongoDB管理页面 + Dashboard增强 - 修复: Pydantic V2迁移 + 前端TS错误修复
This commit is contained in:
1 parent
6fcd9465cf
commit
4c9427e546
105 files changed
+23680
-471
No files matched your search
@@ -0,0 +1,173 @@
|
||||
/**
|
||||
* 查询模板系统
|
||||
* 提供 10 个预设模板,适配 MySQL、PostgreSQL、Redis、MongoDB 四种数据库类型
|
||||
*/
|
||||
|
||||
export type DBType = 'mysql' | 'postgresql' | 'redis' | 'mongodb';
|
||||
|
||||
export type QueryTemplate = {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
category: string;
|
||||
sql: Partial<Record<DBType, string>>;
|
||||
supportedTypes: DBType[];
|
||||
};
|
||||
|
||||
export const queryTemplates: QueryTemplate[] = [
|
||||
{
|
||||
id: 'table-structure',
|
||||
name: '查询表结构',
|
||||
description: '查看指定表或集合的结构定义,包括字段、类型、索引等信息',
|
||||
category: '表结构',
|
||||
sql: {
|
||||
mysql: 'SHOW CREATE TABLE {table};',
|
||||
postgresql:
|
||||
"SELECT column_name, data_type, is_nullable, column_default FROM information_schema.columns WHERE table_name = '{table}' ORDER BY ordinal_position;",
|
||||
mongodb: 'db.{collection}.getIndexes()',
|
||||
},
|
||||
supportedTypes: ['mysql', 'postgresql', 'mongodb'],
|
||||
},
|
||||
{
|
||||
id: 'slow-queries',
|
||||
name: '查询慢SQL',
|
||||
description: '查看慢查询日志,定位执行时间较长的SQL语句',
|
||||
category: '性能分析',
|
||||
sql: {
|
||||
mysql: 'SELECT * FROM mysql.slow_log LIMIT 20;',
|
||||
postgresql:
|
||||
'SELECT * FROM pg_stat_statements ORDER BY total_time DESC LIMIT 20;',
|
||||
},
|
||||
supportedTypes: ['mysql', 'postgresql'],
|
||||
},
|
||||
{
|
||||
id: 'table-size',
|
||||
name: '查询表大小',
|
||||
description: '查看数据库中各表或集合的存储空间占用情况',
|
||||
category: '数据统计',
|
||||
sql: {
|
||||
mysql: "SELECT table_name, data_length, index_length FROM information_schema.tables WHERE table_schema = '{db}';",
|
||||
postgresql:
|
||||
"SELECT relname, pg_relation_size(oid) FROM pg_class WHERE relkind='r';",
|
||||
redis: 'INFO memory',
|
||||
mongodb: 'db.stats()',
|
||||
},
|
||||
supportedTypes: ['mysql', 'postgresql', 'redis', 'mongodb'],
|
||||
},
|
||||
{
|
||||
id: 'active-connections',
|
||||
name: '查询活跃连接',
|
||||
description: '查看当前数据库的活跃连接数及连接详情',
|
||||
category: '性能分析',
|
||||
sql: {
|
||||
mysql: 'SHOW PROCESSLIST;',
|
||||
postgresql: 'SELECT * FROM pg_stat_activity;',
|
||||
redis: 'CLIENT LIST',
|
||||
mongodb: 'db.currentOp()',
|
||||
},
|
||||
supportedTypes: ['mysql', 'postgresql', 'redis', 'mongodb'],
|
||||
},
|
||||
{
|
||||
id: 'indexes',
|
||||
name: '查询索引',
|
||||
description: '查看指定表或集合的索引信息',
|
||||
category: '表结构',
|
||||
sql: {
|
||||
mysql: 'SHOW INDEX FROM {table};',
|
||||
postgresql:
|
||||
"SELECT * FROM pg_indexes WHERE tablename = '{table}';",
|
||||
mongodb: 'db.{collection}.getIndexes()',
|
||||
},
|
||||
supportedTypes: ['mysql', 'postgresql', 'mongodb'],
|
||||
},
|
||||
{
|
||||
id: 'lock-waits',
|
||||
name: '查询锁等待',
|
||||
description: '查看当前数据库中存在的锁等待情况,排查锁冲突',
|
||||
category: '性能分析',
|
||||
sql: {
|
||||
mysql: 'SELECT * FROM information_schema.innodb_lock_waits;',
|
||||
postgresql: 'SELECT * FROM pg_locks WHERE NOT granted;',
|
||||
},
|
||||
supportedTypes: ['mysql', 'postgresql'],
|
||||
},
|
||||
{
|
||||
id: 'top-n',
|
||||
name: 'TOP N查询',
|
||||
description: '查询指定表中按ID倒序排列的前N条记录',
|
||||
category: '基础查询',
|
||||
sql: {
|
||||
mysql: 'SELECT * FROM {table} ORDER BY id DESC LIMIT {n};',
|
||||
postgresql: 'SELECT * FROM {table} ORDER BY id DESC LIMIT {n};',
|
||||
mongodb: 'db.{collection}.find().sort({_id:-1}).limit({n})',
|
||||
},
|
||||
supportedTypes: ['mysql', 'postgresql', 'mongodb'],
|
||||
},
|
||||
{
|
||||
id: 'fuzzy-search',
|
||||
name: '模糊搜索',
|
||||
description: '根据关键词对指定字段进行模糊匹配查询',
|
||||
category: '基础查询',
|
||||
sql: {
|
||||
mysql: "SELECT * FROM {table} WHERE {column} LIKE '%{keyword}%';",
|
||||
postgresql: "SELECT * FROM {table} WHERE {column} LIKE '%{keyword}%';",
|
||||
redis: 'KEYS *{keyword}*',
|
||||
mongodb: 'db.{collection}.find({field: /{keyword}/})',
|
||||
},
|
||||
supportedTypes: ['mysql', 'postgresql', 'redis', 'mongodb'],
|
||||
},
|
||||
{
|
||||
id: 'statistics',
|
||||
name: '查询统计信息',
|
||||
description: '查看表或集合的统计信息,包括行数、大小、索引等',
|
||||
category: '数据统计',
|
||||
sql: {
|
||||
mysql: "SHOW TABLE STATUS LIKE '{table}';",
|
||||
postgresql:
|
||||
"SELECT * FROM pg_stat_user_tables WHERE relname='{table}';",
|
||||
redis: 'INFO keyspace',
|
||||
mongodb: 'db.{collection}.stats()',
|
||||
},
|
||||
supportedTypes: ['mysql', 'postgresql', 'redis', 'mongodb'],
|
||||
},
|
||||
{
|
||||
id: 'execution-plan',
|
||||
name: '查询执行计划',
|
||||
description: '查看查询语句的执行计划,用于SQL性能优化分析',
|
||||
category: '性能分析',
|
||||
sql: {
|
||||
mysql: 'EXPLAIN SELECT ...',
|
||||
postgresql: 'EXPLAIN ANALYZE SELECT ...',
|
||||
mongodb: 'db.{collection}.find({...}).explain()',
|
||||
},
|
||||
supportedTypes: ['mysql', 'postgresql', 'mongodb'],
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取模板在指定数据库类型下的查询语句
|
||||
* @param template 查询模板
|
||||
* @param dbType 数据库类型
|
||||
* @returns 对应的查询语句,如果不支持则返回提示信息
|
||||
*/
|
||||
export function getTemplateSQL(
|
||||
template: QueryTemplate,
|
||||
dbType: DBType
|
||||
): string {
|
||||
const sql = template.sql[dbType];
|
||||
if (!sql) {
|
||||
return `-- 当前模板「${template.name}」不支持 ${dbType} 数据库类型`;
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定数据库类型支持的所有模板
|
||||
* @param dbType 数据库类型
|
||||
* @returns 该数据库类型支持的模板列表
|
||||
*/
|
||||
export function getTemplatesForType(dbType: DBType): QueryTemplate[] {
|
||||
return queryTemplates.filter((template) =>
|
||||
template.supportedTypes.includes(dbType)
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user