|
1 | 1 | # roc |
| 2 | +[]() |
2 | 3 | [](https://circleci.com/gh/penland365/roc/tree/master) |
| 4 | +[](https://codecov.io/github/penland365/roc?branch=master) |
| 5 | + |
| 6 | +roc is a modern [Finagle][finagle] [Postgresql][postgresql] [Client][finagle-client]. What's modern? A Client relying on a [6.x +][finagle-changelog] version of Finagle. |
| 7 | + |
| 8 | +roc is currently under heavy development and is not being published with a current version of `0.0.1-ALPHA`. |
| 9 | +If you need a real driver right now you should absolutely use [finagle-postgres][finagle-postgresql-existing]. |
| 10 | + |
| 11 | +## tl;dr |
| 12 | +roc is not being published yet. You'll have to clone/fork this repository, then build locally. |
| 13 | + |
| 14 | +Once built, open `sbt console` and insert the following |
| 15 | +```scala |
| 16 | +scala > :paste |
| 17 | +import com.twitter.util.Await |
| 18 | +import com.github.finagle.roc.Postgresql |
| 19 | +import com.github.finagle.roc.postgresql.{Request, Row} |
| 20 | + |
| 21 | +val client = Postgresql.client |
| 22 | + .withCredentials([USER_NAME], Some([DATABASE])) |
| 23 | + .withPassword([PASSWORD]) |
| 24 | + .newRichClient("localhost:5432") |
| 25 | +val req = new Request("SELECT * FROM states;") |
| 26 | +val result = Await.result(client.query(req)) |
| 27 | +``` |
| 28 | +A result contains two types, a list of columns detailing information about |
| 29 | +the result, and a list of rows returned from the database. |
| 30 | +```scala |
| 31 | +scala> result.columns |
| 32 | + |
| 33 | +res1: List[com.github.finagle.roc.postgresql.Column] = |
| 34 | + List(Column(name='id, columnType=Int4, formatCode=Text), |
| 35 | + Column(name='name, columnType=VarChar, formatCode=Text), Column(name='abbrv, columnType=VarChar, formatCode=Text), Column(name='last_modified_at, columnType=TimestampWithTimezone, formatCode=Text), |
| 36 | + Column(name='inserted_at, columnType=TimestampWithTimezone, formatCode=Text) |
| 37 | + ) |
| 38 | + |
| 39 | +scala> :paste |
| 40 | + |
| 41 | +val display = (r: Row) => { |
| 42 | + val id = r.get[Int]('id) |
| 43 | + val name = r.get[String]('name) |
| 44 | + val abbrv = r.get[String]('abbrv) |
| 45 | + val insertedAt = r.get[String]('inserted_at) |
| 46 | + val lastModifiedAt = r.get[String]('last_modified_at) |
| 47 | + println(s"Row $id, $name, $abbrv, $insertedAt, $lastModifiedAt") |
| 48 | +} |
| 49 | +// Exiting paste mode, now interpreting. |
| 50 | + |
| 51 | +display: com.github.finagle.roc.postgresql.Row => Unit = <function1> |
| 52 | + |
| 53 | +scala> result.rows.map(display(_)) |
| 54 | +Row 1, North Dakota, ND, 2016-02-18 09:50:55.445246-06, 2016-02-18 09:50:55.445246-06 |
| 55 | +res4: List[Unit] = List(()) |
| 56 | +``` |
| 57 | +At the moment, we can only return `Ints` and `Strings` (I told you it was `ALPHA`). |
| 58 | +The good news is that most `Postgresql` columns can be read as strings first, then transformed into the appropriate type |
| 59 | + ( see the handling of Timestamps With TimeZone above). |
| 60 | + |
| 61 | +## Motivation |
| 62 | +Why create your own when there is an existing implementation? Three reasons |
| 63 | + |
| 64 | +1. The current [finagle-postgres][finagle-postgresql-existing] was developed pre [Finagle 6.x][finagle-changelog] and does not use modern finagle abstractions. These are core enough to require what amounts to a complete rewrite of the driver. |
| 65 | +2. Selfishly, I want to learn more about Finagle internals, and nothing is a better teacher than writing the code yourself. |
| 66 | +3. The current project lacks a true owner - Twitter decided to give the Open Source team a [long vacation][twitter-long-vacation] last fall, and since then only a handful of projects are being actively managed. |
| 67 | + |
| 68 | +It is absolutely the goal of this project to become the reference implementation, and hopefully be moved into the [Finagle ecosystem][finagle-ecosystem]. |
| 69 | + |
| 70 | + |
| 71 | +## What's in a name? |
| 72 | +roc (*Rokh* or *Rukh*) is named after the Persian mythological bird of prey [Roc][roc-wikipedia], |
| 73 | + which was based in part on the now extinct [elephant bird][elephant-bird-wikipedia]. Yes, that means we've hit the rare 4 point play with the name |
| 74 | + |
| 75 | + |
| 76 | + Goal |Status |
| 77 | + :-------------------------------:|:----: |
| 78 | + short name |✔️ |
| 79 | + obligatory mythological reference|✔️ |
| 80 | + bird reference for Twitter |✔️ |
| 81 | + elephant reference for Postgresql|✔️ |
| 82 | + |
| 83 | + High fives for everyone! |
| 84 | +  |
| 85 | + |
| 86 | +## Contributors and Participation |
| 87 | + |
| 88 | +roc is currently maintained by [Jeffrey Davis][jeff-davis]. |
| 89 | + |
| 90 | +The circe project supports the [Typelevel][typelevel] [code of conduct][code-of-conduct] and wants |
| 91 | +all of its channels (GitHub, etc.) to be welcoming environments for everyone. |
3 | 92 |
|
4 | 93 | ## License |
5 | 94 |
|
6 | 95 | Licensed under the **[BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause)** |
7 | 96 | (Revised BSD Liscense); you may not use this software except in compliance with the License. |
8 | 97 |
|
9 | 98 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 99 | + |
| 100 | +[code-of-conduct]: http://typelevel.org/conduct.html |
| 101 | +[elephant-bird-wikipedia]: https://en.wikipedia.org/wiki/Elephant_bird |
| 102 | +[finagle]: http://twitter.github.io/finagle/guide/ |
| 103 | +[finagle-changelog]: http://twitter.github.io/finagle/guide/changelog.html |
| 104 | +[finagle-client]: http://twitter.github.io/finagle/guide/Clients.html |
| 105 | +[finagle-ecosystem]: https://github.com/finagle |
| 106 | +[finagle-postgresql-existing]: https://github.com/finagle/finagle-postgres |
| 107 | +[jeff-davis]: https://twitter.com/penland365 |
| 108 | +[postgresql]: http://www.postgresql.org/ |
| 109 | +[roc-wikipedia]: https://en.wikipedia.org/wiki/Roc_(mythology) |
| 110 | +[twitter-long-vacation]: https://meta.plasm.us/posts/2015/10/13/goodbye-twitter/ |
| 111 | +[typelevel]: http://typelevel.org/ |
0 commit comments