andriimartynov / zio-jasync-sql

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

zio-jasync-sql

Download Build Status Apache License V.2

Scala wrapper for jasync-sql a Simple, Netty based, asynchronous, performant and reliable database drivers for PostgreSQL and MySQL.

Getting zio-jasync-sql

To resolve artifacts through Artifactory, simply add the following code snippet to your build.sbt file:

resolvers += Resolver.jcenterRepo

The current version is 1.1.2, which is cross-built against Scala 2.11.x, 2.12.x and 2.13.x.

libraryDependencies += "com.github.andriimartynov" %% "zio-jasync-sql" % "1.1.2"

Usage example

// Connection to MySQL DB
val connection = MySQLConnectionBuilder.createConnectionPool(
               "jdbc:mysql://$host:$port/$database?user=$username&password=$password");
     
// Connection to PostgreSQL DB    
val connection = PostgreSQLConnectionBuilder.createConnectionPool(
               "jdbc:postgresql://$host:$port/$database?user=$username&password=$password");

val layer: Layer[Throwable, ConnectionService] =
    ConnectionService.live(connection)

val rio: RIO[ConnectionService, QueryResult] = for {
queryResult <- sendPreparedStatement("select * from test limit 2")
} yield queryResult

val task: Task[QueryResult] = rio.provideLayer(layer)

See a full example at zio-jasync-mysql-example and zio-jasync-postgresql-example.

About

License:Apache License 2.0


Languages

Language:Scala 95.6%Language:Java 4.4%