Commit 8aad8df1 authored by Peter van 't Hof's avatar Peter van 't Hof

Added case classes to Schema

parent e921c9dd
......@@ -50,6 +50,8 @@ object SummaryToSqlite extends ToolCommand {
summary.createTables
val runId = Await.result(summary.createRun("runName", "kdfhla"), Duration.Inf)
val runs = Await.result(summary.getRuns(), Duration.Inf)
List("1", "2", "3", "4").foreach(x => Await.result(summary.createSample(x, runId, Some("""{"father": "blabla"}""")), Duration.Inf))
println(Await.result(summary.getSamples(), Duration.Inf))
......@@ -60,6 +62,10 @@ object SummaryToSqlite extends ToolCommand {
println(Await.result(summary.getLibraries(), Duration.Inf))
val pipelineId = Await.result(summary.createPipeline("pipelineName", runId), Duration.Inf)
println(Await.result(summary.getPipelines(), Duration.Inf))
db.close()
logger.info("Done")
......
......@@ -18,8 +18,8 @@ class SummaryDb(db: Database) {
try {
val setup = DBIO.seq(
(runs.schema ++ samples.schema ++
libraries.schema ++ pipelineNames.schema ++
moduleNames.schema ++ stats.schema ++ settings.schema ++
libraries.schema ++ pipelines.schema ++
modules.schema ++ stats.schema ++ settings.schema ++
files.schema ++ executables.schema).create
)
val setupFuture = db.run(setup)
......@@ -29,7 +29,7 @@ class SummaryDb(db: Database) {
def createRun(runName: String, outputDir: String): Future[Int] = {
val id = Await.result(db.run(runs.size.result), Duration.Inf)
db.run(runs.forceInsert(id, runName, outputDir)).map(_ => id)
db.run(runs.forceInsert(Run(id, runName, outputDir))).map(_ => id)
}
def getRuns(runId: Option[Int] = None, runName: Option[String] = None, outputDir: Option[String] = None) = {
......@@ -45,7 +45,7 @@ class SummaryDb(db: Database) {
def createSample(name: String, runId: Int, tags: Option[String] = None): Future[Int] = {
val id = Await.result(db.run(samples.size.result), Duration.Inf)
db.run(samples.forceInsert(id, name, runId, tags)).map(_ => id)
db.run(samples.forceInsert(Sample(id, name, runId, tags))).map(_ => id)
}
def getSamples(sampleId: Option[Int] = None, runId: Option[Int] = None, name: Option[String] = None) = {
......@@ -66,7 +66,7 @@ class SummaryDb(db: Database) {
def createLibrary(name: String, runId: Int, sampleId: Int, tags: Option[String] = None): Future[Int] = {
val id = Await.result(db.run(libraries.size.result), Duration.Inf)
db.run(libraries.forceInsert(id, name, runId, sampleId, tags)).map(_ => id)
db.run(libraries.forceInsert(Library(id, name, runId, sampleId, tags))).map(_ => id)
}
def getLibraries(libId: Option[Int] = None, name: Option[String] = None, runId: Option[Int] = None, sampleId: Option[Int] = None) = {
......@@ -86,4 +86,37 @@ class SummaryDb(db: Database) {
.map(_.headOption.flatten.map(ConfigUtils.jsonTextToMap))
}
def createPipeline(name: String, runId: Int): Future[Int] = {
val id = Await.result(db.run(pipelines.size.result), Duration.Inf)
db.run(pipelines.forceInsert(Pipeline(id, name, runId))).map(_ => id)
}
def getPipelines(pipelineId: Option[Int] = None, name: Option[String] = None, runId: Option[Int] = None) = {
val q = pipelines.filter { lib =>
List(
pipelineId.map(lib.id === _),
runId.map(lib.runId === _),
name.map(lib.name === _) // not a condition as `criteriaRoast` evaluates to `None`
).collect({ case Some(criteria) => criteria }).reduceLeftOption(_ && _).getOrElse(true: Rep[Boolean])
}
db.run(q.map(x => (x.id, x.name, x.runId)).result)
}
def createModule(name: String, runId: Int, pipelineId: Int): Future[Int] = {
val id = Await.result(db.run(modules.size.result), Duration.Inf)
db.run(modules.forceInsert(Module(id, name, runId, pipelineId))).map(_ => id)
}
def getModules(moduleId: Option[Int] = None, name: Option[String] = None, runId: Option[Int] = None, pipelineId: Option[Int] = None) = {
val q = modules.filter { lib =>
List(
moduleId.map(lib.id === _),
runId.map(lib.runId === _),
pipelineId.map(lib.pipelineId === _),
name.map(lib.name === _) // not a condition as `criteriaRoast` evaluates to `None`
).collect({ case Some(criteria) => criteria }).reduceLeftOption(_ && _).getOrElse(true: Rep[Boolean])
}
db.run(q.map(x => (x.id, x.name, x.runId)).result)
}
}
......@@ -7,95 +7,100 @@ import slick.driver.H2Driver.api._
*/
object Schema {
class Runs(tag: Tag) extends Table[(Int, String, String)](tag, "Runs") {
case class Run(id: Int, name: String, outputDir: String)
class Runs(tag: Tag) extends Table[Run](tag, "Runs") {
def id = column[Int]("id", O.PrimaryKey)
def runName = column[String]("runName")
def outputDir = column[String]("outputDir")
def * = (id, runName, outputDir)
def * = (id, runName, outputDir) <> (Run.tupled, Run.unapply)
}
val runs = TableQuery[Runs]
class Samples(tag: Tag) extends Table[(Int, String, Int, Option[String])](tag, "Samples") {
case class Sample(id: Int, name: String, runId: Int, tags: Option[String])
class Samples(tag: Tag) extends Table[Sample](tag, "Samples") {
def id = column[Int]("id", O.PrimaryKey)
def name = column[String]("name")
def runId = column[Int]("runId")
def tags = column[Option[String]]("tags")
def * = (id, name, runId, tags)
def * = (id, name, runId, tags) <> (Sample.tupled, Sample.unapply)
def idx = index("idx_samples", (runId, name), unique = true)
}
val samples = TableQuery[Samples]
class Libraries(tag: Tag) extends Table[(Int, String, Int, Int, Option[String])](tag, "Libraries") {
case class Library(id: Int, name: String, runId: Int, sampleId: Int, tags: Option[String])
class Libraries(tag: Tag) extends Table[Library](tag, "Libraries") {
def id = column[Int]("id", O.PrimaryKey)
def name = column[String]("name")
def runId = column[Int]("runId")
def sampleId = column[Int]("sampleId")
def tags = column[Option[String]]("tags")
def * = (id, name, runId, sampleId, tags)
def * = (id, name, runId, sampleId, tags) <> (Library.tupled, Library.unapply)
def idx = index("idx_libraries", (runId, sampleId, name), unique = true)
}
val libraries = TableQuery[Libraries]
class PipelineNames(tag: Tag) extends Table[(Int, String, Int)](tag, "PipelineNames") {
case class Pipeline(id: Int, name: String, runId: Int)
class Pipelines(tag: Tag) extends Table[Pipeline](tag, "PipelineNames") {
def id = column[Int]("id", O.PrimaryKey)
def name = column[String]("name")
def runId = column[Int]("runId")
def * = (id, name, runId)
def * = (id, name, runId) <> (Pipeline.tupled, Pipeline.unapply)
def idx = index("idx_pipeline_names", (name, runId), unique = true)
}
val pipelineNames = TableQuery[PipelineNames]
val pipelines = TableQuery[Pipelines]
class ModuleNames(tag: Tag) extends Table[(Int, String, Int, Int)](tag, "ModuleNames") {
case class Module(id: Int, name: String, runId: Int, pipelineId: Int)
class Modules(tag: Tag) extends Table[Module](tag, "ModuleNames") {
def id = column[Int]("id", O.PrimaryKey)
def name = column[String]("name")
def runId = column[Int]("runId")
def pipelineId = column[Int]("pipelineId")
def * = (id, name, runId, pipelineId)
def * = (id, name, runId, pipelineId) <> (Module.tupled, Module.unapply)
def idx = index("idx_module_names", (name, runId, pipelineId), unique = true)
}
val moduleNames = TableQuery[ModuleNames]
val modules = TableQuery[Modules]
class Stats(tag: Tag) extends Table[(Int, Int, Option[Int], Option[Int], Option[Int], String, Option[String])](tag, "Stats") {
case class Stat(runId: Int, pipelineId: Int, moduleId: Option[Int], sampleId: Option[Int], library: Option[Int], content: String)
class Stats(tag: Tag) extends Table[Stat](tag, "Stats") {
def runId = column[Int]("runId")
def pipelineId = column[Int]("pipelineId")
def moduleId = column[Option[Int]]("moduleId")
def sampleId = column[Option[Int]]("sampleId")
def libraryId = column[Option[Int]]("libraryId")
def stats = column[String]("stats")
def schema = column[Option[String]]("schema")
def content = column[String]("content")
def * = (runId, pipelineId, moduleId, sampleId, libraryId, stats, schema)
def * = (runId, pipelineId, moduleId, sampleId, libraryId, content) <> (Stat.tupled, Stat.unapply)
def idx = index("idx_stats", (runId, pipelineId, moduleId, sampleId, libraryId), unique = true)
}
val stats = TableQuery[Stats]
class Settings(tag: Tag) extends Table[(Int, Int, Option[Int], Option[Int], Option[Int], String, Option[String])](tag, "Settings") {
case class Setting(runId: Int, pipelineId: Int, moduleId: Option[Int], sampleId: Option[Int], library: Option[Int], content: String)
class Settings(tag: Tag) extends Table[Setting](tag, "Settings") {
def runId = column[Int]("runId")
def pipelineId = column[Int]("pipelineId")
def moduleId = column[Option[Int]]("moduleId")
def sampleId = column[Option[Int]]("sampleId")
def libraryId = column[Option[Int]]("libraryId")
def stats = column[String]("stats")
def schema = column[Option[String]]("schema")
def content = column[String]("content")
def * = (runId, pipelineId, moduleId, sampleId, libraryId, stats, schema)
def * = (runId, pipelineId, moduleId, sampleId, libraryId, content) <> (Setting.tupled, Setting.unapply)
def idx = index("idx_settings", (runId, pipelineId, moduleId, sampleId, libraryId), unique = true)
}
val settings = TableQuery[Settings]
class Files(tag: Tag) extends Table[(Int, Int, Option[Int], Option[Int], Option[Int], String, String, String, Boolean, Long)](tag, "Files") {
case class File(runId: Int, pipelineId: Int, moduleId: Option[Int], sampleId: Option[Int], library: Option[Int], name: String, path: String, md5: String, link: Boolean, size: Long)
class Files(tag: Tag) extends Table[File](tag, "Files") {
def runId = column[Int]("runId")
def pipelineId = column[Int]("pipelineId")
def moduleId = column[Option[Int]]("moduleId")
......@@ -107,13 +112,14 @@ object Schema {
def link = column[Boolean]("link", O.Default(false))
def size = column[Long]("size")
def * = (runId, pipelineId, moduleId, sampleId, libraryId, name, path, md5, link, size)
def * = (runId, pipelineId, moduleId, sampleId, libraryId, name, path, md5, link, size) <> (File.tupled, File.unapply)
def idx = index("idx_files", (runId, pipelineId, sampleId, libraryId, name), unique = true)
}
val files = TableQuery[Files]
class Executables(tag: Tag) extends Table[(Int, String, Option[String], Option[String], Option[String], Option[String])](tag, "Executables") {
case class Executable(runId: Int, toolName: String, version : Option[String], javaVersion: Option[String], exeMd5: Option[String], javaMd5: Option[String])
class Executables(tag: Tag) extends Table[Executable](tag, "Executables") {
def runId = column[Int]("runId")
def toolName = column[String]("toolName")
def version = column[Option[String]]("version")
......@@ -121,7 +127,7 @@ object Schema {
def exeMd5 = column[Option[String]]("exeMd5")
def javaMd5 = column[Option[String]]("javaMd5")
def * = (runId, toolName, version, javaVersion, exeMd5, javaMd5)
def * = (runId, toolName, version, javaVersion, exeMd5, javaMd5) <> (Executable.tupled, Executable.unapply)
def idx = index("idx_executables", (runId, toolName), unique = true)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment