Auto-create account in both MySQL and PG
This commit is contained in:
10
src/main/java/database/account/Account.java
Normal file
10
src/main/java/database/account/Account.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package database.account;
|
||||
|
||||
import lombok.Builder;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Builder
|
||||
public record Account(String name, String password, boolean acceptedTos, LocalDate birthdate, String pin, String pic,
|
||||
int loggedIn) {
|
||||
}
|
||||
31
src/main/java/database/account/AccountRepository.java
Normal file
31
src/main/java/database/account/AccountRepository.java
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,7 @@ public class CharacterSaver {
|
||||
try (Handle handle = pgConnection.getHandle()) {
|
||||
handle.useTransaction(h -> doPostgresSave(h, chr));
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error saving chr to PG: " + e.getMessage());
|
||||
log.error("Error saving chr {} to PG", chr.getName(), e);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user