Don't fail if the DB doesn't exist yet

This commit is contained in:
Gunnar Morling 2023-03-18 21:05:38 +01:00
commit 1d1c40fe30
2 changed files with 6 additions and 1 deletions

View file

@ -112,6 +112,12 @@ public class UserResource {
private int getUserCount() throws SQLException {
try (Connection connection = ds.getConnection()) {
try (Statement statement = connection.createStatement()) {
try (ResultSet rs = statement.executeQuery("SELECT name FROM sqlite_master WHERE type='table' AND name='users'")) {
if (!rs.next()) {
return 0;
}
}
try (ResultSet rs = statement.executeQuery("SELECT COUNT(1) FROM users")) {
rs.next();
return rs.getInt(1);

View file

@ -1,5 +1,4 @@
quarkus.datasource.db-kind=sqlite
quarkus.datasource.autoCommit=false
#quarkus.datasource.jdbc.url=jdbc:sqlite::memory:
quarkus.datasource.jdbc.url=jdbc:sqlite:sample.db
quarkus.hibernate-orm.database.generation=none