Skip to content

Instantly share code, notes, and snippets.

@timowest
Created November 30, 2011 22:05
Show Gist options
  • Save timowest/1411235 to your computer and use it in GitHub Desktop.
Save timowest/1411235 to your computer and use it in GitHub Desktop.
Querydsl Scala syntax
// DEFAULT AND COMPACT SYNTAX COMPARED
// for each example the default and compact syntax are shown
// select single
query.from(survey).select(survey.id) // default
survey.select(_.id) // compact
// select single 2
query.from(employee).select(employee.firstname)
employee.select(_.firstname)
// select two
query.from(survey).select(survey.id, survey.name)
survey.select(_.id, _.name)
// select more
query.from(survey).select(survey.id, survey.name, survey.name.substring(0,1))
survey.select(_.id, _.name, _.name.substring(0,1))
// select more 2
query.from(survey).select(survey.id, survey.name, survey.name + "X", survey.name + "Y")
survey.select(_.id, _.name, _.name + "X", _.name + "Y")
// count
query.from(survey).count
survey.query.count
// count 2
query.from(employee).count
employee.query.count
// join
query.from(employee).join(employee.superiorFk, sup).select(employee, sup)
employee.join(_.superiorFk, sup).select
// unique
query.from(survey).where(survey.id eq 1).unique(survey.name)
query.from(survey).where(survey.id eq 2).unique(survey.name)
query.from(employee).where(employee.lastname eq "Smith").unique(employee.firstname)
query.from(employee).where(employee.lastname eq "Doe").unique(employee.firstname)
survey.where(_.id eq 1).unique(_.name)
survey.where(_.id eq 2).unique(_.name)
employee.where(_.lastname eq "Smith").unique(_.firstname)
employee.where(_.lastname eq "Doe").unique(_.firstname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment