Skip to content

Instantly share code, notes, and snippets.

@jakob85
Created June 23, 2015 17:20
Show Gist options
  • Save jakob85/7aa7789f404e90172279 to your computer and use it in GitHub Desktop.
Save jakob85/7aa7789f404e90172279 to your computer and use it in GitHub Desktop.
case class SearchCategory(
id: Option[Long],
created: DateTime,
modified: DateTime,
name: Option[String] = None
) {
}
object SearchCategory extends SQLSyntaxSupport[SearchCategory] {
override val columnNames = Seq("id", "created", "modified", "name")
override val tableName = "SearchCategory"
override val useSnakeCaseColumnName = false
//override val connectionPoolName = 'postgres
lazy val sc = SearchCategory.syntax
def db(sc: SyntaxProvider[SearchCategory])(rs: WrappedResultSet): SearchCategory = db(sc.resultName)(rs)
def db(sc: ResultName[SearchCategory])(rs: WrappedResultSet): SearchCategory = SearchCategory(
rs.longOpt(sc.id),
rs.jodaDateTime(sc.created),
rs.jodaDateTime(sc.modified),
rs.stringOpt(sc.name)
)
def apply(sc: ResultName[SearchCategory])(rs: WrappedResultSet): SearchCategory =
new SearchCategory(
id = rs.longOpt(sc.id),
created = rs.jodaDateTime(sc.created),
modified = rs.jodaDateTime(sc.modified),
name = rs.stringOpt(sc.name)
)
def findAll() : Future[List[SearchCategory]] = AsyncDB.withPool { implicit s =>
withSQL(select.from[SearchCategory](SearchCategory as sc)).map(SearchCategory.db(sc))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment