-
Notifications
You must be signed in to change notification settings - Fork 0
UserRepositoryを試しにEntity APIで実装してみたがダメだった件 #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Entity API doesn't provide a way to get generated auto increment key when inserting record. So it's impossible to reproduce the same logic as SQL DSL.
|
|
||
| @Repository | ||
| class UsersRepositoryImpl(val database: Database): UsersRepository { | ||
| // insert時に生成されたidを取得する手段がない |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これが致命的だった。やはりAuto incrementなIDを振る場合Entity APIは使えない。UUIDを使うのであればアリかも。
|
|
||
| return user.copy(id = id) | ||
| val userDao = buildDao(user) | ||
| users().add(userDao) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addメソッドの返り値はinsert文のaffected rowの数。そんなん要らんのよ 😇
| val userDao = buildDao(user) | ||
| users().add(userDao) | ||
|
|
||
| return user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ID取ってこれない以上他にユニークなキーがないので検索して引っ張ってくることもできない。とりあえず元のエンティティ返してるけどID = 0が入ってるのでこの返り値は使えない。
やったこと