Skip to content

Instantly share code, notes, and snippets.

@syossan27
Created October 31, 2017 07:15
Show Gist options
  • Select an option

  • Save syossan27/98edc13b6b4c466da6e086cdbc306ba0 to your computer and use it in GitHub Desktop.

Select an option

Save syossan27/98edc13b6b4c466da6e086cdbc306ba0 to your computer and use it in GitHub Desktop.
// テーブルに指定したIDのレコードがあれば、Contentsを返す
// 無かった場合、新たなレコードをInsertし、結果のContentsを返す
def hoge(id: Int): String = {
Await.result(database.findById(id), Duration.Inf) match {
case Some(result) => {
// idに合致するレコードがあればcontentsを返す
return result.contents
}
case None => {
val table_entity = TableEntity(id, "コンテンツ")
Await.result(database.save(table_entity), Duration.Inf) match {
case result => {
if (result) {
// insertが成功した場合
Await.result(database.findById(id), Duration.Inf) match {
case Some(result) => {
// 発見すればproduct_tokenを返す
return result.contents
}
case None => {
// エラー処理
}
}
} else {
// insertが失敗した場合
// エラー処理
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment