ObjectiveSql icon indicating copy to clipboard operation
ObjectiveSql copied to clipboard

clickhouse数据库可以适配吗?

Open activepirate opened this issue 4 years ago • 6 comments

clickhouse表不能设置主键自增,现在的版本,支不支持clickhouse数据库阿

activepirate avatar Nov 26 '20 09:11 activepirate

这块还在开发中。有兴趣你可以提交PR

catchex avatar Nov 26 '20 09:11 catchex

objsql调用jdbc插入部分

https://github.com/braisdom/ObjectiveSql/blob/58e67c5762742c9c4f65bf5487bdaff0f606ab2f/core/src/main/java/com/github/braisdom/objsql/jdbc/QueryRunner.java#L599

clickhouse驱动对prepareStatement方法的实现 https://github.com/ClickHouse/clickhouse-jdbc/blob/master/src/main/java/ru/yandex/clickhouse/ClickHouseConnectionImpl.java#L337

@Override
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
    throw new SQLFeatureNotSupportedException();
}

activepirate avatar Dec 03 '20 03:12 activepirate

这应该是数据库适配,你先手工调整一下,我查看一下是否有API 判断是否支持Statement.RETURN_GENERATED_KEYS 这类API,如果没有,可以在外层catch SQLFeatureNotSupportedException 异常

catchex avatar Dec 03 '20 03:12 catchex

我觉得这块可以考虑 如果domains设置主键自增,调用

public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)

如果domains设置非主键自增,调用

public PreparedStatement prepareStatement(String sql)

activepirate avatar Dec 03 '20 03:12 activepirate

你的想法是可行的,但不够健全,如果Clickhouse 有大量的DomainModel 都要去设计 autoGenerated 有点麻烦,还是要增强底层程序的健壮性,这是API 设计的基本特性

catchex avatar Dec 03 '20 03:12 catchex

@catchex @activepirate 请问两位最后是怎么解决该问题的 我现在也遇到了

zhilinli123 avatar Jul 29 '22 07:07 zhilinli123