absaoss / fa-db   0.1.0

Apache License 2.0 GitHub

Functional Access to Database

Scala versions: 2.12 2.11

fa-db

Functional Access to Database

Build Status

Build

Maven Central


What is fa-db

This library is a less traditional way to facilitate data between an application and an SQL Database.

Traditionally application directly applies SQL queries or use some ORM framework. While the first approach mixes two rather different domain languages within one source, the second too often fails in case of more complicated queries and table relations.


This library offers a different approach.

The idea is that the application transfers data to and from using database stored procedures/functions (from here on referenced in this library as DB functions). This establishes a stable contract between the DB and the application. To emphasize – the data are both read and written to/from DB using DB functions.

The purpose of the library then is to facilitate an easy and natural – meaning Scala style – call of the DB functions within the application.

Benefits:

  • Stable contract between the application and the DB
  • Early locking of the data model
  • Separation of the domains while keeping each part doing what they are good for:
    • the application parsing and utilizing the data
    • the DB storing and retrieving the data effectively
  • Better data security and consistency protection

Currently, the library is developed with Postgres as the target DB. But the approach is applicable to any DB supporting stored procedure/functions – Oracle, MS-SQL, ...

Usage

Sbt

libraryDependencies ++= Seq(
  "za.co.absa.fa-db" %% "core"  % "X.Y.Z",
  "za.co.absa.fa-db" %% "slick" % "X.Y.Z"
)

Maven

Scala 2.11

Modules:

  • Core Maven Central
  • Slick Maven Central
<dependency>
   <groupId>za.co.absa.fa-db</groupId>
   <artifactId>core_2.11</artifactId>
   <version>${latest_version}</version>
</dependency>
<dependency>
<groupId>za.co.absa.fa-db</groupId>
<artifactId>slick_2.11</artifactId>
<version>${latest_version}</version>
</dependency>

Scala 2.12

Modules:

  • Core Maven Central
  • Slick Maven Central
<dependency>
   <groupId>za.co.absa.fa-db</groupId>
   <artifactId>core_2.12</artifactId>
   <version>${latest_version}</version>
</dependency>
<dependency>
    <groupId>za.co.absa.fa-db</groupId>
    <artifactId>slick_2.12</artifactId>
    <version>${latest_version}</version>
</dependency>

How to generate Code coverage report

sbt jacoco

Code coverage will be generated on path:

{project-root}/fa-db/{module}/target/scala-{scala_version}/jacoco/report/html