mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-08-06 01:36:46 +08:00
support view trigger producer function
This commit is contained in:
@ -74,36 +74,38 @@ public class DlTemplateServiceImpl implements DlTemplateService {
|
||||
|
||||
// 解析sql分页
|
||||
SQLStatement sqlStatement;
|
||||
boolean autoLimit = false;
|
||||
try {
|
||||
sqlStatement = SQLUtils.parseSingleStatement(sql, dbType);
|
||||
// 是否需要代码帮忙分页
|
||||
|
||||
if (sqlStatement instanceof SQLSelectStatement) {
|
||||
// 不是查询全部数据 而且 用户自己没有传分页
|
||||
autoLimit = BooleanUtils.isNotTrue(param.getPageSizeAll()) && SQLUtils.getLimit(sqlStatement,
|
||||
dbType)
|
||||
== null;
|
||||
if (autoLimit) {
|
||||
pageNo = Optional.ofNullable(param.getPageNo()).orElse(1);
|
||||
pageSize = Optional.ofNullable(param.getPageSize()).orElse(EasyToolsConstant.MAX_PAGE_SIZE);
|
||||
int offset = (pageNo - 1) * pageSize;
|
||||
try {
|
||||
sql = PagerUtils.limit(sql, dbType, offset, pageSize);
|
||||
} catch (Exception e) {
|
||||
autoLimit = false;
|
||||
}
|
||||
}
|
||||
sqlType = SqlTypeEnum.SELECT.getCode();
|
||||
}
|
||||
} catch (ParserException e) {
|
||||
log.warn("解析sql失败:{}", sql, e);
|
||||
ExecuteResult executeResult = ExecuteResult.builder()
|
||||
.success(Boolean.FALSE)
|
||||
.originalSql(originalSql)
|
||||
.sql(sql)
|
||||
.message(e.getMessage())
|
||||
.build();
|
||||
result.add(executeResult);
|
||||
continue;
|
||||
}
|
||||
// 是否需要代码帮忙分页
|
||||
boolean autoLimit = false;
|
||||
if (sqlStatement instanceof SQLSelectStatement) {
|
||||
// 不是查询全部数据 而且 用户自己没有传分页
|
||||
autoLimit = BooleanUtils.isNotTrue(param.getPageSizeAll()) && SQLUtils.getLimit(sqlStatement, dbType)
|
||||
== null;
|
||||
if (autoLimit) {
|
||||
pageNo = Optional.ofNullable(param.getPageNo()).orElse(1);
|
||||
pageSize = Optional.ofNullable(param.getPageSize()).orElse(EasyToolsConstant.MAX_PAGE_SIZE);
|
||||
int offset = (pageNo - 1) * pageSize;
|
||||
try {
|
||||
sql = PagerUtils.limit(sql, dbType, offset, pageSize);
|
||||
} catch (Exception e) {
|
||||
autoLimit = false;
|
||||
}
|
||||
}
|
||||
sqlType = SqlTypeEnum.SELECT.getCode();
|
||||
//ExecuteResult executeResult = ExecuteResult.builder()
|
||||
// .success(Boolean.FALSE)
|
||||
// .originalSql(originalSql)
|
||||
// .sql(sql)
|
||||
// .message(e.getMessage())
|
||||
// .build();
|
||||
//result.add(executeResult);
|
||||
//continue;
|
||||
}
|
||||
|
||||
ExecuteResult executeResult = execute(sql);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ai.chat2db.server.domain.core.impl;
|
||||
|
||||
import ai.chat2db.server.domain.api.service.FunctionService;
|
||||
import ai.chat2db.server.tools.base.wrapper.result.DataResult;
|
||||
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
|
||||
import ai.chat2db.spi.model.Function;
|
||||
import ai.chat2db.spi.sql.Chat2DBContext;
|
||||
@ -12,4 +13,9 @@ public class FunctionServiceImpl implements FunctionService {
|
||||
public ListResult<Function> functions(String databaseName, String schemaName) {
|
||||
return ListResult.of(Chat2DBContext.getMetaData().functions(Chat2DBContext.getConnection(),databaseName, schemaName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataResult<Function> detail(String databaseName, String schemaName, String functionName) {
|
||||
return DataResult.of(Chat2DBContext.getMetaData().function(Chat2DBContext.getConnection(), databaseName, schemaName, functionName));
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ai.chat2db.server.domain.core.impl;
|
||||
|
||||
import ai.chat2db.server.domain.api.service.ProcedureService;
|
||||
import ai.chat2db.server.tools.base.wrapper.result.DataResult;
|
||||
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
|
||||
import ai.chat2db.spi.model.Procedure;
|
||||
import ai.chat2db.spi.sql.Chat2DBContext;
|
||||
@ -13,4 +14,9 @@ public class ProcedureServiceImpl implements ProcedureService {
|
||||
public ListResult<Procedure> procedures(String databaseName, String schemaName) {
|
||||
return ListResult.of(Chat2DBContext.getMetaData().procedures(Chat2DBContext.getConnection(),databaseName, schemaName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataResult<Procedure> detail(String databaseName, String schemaName, String procedureName) {
|
||||
return DataResult.of(Chat2DBContext.getMetaData().procedure(Chat2DBContext.getConnection(), databaseName, schemaName, procedureName));
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ai.chat2db.server.domain.core.impl;
|
||||
|
||||
import ai.chat2db.server.domain.api.service.TriggerService;
|
||||
import ai.chat2db.server.tools.base.wrapper.result.DataResult;
|
||||
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
|
||||
import ai.chat2db.spi.model.Trigger;
|
||||
import ai.chat2db.spi.sql.Chat2DBContext;
|
||||
@ -12,4 +13,9 @@ public class TriggerServiceImpl implements TriggerService {
|
||||
public ListResult<Trigger> triggers(String databaseName, String schemaName) {
|
||||
return ListResult.of(Chat2DBContext.getMetaData().triggers(Chat2DBContext.getConnection(),databaseName, schemaName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataResult<Trigger> detail(String databaseName, String schemaName, String triggerName) {
|
||||
return DataResult.of(Chat2DBContext.getMetaData().trigger(Chat2DBContext.getConnection(), databaseName, schemaName, triggerName));
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,7 @@ public class ViewServiceImpl implements ViewService {
|
||||
@Override
|
||||
public DataResult<Table> detail(String databaseName, String schemaName, String tableName) {
|
||||
MetaData metaSchema = Chat2DBContext.getMetaData();
|
||||
String ddl = metaSchema.tableDDL(Chat2DBContext.getConnection(), databaseName, schemaName, tableName);
|
||||
Table table = new Table();
|
||||
table.setDdl(ddl);
|
||||
table.setName(tableName);
|
||||
table.setSchemaName(schemaName);
|
||||
table.setDatabaseName(databaseName);
|
||||
Table table = metaSchema.view(Chat2DBContext.getConnection(), databaseName, schemaName, tableName);
|
||||
return DataResult.of(table);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user