0
PostgreSQLのテーブルに乱数を使って複数の行(約1 mill。)を挿入する必要があります。このコードは乱数を1つの列に挿入します。どのように私はそれをすべての列に同時にランダムなデータを挿入することができますか?Scala Slick複数のランダムな行をPostgreSQLデータベースに挿入
輸入slick.driver.PostgresDriver.simple._
object Main {
class Users(tag: Tag) extends Table[(Int, String, String)](tag, "users") {
def id = column[Int]("id")
def username = column[String]("username")
def miestas = column[String]("miestas")
def * = (id, username, miestas)
}
def main(args: Array[String]): Unit = {
val connectionUrl = "jdbc:postgresql://localhost/test?user=postgres&password=kurmis"
Database.forURL(connectionUrl, driver = "org.postgresql.Driver") withSession {
implicit session =>
val users = TableQuery[Users]
for (a <- 1 to 10) {
val r = scala.util.Random
users.map(_.username) += r.nextInt.toString
}
//Insert
val r = scala.util.Random
users.map(_.username) += r.nextInt.toString
println("pabandom")
}
}
}