package com.fshark.overseas.advert.util;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.jdbi.v3.core.Jdbi;
import org.jdbi.v3.sqlobject.SqlObjectPlugin;
import ru.yandex.clickhouse.ClickHouseConnection;
import ru.yandex.clickhouse.ClickHouseDataSource;
import ru.yandex.clickhouse.settings.ClickHouseProperties;

import java.sql.SQLException;

/**
 * @author libing
 * @version 1.0
 * @date 2019-08-08 16:35
 */
public class DatabaseUtils {


    public static JdbiContext getCHGenJdbiClient(String url, String username, String password) throws SQLException {
        HikariConfig hc = new HikariConfig();
        hc.setDriverClassName("ru.yandex.clickhouse.ClickHouseDriver");
        hc.setJdbcUrl(url);
        hc.setUsername(username);
        hc.setPassword(password);
        hc.setMaximumPoolSize(4);
        HikariDataSource hikariDataSource = new HikariDataSource(hc);
        Jdbi jdbi = Jdbi.create(hikariDataSource);
        jdbi.installPlugin(new SqlObjectPlugin());
        return new JdbiContext(hikariDataSource, jdbi);
    }
}
