<commit_before>jdub
====

*A damn simple JDBC wrapper. Y'know. For databases.*


Requirements
------------

* Java SE 6
* Scala 2.9.2

How To Use
----------

**First**, specify Jdub as a dependency:

```xml
<dependencies>
  <dependency>
    <groupId>com.simple</groupId>
    <artifactId>jdub_${scala.version}</artifactId>
    <version>0.1.0</version>
  </dependency>
</dependencies>
```

(Don't forget to include your JDBC driver!)

**Second**, connect to a database:

```scala
val db = Database.connect("jdbc:postgresql://localhost/wait_what", "myaccount", "mypassword")
```

**Third**, run some queries:

```scala
// Query returning a single result.
case class GetAge(name: String) extends FlatSingleRowQuery[Int] {

  val sql = trim("""
      SELECT age
      FROM people
      WHERE name = ?
      """)

  val values = name :: Nil

  def flatMap(row: Row) = {
    row.int(0) // returns Option[Int]
  }

}

println(db(GetAge("Old Guy")).getOrElse("Name not found!")) // 402
```

```scala
// Query returning a Person object for each row.
case object GetPeople extends CollectionQuery[Seq, Person] {

  val sql = trim("""
      SELECT name, email, age
      FROM people
      """)

  val values = Nil

  def map(row: Row) = {
    val name = row.string("name").get
    val email = row.string("email").getOrElse("")
    val age = row.int("age").get
    Person(name, email, age)
  }

}

println(db(GetPeople).head) // Person(<NAME>,<EMAIL>,29)
```


**Fourth**, execute some statements:

```scala
case class UpdateEmail(name: String, newEmail: String) extends Statement {
  val sql = trim("""
      UPDATE people
      SET email = ?
      WHERE name = ?
      """)
  val values = newEmail :: name :: Nil
}

// Execute the statement.
db.execute(UpdateEmail("<NAME>", "<EMAIL>"))

// Or return the number of rows updated.
val count = db.update(UpdateEmail("<NAME>", "<EMAIL>"))
println(count) // 1
```

**Fifth**, read up on all the details in the [Jdub tour](tour.md).

License
-------

Copyright (c) 2011-2012 <NAME>
Copyright (c) 2012-2013 Simple Finance Technology Corp. All rights reserved.

Published under The MIT License, see LICENSE.md<commit_msg>Bring README in line with DatabaseSpec.<commit_after>jdub
====

*A damn simple JDBC wrapper. Y'know. For databases.*


Requirements
------------

* Java SE 6 or above
* Scala 2.9.2

How To Use
----------

**First**, specify Jdub as a dependency:

```xml
<dependencies>
  <dependency>
    <groupId>com.simple</groupId>
    <artifactId>jdub_${scala.version}</artifactId>
    <version>0.1.0</version>
  </dependency>
</dependencies>
```

(Don't forget to include your JDBC driver!)

**Second**, connect to a database:

```scala
val db = Database.connect("jdbc:postgresql://localhost/wait_what", "myaccount", "mypassword")
```

**Third**, run some queries:

```scala
// Query returning a single result.
case class GetAge(name: String) extends FlatSingleRowQuery[Int] {

  val sql = trim("""
      SELECT age
      FROM people
      WHERE name = ?
      """)

  val values = name :: Nil

  def flatMap(row: Row) = {
    row.int(0) // returns Option[Int]
  }

}

println(db(GetAge("Old Guy")).getOrElse("Name not found!")) // 402
```

```scala
// Query returning a Person object for each row.
case object GetPeople extends CollectionQuery[Seq, Person] {

  val sql = trim("""
      SELECT name, email, age
      FROM people
      """)

  val values = Nil

  def map(row: Row) = {
    val name = row.string("name").get
    val email = row.string("email").getOrElse("")
    val age = row.int("age").getOrElse(0)
    Person(name, email, age)
  }

}

val person = db(GetPeople).head // Person(<NAME>,<EMAIL>,29)
```


**Fourth**, execute some statements:

```scala
case class UpdateEmail(name: String, newEmail: String) extends Statement {
  val sql = trim("""
      UPDATE people
      SET email = ?
      WHERE name = ?
      """)
  val values = newEmail :: name :: Nil
}

// Execute the statement.
db.execute(UpdateEmail("Old Guy", "<EMAIL>"))

// Or return the number of rows updated.
val count = db.update(UpdateEmail("Old Guy", "<EMAIL>")) // 1
```

**Fifth**, read up on all the details in the [Jdub tour](tour.md).

License
-------

Copyright (c) 2011-2012 <NAME>
Copyright (c) 2012-2013 Simple Finance Technology Corp. All rights reserved.

Published under The MIT License, see LICENSE.md
{'fraction_non_alphanumeric': 0.16639778750864254, 'fraction_numerical': 0.01405853883383268, 'mean_word_length': 3.2507345739471107, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 2, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1578013', 'n_tokens_mistral': 1526, 'n_tokens_neox': 1361, 'n_words': 433}