refined-anorm


License

License

Categories

Categories

ORM Data
GroupId

GroupId

com.github.derekmorr
ArtifactId

ArtifactId

refined-anorm_2.11
Last Version

Last Version

0.1
Release Date

Release Date

Type

Type

jar
Description

Description

refined-anorm
refined-anorm
Project URL

Project URL

https://github.com/derekmorr/refined-anorm/
Project Organization

Project Organization

com.github.derekmorr
Source Code Management

Source Code Management

http://github.com/derekmorr/refined-anorm/tree/master

Download refined-anorm_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.derekmorr/refined-anorm_2.11/ -->
<dependency>
    <groupId>com.github.derekmorr</groupId>
    <artifactId>refined-anorm_2.11</artifactId>
    <version>0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.derekmorr/refined-anorm_2.11/
implementation 'com.github.derekmorr:refined-anorm_2.11:0.1'
// https://jarcasting.com/artifacts/com.github.derekmorr/refined-anorm_2.11/
implementation ("com.github.derekmorr:refined-anorm_2.11:0.1")
'com.github.derekmorr:refined-anorm_2.11:jar:0.1'
<dependency org="com.github.derekmorr" name="refined-anorm_2.11" rev="0.1">
  <artifact name="refined-anorm_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.derekmorr', module='refined-anorm_2.11', version='0.1')
)
libraryDependencies += "com.github.derekmorr" % "refined-anorm_2.11" % "0.1"
[com.github.derekmorr/refined-anorm_2.11 "0.1"]

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.11
com.typesafe.play : anorm_2.11 jar 2.5.3
eu.timepit : refined_2.11 jar 0.8.0

test (7)

Group / Artifact Type Version
org.eu.acolyte : jdbc-scala_2.11 jar 1.0.43-j7p
org.scalacheck : scalacheck_2.11 jar 1.13.5
org.scalatest : scalatest_2.11 jar 3.0.1
org.pegdown : pegdown jar 1.6.0
com.typesafe : config jar 1.3.1
com.zaxxer : HikariCP jar 2.4.1
org.postgresql : postgresql jar 42.0.0

Project Modules

There are no modules declared in this project.

Refined Anorm

Adds support for Refinement types to the Anorm database access layer for Scala.

Build Status

Installation

Add the following to your build.sbt:

libraryDependencies += "com.github.derekmorr" %% "refined-anorm" % "0.1"

refined-anorm is available for Scala 2.11 and 2.12 for Anorm 2.5.

Usage

Add the following to Anorm models:

import refined.anorm._

Then you'll be able to serialize and deserialize refined types with JDBC.

For example:

/** 802.1Q Vlan ID */
type VlanId = Int Refined Interval.Closed[W.`0`.T, W.`4095`.T]

type NonBlankString = String Refined And[NonEmpty, Exists[Not[Whitespace]]]

case class Vlan(id: VlanId, name: NonBlankString)

object Vlan {
   import refined.anorm._
   val parser: RowParser[Vlan] = Macro.namedParser[Vlan]
  
  def getById(id: VlanId)(implicit connection: Connection): Option[Vlan] = {
    SQL"""SELECT id, name FROM vlans WHERE id = $id""".as(Vlan.parser.singleOpt)
  }
 
  def create(vlan: Vlan)(implicit connection: Connection): Boolean = {
    SQL"""INSERT INTO vlans (id, name) VALUES (${vlan.id}, ${vlan.name})""".executeUpdate() == 1
  }
}

There is a complete, working example in the integration tests (in src/it).

Testing the app

To run unit tests, run

sbt test

To run the integration tests:

  1. Install a database (PostgreSQL is the default).
  2. Create a database named refinement. Grant a user read/write and create table access to it.
  3. Edit src/it/resources/application.conf:
  4. Edit the username and password fields
  5. Adjust the database URL if necessary.
  6. Run sbt it:test

Code coverage report

To generate a code coverage report run,

sbt clean coverage test coverageReport

The HTML report will be written to target/scala-2.12/scoverage-report/index.html.

Code quality analysis

The project uses the scapegoat tool for code quality analysis. Run run a scapegoat report, run

sbt scapegoat

The HTML report will be written to target/scala-2.12/scapegoat-report/scapegoat.html

Versions

Version
0.1