Last active
December 15, 2015 20:29
-
-
Save jg/5318441 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object TypeSerializers { | |
implicit object LongPropertySerializer extends PropertySerializer[Long] { | |
def sqlType = "long" | |
} | |
implicit object StringPropertySerializer extends PropertySerializer[String] { | |
def sqlType = "string" | |
} | |
} | |
trait TaskProperties { | |
import TypeSerializers._ | |
var id: Property[Long] = Property("id", None) | |
var title: Property[String] = Property("title", None) | |
val properties = List(id, title) | |
def toSQL() = { | |
properties.map((p: Property[_]) => | |
p.name + " " + Property.sqlType(p)).mkString(", ") + ", FOREIGN KEY(task_list_id) REFERENCES task_list(id)" | |
} | |
} | |
object Property { | |
def apply[T](name: String, value: Option[T]) = new Property(name, value) | |
def sqlType[T](p: Property[T])(implicit propertySerializer: PropertySerializer[T]): String = | |
propertySerializer.sqlType | |
} | |
class Property[T](val name: String, var value: Option[T]) | |
[error] Task.scala:28: could not find implicit value for parameter propertySerializer: com.android.todoapp.PropertySerializer[_$1] | |
[error] p.name + " " + Property.sqlType(p)).mkString(", ") + ", FOREIGN KEY(task_list_id) REFERENCES task_list(id)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment