8000 GitHub - karimagnusson/kuzminki-zio at Latest · GitHub
[go: up one dir, main page]

Skip to content

About

Kuzminki is feature-rich query builder and access library for PostgreSQL written in Scala.

Resources

Stars

28 stars

Watchers

2 watching

Forks

Latest commit

 

History

66 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

license Gitter

kuzminki-zio

Kuzminki is query builder and access library for PostgreSQL written in Scala.
This version is for ZIO 1.

Kuzminki is written for those who like SQL. Queries are written with the same logic you write SQL statements. As a result the code is easy to read and memorise while the resulting SQL statement is predictable.

This library is also available for ZIO 2 kuzminki-zio-2

See full documentation at https://kuzminki.io/

You can take a look at kuzminki-zhttp-demo for a example of a REST API using this library and zio-http

Release 0.9.4-RC2 adds the following features:

  • Support for jsonb field
  • Support for uuid field
  • Streaming from and to the database
  • Support for transactions
  • Ability to use postgres functions
  • Improved ability to cache statements

Attention! There are some changes to the API in this version. They affect INSERT, UPDATE and DELETE.

Sbt

libraryDependencies += "io.github.karimagnusson" % "kuzminki-zio" % "0.9.4-RC2"

Example

import zio._
import kuzminki.api._

object ExampleApp extends zio.App {

  class Client extends Model("client") {
    val id = column[Int]("id")
    val username = column[String]("username")
    val age = column[Int]("age")
    def all = (id, username, age)
  }

  val client = Model.get[Client]

  val job = for {
    _ <- sql
      .insert(client)
      .cols2(t => (t.username, t.age))
      .values(("Joe", 35))
      .run
    
    _ <- sql
      .update(client)
      .set(_.age ==> 24)
      .where(_.id === 4)
      .run
    
    _ <- sql.delete(client).where(_.id === 7).run
    
    clients <- sql
      .select(client)
      .cols3(_.all)
      .where(_.age > 25)
      .run
    
    _ <- ZIO.foreach(clients) {
      case (id, username, age) =>
        putStrLn(s"$id $username $age")
    }
  } yield ()

  val dbLayer = Kuzminki.layer(DbConfig.forDb("company"))

  override def run(args: List[String]): ZIO[ZEnv, Nothing, ExitCode] = {
    job.provideCustomLayer(dbLayer).exitCode
  }
}

About

Kuzminki is feature-rich query builder and access library for PostgreSQL written in Scala.

Resources

Stars

28 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages

0