mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-08-02 21:50:43 +08:00
support for mongodb
This commit is contained in:
@ -1,8 +1,30 @@
|
||||
package ai.chat2db.plugin.mongodb;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import ai.chat2db.spi.DBManage;
|
||||
import ai.chat2db.spi.jdbc.DefaultDBManage;
|
||||
import ai.chat2db.spi.sql.SQLExecutor;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
public class MongodbManage extends DefaultDBManage implements DBManage {
|
||||
@Override
|
||||
public void connectDatabase(Connection connection, String database) {
|
||||
if (StringUtils.isEmpty(database)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
SQLExecutor.getInstance().execute(connection, "use " + database + ";");
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropTable(Connection connection, String databaseName, String schemaName, String tableName) {
|
||||
String sql = " db. " + tableName + ".drop();";
|
||||
SQLExecutor.getInstance().executeSql(connection, sql, resultSet -> null);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user