Getting Started
Installation
Not decided yet, but likely integrated with main stream zio support.
Sample
Here is a simple example of how to use ZIO Magnum in a Scala application:
package demo
import zio.*
import com.augustnagro.magnum.*
import com.augustnagro.magnum.ziomagnum.*
object ZIOMagnumDemo extends zio.ZIOAppDefault:
@Table(PostgresDbType, SqlNameMapper.CamelToSnakeCase)
case class User(@Id id: Int, name: String) derives DbCodec
val repo = Repo[User, User, Int]
// Example of inserting a user into the database
private val program: RIO[DataSource, Unit] = repo.zInsert(User(0, "Alice"))
override def run = program
.provide:
// Provide necessary layers, e.g., database connection, logging, etc.
Scope.default >>> dataSourceLayer(
"jdbc:postgresql://localhost:5432/mydb",
"user",
"password"
)
See more sample in usage.
In this article