This gist has been upgraded to a blog post here.
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
/** | |
* Created by pedrofurla on 26/03/14. | |
*/ | |
package slicks.docs | |
import slicks.docs.dao.{Entity, IdentifiableTable, CrudComponent, Profile} | |
case class User(id: Option[Long], first: String, last: String) extends Entity[Long] | |
trait UserComponent extends CrudComponent { outer: Profile => |
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
import scala.slick.lifted.CanBeQueryCondition | |
// optionally filter on a column with a supplied predicate | |
case class MaybeFilter[X, Y](val query: scala.slick.lifted.Query[X, Y]) { | |
def filter[T,R:CanBeQueryCondition](data: Option[T])(f: T => X => R) = { | |
data.map(v => MaybeFilter(query.filter(f(v)))).getOrElse(this) | |
} | |
} | |
// example use case | |
import java.sql.Date |
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
app = angular.module 'BlogExample', [] | |
# Simple controller that loads all blog posts | |
app.controller 'BlogCtrl', ['$scope', 'Blog', ($scope, Blog) -> | |
# Get all the blog posts | |
Blog.all().then (posts) -> | |
$scope.posts = posts | |
# Extend the $scope with our own properties, all in one big block | |
# I like this because it looks like declaring a class. |
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
import com.typesafe.config.ConfigFactory | |
import sbt._ | |
import Keys._ | |
import play.Project._ | |
object ApplicationBuild extends Build { | |
val conf = ConfigFactory.parseFile(new File("conf/application.conf")).resolve() | |
val appVersion = conf.getString("application.version") |
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
import scala.slick.driver.JdbcProfile | |
import scala.slick.ast.BaseTypedType | |
trait Profile { | |
val profile: JdbcProfile | |
} | |
trait TableComponent extends Profile { | |
import profile.simple._ | |
trait TypedId{ def id:Long } | |
trait Entity[ID]{ | |
def id : Option[ID] |
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
define (require) -> | |
$ = require 'jquery' | |
_ = require 'underscore' | |
Backbone = require 'backbone' | |
Handlebars = require 'handlebars' | |
View = require 'lib/view' | |
startTemplate = require 'text!templates/start.html' | |
class StartView extends View |
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
// app/controllers/Application.scala | |
trait SubdomainController extends Controller { | |
def WithSubdomain(f: => String => Request[AnyContent] => Result) = Action { implicit request => | |
val splitDomain = request.domain.split("\\.") | |
if (splitDomain.length < 2) { | |
BadRequest("Domain not found!") | |
} else { | |
f(splitDomain.head)(request) |
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
# --- !Ups | |
CREATE TABLE users( | |
email VARCHAR(255) NOT NULL PRIMARY KEY, | |
name VARCHAR(255) | |
); | |
CREATE TABLE subjects( | |
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, | |
title LONGTEXT NOT NULL, |
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
package com.benmccann.example.schema; | |
import java.io.ByteArrayOutputStream; | |
import java.io.File; | |
import java.io.IOException; | |
import java.io.PrintStream; | |
import java.io.PrintWriter; | |
import java.io.Writer; | |
import java.net.URL; | |
import java.util.Arrays; |
NewerOlder