Auto-create account in both MySQL and PG

This commit is contained in:
P0nk
2024-09-26 07:59:27 +02:00
parent bf9c02bc16
commit 647e67f6e8
13 changed files with 158 additions and 49 deletions

View File

@@ -0,0 +1,31 @@
package database.account;
import database.PgDatabaseConnection;
import org.jdbi.v3.core.Handle;
public class AccountRepository {
private final PgDatabaseConnection connection;
public AccountRepository(PgDatabaseConnection connection) {
this.connection = connection;
}
public Account getByName(String name) {
return null; // TODO
}
public Integer insert(Account account) {
String sql = """
INSERT INTO account (name, password, birthdate)
VALUES (:name, :password, :birthdate)""";
try (Handle handle = connection.getHandle()) {
return handle.createUpdate(sql)
.bind("name", account.name())
.bind("password", account.password())
.bind("birthdate", account.birthdate())
.executeAndReturnGeneratedKeys("id")
.mapTo(Integer.class)
.one();
}
}
}