All Downloads are FREE. Search and download functionalities are using the official Maven repository.

oriana.TableAccess.scala Maven / Gradle / Ivy

Go to download

Oriana is a small layer on top of slick that allows easier access to the database. It allows peudo-syntactic methods to inject a database context into arbitrary code, and simplifies deployment, updates and initialization.

The newest version!
package oriana

import slick.dbio.Effect.Schema
import slick.dbio.{DBIOAction, NoStream}
import slick.jdbc.JdbcProfile
import slick.lifted._

/**
  * Defines access to a slick table. This includes a query object (for CRUD operations) and a schema create action.
  * @tparam TableMappingType type of slick FRM table class
  */
trait TableAccess[TableMappingType <: AbstractTable[_]] {
  /** table query for the given table */
  def query: TableQuery[TableMappingType]
  /** table create schema action */
  def createDDL: DBIOAction[Unit, NoStream, Schema]
}

object TableAccess {
  implicit class SimpleTableAccess[T <: AbstractTable[_]](val query: TableQuery[T])(implicit driver: JdbcProfile) extends TableAccess[T]{
    /** table create schema action */
    override def createDDL: DBIOAction[Unit, NoStream, Schema] = {
      val schema = driver.buildTableSchemaDescription(query.baseTableRow.asInstanceOf[driver.Table[_]])
      driver.createSchemaActionExtensionMethods(schema).create
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy