質問編集履歴
1
モデル(リポジトリ)の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -162,7 +162,11 @@
|
|
162
162
|
|
163
163
|
```
|
164
164
|
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
165
|
-
### index.
|
169
|
+
### index.scala.html (テンプレート)
|
166
170
|
|
167
171
|
```
|
168
172
|
|
@@ -188,7 +192,81 @@
|
|
188
192
|
|
189
193
|
```
|
190
194
|
|
191
|
-
|
195
|
+
### PresonRepository.scala (リポジトリ)
|
196
|
+
|
197
|
+
```
|
198
|
+
|
199
|
+
package models
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
import javax.inject.{ Inject, Singleton }
|
204
|
+
|
205
|
+
import play.api.db.slick.DatabaseConfigProvider
|
206
|
+
|
207
|
+
import slick.jdbc.JdbcProfile
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
import scala.concurrent.{ Future, ExecutionContext }
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
@Singleton
|
216
|
+
|
217
|
+
class PersonRepository @Inject()
|
218
|
+
|
219
|
+
(dbConfigProvider: DatabaseConfigProvider)
|
220
|
+
|
221
|
+
(implicit ec: ExecutionContext) {
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
private val dbConfig = dbConfigProvider.get[JdbcProfile]
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
import dbConfig._
|
230
|
+
|
231
|
+
import profile.api._
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
private class PeopleTable(tag: Tag)
|
236
|
+
|
237
|
+
extends Table[Person](tag, "people") {
|
238
|
+
|
239
|
+
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
|
240
|
+
|
241
|
+
def name = column[String]("name")
|
242
|
+
|
243
|
+
def mail = column[String]("mail")
|
244
|
+
|
245
|
+
def tel = column[String]("tel")
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
def * = (id, name, mail, tel) <>
|
250
|
+
|
251
|
+
((Person.apply _).tupled, Person.unapply)
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
private val people = TableQuery[PeopleTable]
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
def list(): Future[Seq[Person]] = db.run {
|
262
|
+
|
263
|
+
people.result
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
```
|
192
270
|
|
193
271
|
### バージョン
|
194
272
|
|