Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 09cff57678dee4a72366a4b8c35928fc1ddbb134 0 parents
@pbrant authored
5 .gitignore
@@ -0,0 +1,5 @@
+.idea
+lib_managed
+minimalexample.iml
+target
+
2  project/.gitignore
@@ -0,0 +1,2 @@
+boot
+project.iml
9 project/build.properties
@@ -0,0 +1,9 @@
+#
+#Tue May 03 19:30:41 CEST 2011
+project.organization=org.squeryl
+project.name=minimalexample
+sbt.version=0.7.7
+project.version=0.1-SNAPSHOT
+build.scala.versions=2.7.7
+project.initialize=false
+build.scala.versions=2.8.1
6 project/build/ExampleProject.scala
@@ -0,0 +1,6 @@
+import sbt._
+
+class ExampleProject(info: ProjectInfo) extends DefaultProject(info) with IdeaProject {
+ val squeryl = "org.squeryl" %% "squeryl" % "0.9.4" % "compile" withSources()
+ val h2 = "com.h2database" % "h2" % "1.2.127" withSources()
+}
2  project/plugins/.gitignore
@@ -0,0 +1,2 @@
+project
+src_managed
5 project/plugins/Plugins.scala
@@ -0,0 +1,5 @@
+import sbt._
+class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
+ val sbtIdeaRepo = "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"
+ val sbtIdea = "com.github.mpeltonen" % "sbt-idea-plugin" % "0.4.0"
+}
56 src/main/scala/code/Main.scala
@@ -0,0 +1,56 @@
+package code
+
+import org.squeryl._
+import adapters.H2Adapter
+import PrimitiveTypeMode._
+
+object Main {
+ def main(args: Array[String]) {
+ Class.forName("org.h2.Driver");
+ SessionFactory.concreteFactory = Some(()=>
+ Session.create(
+ java.sql.DriverManager.getConnection("jdbc:h2:~/example", "sa", ""),
+ new H2Adapter)
+ )
+
+ inTransaction {
+ import Library._
+
+ drop // Bad idea in production application!!!!
+ create
+ printDdl
+
+ authors.insert(new Author(1, "JRR", "Tolkien", None))
+ authors.insert(new Author(2, "Jane", "Austen", None))
+ authors.insert(new Author(3, "Philip", "Pullman", None))
+
+ books.insert(new Book(1, "The Lord of the Rings", 1, None))
+ books.insert(new Book(2, "Pride and Prejudice", 2, None))
+ books.insert(new Book(3, "His Dark Materials", 3, None))
+
+ val q = join(books, authors)((b, a) =>
+ select(b, a)
+ on(b.authorId === a.id)
+ )
+
+ for ((book, author) <- q) {
+ println(author.firstName + " " + author.lastName + " wrote " + book.title)
+ }
+ }
+ }
+}
+
+class Author(val id: Long,
+ val firstName: String,
+ val lastName: String,
+ val email: Option[String]) extends KeyedEntity[Long]
+
+class Book(val id: Long,
+ val title: String,
+ val authorId: Long,
+ val coAuthorId: Option[Long]) extends KeyedEntity[Long]
+
+object Library extends Schema {
+ val authors = table[Author]
+ val books = table[Book]
+}
Please sign in to comment.
Something went wrong with that request. Please try again.