2016-06-23 2 views
0

Ich versuche, eine Liste von Bereichen von Zeitstempeln in der "verfügbaren" Spalte einer PostgreSQL-Tabelle zu speichern. Ich benutze slick-pg, um zu helfen. Für die Datentabelle Ich habe:Speichern eines Bereichs von Zeitstempeln in postgresql mit PlaySlick und slick-pg

create table users (
    id text NOT NULL PRIMARY KEY, 
    action text NOT NULL, 
    scheduled timestamptz, 
    available tstzrange[] 
); 

In meinem DAO ich habe:

private class UsersTable(tag: Tag) extends Table[User](tag, "users") { 

    def id = column[String]("id", O.PrimaryKey) 
    def action = column[String]("action") 
    def timestamp = column[Option[Timestamp]]("scheduled") 
    def available = column[Option[List[com.github.tminglei.slickpg.Range[Timestamp]]]]("available") 

    def * = (id, action, timestamp, available) <> (User.tupled, User.unapply _) 
} 

und eine zugehörige Fallklasse für die Tabelle:

case class User(id: String, action: String, timestamp: Option[Timestamp] = None, available:Option[List[com.github.tminglei.slickpg.Range[Timestamp]]] = None) 

Ich weiß, ich bin fehlt ein implizit, etwas ähnliches wie die implicits in diesem example file. Aber ich bin immer noch neu in Scala und habe genau darauf geachtet, wie ich es definiere.

Antwort

0

In der Klasse einige DAO-Zugriffe tun, injizieren DatabaseConfigProvider wie folgt aus:

class Class @Inject() (protected val dbConfigProvider: DatabaseConfigProvider) 

und es extends HasDatabaseConfigProvider[MyPostgresDriver] machen.

Sie müssen importieren: (Datenbank ist der Name des Pakets, wo ist die MyPostgresDriver Datei)

import database.MyPostgresDriver.api._ 
import database.MyPostgresDriver 
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider} 

Hier ist die MyPostgresDriver Datei:

package database 

import com.github.tminglei.slickpg._ 

trait MyPostgresDriver extends ExPostgresDriver 
    with PgArraySupport 
    with PgDate2Support 
    with PgPlayJsonSupport 
    with PgNetSupport 
    with PgLTreeSupport 
    with PgRangeSupport 
    with PgHStoreSupport 
    with PgSearchSupport 
    with PgPostGISSupport { 

    override val pgjson = "jsonb" 
    override lazy val Implicit = new ImplicitsPlus {} 
    override val simple = new SimpleQLPlus {} 

    trait ImplicitsPlus extends Implicits 
    with ArrayImplicits 
    with DateTimeImplicits 
    with RangeImplicits 
    with HStoreImplicits 
    with JsonImplicits 
    with SearchImplicits 
    with PostGISImplicits 

    trait SimpleQLPlus extends SimpleQL 
    with ImplicitsPlus 
    with SearchAssistants 
    with PostGISAssistants 

    override val api = new API with ArrayImplicits 
    with DateTimeImplicits 
    with PlayJsonImplicits 
    with NetImplicits 
    with LTreeImplicits 
    with RangeImplicits 
    with HStoreImplicits 
    with SearchImplicits 
    with PostGISImplicits 
    with SearchAssistants {} 
} 

object MyPostgresDriver extends MyPostgresDriver 

(Wählen Sie nur die benötigten implicits) .

Verwandte Themen