mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-07-29 10:43:06 +08:00
fix mysql plugin name error
This commit is contained in:
21
chat2db-server/chat2db-plugins/chat2db-mysql/pom.xml
Normal file
21
chat2db-server/chat2db-plugins/chat2db-mysql/pom.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<parent>
|
||||
<groupId>ai.chat2db</groupId>
|
||||
<artifactId>chat2db-plugins</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>chat2db-mysql</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>ai.chat2db</groupId>
|
||||
<artifactId>chat2db-spi</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,61 @@
|
||||
package ai.chat2db.plugin.mysql;
|
||||
|
||||
import ai.chat2db.spi.DBManage;
|
||||
import ai.chat2db.spi.sql.SQLExecutor;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class MysqlDBManage implements DBManage {
|
||||
@Override
|
||||
public void connectDatabase(String database) {
|
||||
if (StringUtils.isEmpty(database)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
SQLExecutor.getInstance().execute("use `" + database + "`;");
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modifyDatabase(String databaseName, String newDatabaseName) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createDatabase(String databaseName) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropDatabase(String databaseName) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createSchema(String databaseName, String schemaName) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropSchema(String databaseName, String schemaName) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modifySchema(String databaseName, String schemaName, String newSchemaName) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropTable(String databaseName, String schemaName, String tableName) {
|
||||
String sql = "DROP TABLE "+ format(tableName);
|
||||
SQLExecutor.getInstance().executeSql(sql, resultSet -> null);
|
||||
}
|
||||
|
||||
public static String format(String tableName) {
|
||||
return "`" + tableName + "`";
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package ai.chat2db.plugin.mysql;
|
||||
|
||||
import ai.chat2db.spi.MetaData;
|
||||
import ai.chat2db.spi.jdbc.DefaultMetaService;
|
||||
import ai.chat2db.spi.sql.SQLExecutor;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class MysqlMetaData extends DefaultMetaService implements MetaData {
|
||||
@Override
|
||||
public String tableDDL(@NotEmpty String databaseName, String schemaName, @NotEmpty String tableName) {
|
||||
String sql = "SHOW CREATE TABLE " + format(databaseName) + "."
|
||||
+ format( tableName);
|
||||
return SQLExecutor.getInstance().executeSql(sql, resultSet -> {
|
||||
try {
|
||||
if (resultSet.next()) {
|
||||
return resultSet.getString("Create Table");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
public static String format(String tableName) {
|
||||
return "`" + tableName + "`";
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package ai.chat2db.plugin.mysql;
|
||||
|
||||
import ai.chat2db.plugin.mysql.builder.DBConfigBuilder;
|
||||
import ai.chat2db.spi.DBManage;
|
||||
import ai.chat2db.spi.MetaData;
|
||||
import ai.chat2db.spi.Plugin;
|
||||
import ai.chat2db.spi.config.DBConfig;
|
||||
|
||||
public class MysqlPlugin implements Plugin {
|
||||
|
||||
@Override
|
||||
public DBConfig getDBConfig() {
|
||||
return DBConfigBuilder.buildDBConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaData getMetaData() {
|
||||
return new MysqlMetaData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DBManage getDBManage() {
|
||||
return new MysqlDBManage();
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package ai.chat2db.plugin.mysql.builder;
|
||||
|
||||
import ai.chat2db.spi.config.DBConfig;
|
||||
import ai.chat2db.spi.config.DriverConfig;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class DBConfigBuilder {
|
||||
|
||||
public static DBConfig buildDBConfig() {
|
||||
DBConfig dbConfig = new DBConfig();
|
||||
dbConfig.setName("Mysql");
|
||||
dbConfig.setDbType("MYSQL");
|
||||
|
||||
DriverConfig driverConfig = new DriverConfig();
|
||||
driverConfig.setJdbcDriver("mysql-connector-java-8.0.30.jar");
|
||||
driverConfig.setJdbcDriverClass("com.mysql.cj.jdbc.Driver");
|
||||
driverConfig.setDownloadJdbcDriverUrls(Lists.newArrayList("https://oss-chat2db.alibaba.com/lib/mysql-connector-java-8.0.30.jar"));
|
||||
dbConfig.setDefaultDriverConfig(driverConfig);
|
||||
|
||||
|
||||
DriverConfig driverConfig2 = new DriverConfig();
|
||||
driverConfig2.setJdbcDriver("mysql-connector-java-5.1.47.jar");
|
||||
driverConfig2.setJdbcDriverClass("com.mysql.jdbc.Driver");
|
||||
driverConfig2.setDownloadJdbcDriverUrls(Lists.newArrayList("https://oss-chat2db.alibaba.com/lib/mysql-connector-java-5.1.47.jar"));
|
||||
|
||||
dbConfig.setDriverConfigList(Lists.newArrayList(driverConfig,driverConfig2));
|
||||
return dbConfig;
|
||||
}
|
||||
}
|
@ -0,0 +1,183 @@
|
||||
{
|
||||
"baseInfo": {
|
||||
"items": [
|
||||
{
|
||||
"defaultValue": "@localhost",
|
||||
"inputType": "INPUT",
|
||||
"labelNameCN": "名称",
|
||||
"labelNameEN": "Name",
|
||||
"name": "alias",
|
||||
"required": true,
|
||||
"width": 100,
|
||||
},
|
||||
{
|
||||
"defaultValue": "localhost",
|
||||
"inputType": "INPUT",
|
||||
"labelNameCN": "主机",
|
||||
"labelNameEN": "Host",
|
||||
"name": "host",
|
||||
"required": true,
|
||||
"width": 70,
|
||||
},
|
||||
{
|
||||
"defaultValue": "3306",
|
||||
"inputType": "INPUT",
|
||||
"labelNameCN": "端口",
|
||||
"labelNameEN": "Port",
|
||||
"name": "port",
|
||||
"labelTextAlign": "right",
|
||||
"required": true,
|
||||
"width": 30,
|
||||
},
|
||||
{
|
||||
"defaultValue": AuthenticationType.USERANDPASSWORD,
|
||||
"inputType": InputType.SELECT,
|
||||
"labelNameCN": "身份验证",
|
||||
"labelNameEN": "Authentication",
|
||||
"name": "authentication",
|
||||
"required": true,
|
||||
"selects": [
|
||||
{
|
||||
"items": [
|
||||
{
|
||||
"defaultValue": "root",
|
||||
"inputType": "INPUT",
|
||||
"labelNameCN": "用户名",
|
||||
"labelNameEN": "User",
|
||||
"name": "user",
|
||||
"required": true,
|
||||
"width": 100,
|
||||
},
|
||||
{
|
||||
"defaultValue": ",
|
||||
"inputType": InputType.PASSWORD,
|
||||
"labelNameCN": "密码",
|
||||
"labelNameEN": "Password",
|
||||
"name": "password",
|
||||
"required": true,
|
||||
"width": 100,
|
||||
},
|
||||
],
|
||||
"label": "User&Password",
|
||||
"value": AuthenticationType.USERANDPASSWORD,
|
||||
},
|
||||
{
|
||||
"label": "NONE",
|
||||
"value": "NONE,
|
||||
},
|
||||
],
|
||||
"width": 50
|
||||
},
|
||||
{
|
||||
"defaultValue": "",
|
||||
"inputType": "INPUT",
|
||||
"labelNameCN": "数据库",
|
||||
"labelNameEN": "Database",
|
||||
"name": "database",
|
||||
"required": false,
|
||||
"width": 100
|
||||
},
|
||||
{
|
||||
"defaultValue": "jdbc:mysql://localhost:3306",
|
||||
"inputType": "INPUT",
|
||||
"labelNameCN": "URL",
|
||||
"labelNameEN": "URL",
|
||||
"name": "url",
|
||||
"required": true,
|
||||
"width": 100
|
||||
},
|
||||
{
|
||||
"defaultValue": "8.0",
|
||||
"inputType": "SELECT",
|
||||
"labelNameCN": "JDBC驱动",
|
||||
"labelNameEN": "JDBC Driver",
|
||||
"name": "jdbc",
|
||||
"required": true,
|
||||
"selects": [
|
||||
{
|
||||
"value": "8.0"
|
||||
},
|
||||
{
|
||||
"value": "5.0"
|
||||
}
|
||||
],
|
||||
"width": 100
|
||||
}
|
||||
],
|
||||
"pattern": "/jdbc:mysql:\/\/(.*):(\\d+)(\/(\\w+))?/",
|
||||
"template": "jdbc:mysql://{host}:{port}/{database}"
|
||||
},
|
||||
"ssh": {
|
||||
"items": [
|
||||
{
|
||||
"defaultValue": "false",
|
||||
"inputType": "SELECT",
|
||||
"labelNameCN": "使用SSH",
|
||||
"labelNameEN": "USE SSH",
|
||||
"name": "use",
|
||||
"required": false,
|
||||
"selects": [
|
||||
{
|
||||
"value": "false"
|
||||
},
|
||||
{
|
||||
"value": "true"
|
||||
}
|
||||
],
|
||||
"width": 100
|
||||
},
|
||||
{
|
||||
"defaultValue": "",
|
||||
"inputType": "INPUT",
|
||||
"labelNameCN": "SSH 主机",
|
||||
"labelNameEN": "SSH Hostname",
|
||||
"name": "hostName",
|
||||
"required": false,
|
||||
"width": 70
|
||||
},
|
||||
{
|
||||
"defaultValue": "22",
|
||||
"inputType": "INPUT",
|
||||
"labelNameCN": "SSH 端口",
|
||||
"labelNameEN": "Port",
|
||||
"name": "port",
|
||||
"required": false,
|
||||
"width": 28
|
||||
},
|
||||
{
|
||||
"defaultValue": "root",
|
||||
"inputType": "INPUT",
|
||||
"labelNameCN": "用户名",
|
||||
"labelNameEN": "SSH UserName",
|
||||
"name": "userName",
|
||||
"required": false,
|
||||
"width": 70
|
||||
},
|
||||
{
|
||||
"defaultValue": "3306",
|
||||
"inputType": "INPUT",
|
||||
"labelNameCN": "本地端口",
|
||||
"labelNameEN": "LocalPort",
|
||||
"name": "localPort",
|
||||
"required": false,
|
||||
"width": 28
|
||||
},
|
||||
{
|
||||
"defaultValue": "",
|
||||
"inputType": "PASSWORD",
|
||||
"labelNameCN": "密码",
|
||||
"labelNameEN": "Password",
|
||||
"name": "password",
|
||||
"required": true,
|
||||
"width": 100
|
||||
}
|
||||
]
|
||||
},
|
||||
"extendInfo": [
|
||||
{
|
||||
"key":"zeroDateTimeBehavior",
|
||||
"value":"convertToNull"
|
||||
}
|
||||
],
|
||||
"type":"MYSQL"
|
||||
}
|
@ -0,0 +1 @@
|
||||
ai.chat2db.plugin.mysql.MysqlPlugin
|
Reference in New Issue
Block a user