带有生成表的光滑隐式参数 'tables'

Slick implicit parameter 'tables' with generated tables

简易版

导入和使用生成的 Slick 表的首选方式是什么?

详细版本和我试过的

我使用 Slick 3.1.1 codegen 从 MySQL (MariaDB) 模式生成 Tables.scala

Tables.scala 开头是这样的:

// AUTO-GENERATED Slick data model
/** Stand-alone Slick data model for immediate use */
object Tables extends {
    val profile = slick.driver.MySQLDriver
} with Tables

使用这些 class 的最佳方式是什么?根据 Slick documentation:

The file contains an object Tables from which the code can be imported for use right away. ... The file also contains a trait Tables which can be used in the cake pattern.

...我试过 this example

的变体
import Tables._
import Tables.profile.api._
import slick.jdbc.JdbcBackend

class Test(s: String)(implicit db: Database) {
    def exec[T](action: DBIO[T])(implicit db: Database): T =
            Await.result(db run action)
    def run: Unit = exec(((ATable filter (_.id)).result)
}
object Test {
    implicit val db = Database.forURL(url, user, password)
    new Test("")
}

我在任何地方引用 class ATable:

时都会遇到编译错误
could not find implicit value for parameter tables: Tables

我什至没有在 Tables.scala 中看到 tables。我如何在范围内获得我需要的一切来使用我生成的 Slick classes?

我得到了这个例子:Tables._Tables.profile.api._ 只需要导入到 class 中,隐含的 Database 可用。

import slick.jdbc.JdbcBackend

class Test(s: String)(implicit db: Database) {
    import Tables._
    import Tables.profile.api._

    def exec[T](action: DBIO[T])(implicit db: Database): T =
            Await.result(db run action)
    def run: Unit = exec(((ATable filter (_.id)).result)
}
object Test {
    implicit val db = Database.forURL(url, user, password)
    new Test("")
}