Skip to content

Commit

Permalink
feat: 테이블 설계 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
be-student committed Mar 25, 2023
1 parent 2aae9c8 commit 3becd43
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
38 changes: 37 additions & 1 deletion script.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
create table chess_test.table_name
create table chess.user
(
user_id varchar(100) null
);
create table chess.chess_board
(
user_id varchar(100) null,
chess_id int auto_increment,
constraint chess_board_pk
primary key (chess_id)
);
create table chess.move
(
chess_id int not null,
origin varchar(10) not null,
destination varchar(10) not null,
turn int not null
);
create table chess_test.user_dao
(
user_id varchar(100) null,
name varchar(100) null
);
create table chess_test.user
(
user_id varchar(100) null
);
create table chess_test.chess_board
(
user_id varchar(100) null,
chess_id int auto_increment,
constraint chess_board_pk
primary key (chess_id)
);
create table chess_test.move
(
chess_id int not null,
origin varchar(10) not null,
destination varchar(10) not null,
turn int not null
);
8 changes: 4 additions & 4 deletions src/main/java/database/UserDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public UserDao(JdbcTemplate jdbcTemplate) {
}

public void addUser(User user) {
jdbcTemplate.executeUpdate("INSERT INTO user VALUES(?, ?)", user.userId(), user.name());
jdbcTemplate.executeUpdate("INSERT INTO user_dao VALUES(?, ?)", user.userId(), user.name());
}

public User findByUserId(String userId) {
return jdbcTemplate.query("SELECT * FROM user WHERE user_id = ?", getUserRowMapper(), userId);
return jdbcTemplate.query("SELECT * FROM user_dao WHERE user_id = ?", getUserRowMapper(), userId);
}

private RowMapper<User> getUserRowMapper() {
Expand All @@ -32,10 +32,10 @@ private RowMapper<User> getUserRowMapper() {
}

public void update(User user, String name) {
jdbcTemplate.executeUpdate("UPDATE user SET name = ? WHERE user_id = ?", name, user.userId());
jdbcTemplate.executeUpdate("UPDATE user_dao SET name = ? WHERE user_id = ?", name, user.userId());
}

public void delete(String userId) {
jdbcTemplate.executeUpdate("DELETE FROM user WHERE user_id = ?", userId);
jdbcTemplate.executeUpdate("DELETE FROM user_dao WHERE user_id = ?", userId);
}
}

0 comments on commit 3becd43

Please sign in to comment.