dieselpoint / norm

Access a database in one line of code.
Other
205 stars 36 forks source link

how it initialize for sqlite #12

Open GF-Huang opened 8 years ago

GF-Huang commented 8 years ago

sqlite do not need localhost System.setProperty("norm.serverName", "localhost");

ccleve commented 8 years ago

Ok. Does it work for sqllite otherwise?

GF-Huang commented 8 years ago

never try other, because i'm using sqlite and i must use it in my environment.

ccleve commented 8 years ago

No, what I mean is, does it work ok for sqllite? Are you having any problems?

On Tue, May 3, 2016 at 1:28 PM, Great Fire Wall notifications@github.com wrote:

never try other, because i'm using sqlite and i must use it in my environment.

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/dieselpoint/norm/issues/12#issuecomment-216621635

GF-Huang commented 8 years ago

it's not work for sqlite. but I see https://github.com/brettwooldridge/HikariCP/issues/393, and make my code like this, it work fine. code:

import com.dieselpoint.norm.Database;

public final class Db extends Database {
    @Override
    protected DataSource getDataSource() throws SQLException {
        HikariConfig config = new HikariConfig();
        config.setDriverClassName("org.sqlite.JDBC");
        config.setJdbcUrl("jdbc:sqlite:file.db");
        config.setConnectionTestQuery("SELECT 1");
        config.setMaximumPoolSize(100);
        config.setInitializationFailFast(true); // optional

        return new HikariDataSource(config);
    }
}

main here:
    Db db = new Db();
    db.getConnection();  // work fine, and file.db will create.