{"id":19502332,"url":"https://github.com/zio-archive/zio-sql","last_synced_at":"2025-09-30T17:30:37.200Z","repository":{"id":37098242,"uuid":"225012224","full_name":"zio/zio-sql","owner":"zio","description":"Type-safe, composable SQL for ZIO applications","archived":false,"fork":false,"pushed_at":"2024-08-20T01:50:11.000Z","size":2981,"stargazers_count":240,"open_issues_count":78,"forks_count":116,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-01-13T07:02:03.730Z","etag":null,"topics":["scala","sql","zio"],"latest_commit_sha":null,"homepage":"https://zio.dev/zio-sql/","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-30T12:54:39.000Z","updated_at":"2024-12-31T23:54:04.000Z","dependencies_parsed_at":"2024-05-05T22:23:32.857Z","dependency_job_id":"537b9cd7-5fd2-4766-8fbc-a9e82cbbff08","html_url":"https://github.com/zio/zio-sql","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zio%2Fzio-sql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zio%2Fzio-sql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zio%2Fzio-sql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zio%2Fzio-sql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zio","download_url":"https://codeload.github.com/zio/zio-sql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234757148,"owners_count":18881936,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["scala","sql","zio"],"created_at":"2024-11-10T22:16:06.144Z","updated_at":"2025-09-30T17:30:31.851Z","avatar_url":"https://github.com/zio.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"[//]: # (This file was autogenerated using `zio-sbt-website` plugin via `sbt generateReadme` command.)\n[//]: # (So please do not edit it manually. Instead, change \"docs/index.md\" file or sbt setting keys)\n[//]: # (e.g. \"readmeDocumentation\" and \"readmeSupport\".)\n\n# ZIO SQL\n\nZIO SQL lets you write type-safe, type-inferred, and composable SQL queries in ordinary Scala, helping you prevent persistence bugs before they happen, and leverage your IDE to make writing SQL productive, safe, and fun.\n\n[![Development](https://img.shields.io/badge/Project%20Stage-Development-green.svg)](https://github.com/zio/zio/wiki/Project-Stages) ![CI Badge](https://github.com/zio/zio-sql/workflows/CI/badge.svg) [![Sonatype Releases](https://img.shields.io/nexus/r/https/oss.sonatype.org/dev.zio/zio-sql_2.13.svg?label=Sonatype%20Release)](https://oss.sonatype.org/content/repositories/releases/dev/zio/zio-sql_2.13/) [![Sonatype Snapshots](https://img.shields.io/nexus/s/https/oss.sonatype.org/dev.zio/zio-sql_2.13.svg?label=Sonatype%20Snapshot)](https://oss.sonatype.org/content/repositories/snapshots/dev/zio/zio-sql_2.13/) [![javadoc](https://javadoc.io/badge2/dev.zio/zio-sql-docs_2.13/javadoc.svg)](https://javadoc.io/doc/dev.zio/zio-sql-docs_2.13) [![ZIO SQL](https://img.shields.io/github/stars/zio/zio-sql?style=social)](https://github.com/zio/zio-sql)\n\n## Introduction\n\n* **Type-safety**. ZIO SQL queries are type-safe by construction. Most classes of bugs can be detected at compile-time, shortening your feedback loop and helping you use your IDE to write correct queries.\n* **Composable**. All ZIO SQL components are ordinary values, which can be transformed and composed in sensible ways. This uniformity and regularity means you have a lot of power in a small package.\n* **Type-inferred**. ZIO SQL uses maximal variance and lower-kinded types, which means it features very good type inference. You can let Scala figure out the types required for type-safe SQL.\n* **No magic**. ZIO SQL does not need any macros or plug-ins to operate (everything is a value!), and it works across both Scala 2.x and Scala 3. Optionally, Scala schema can be created from database schemas.\n\nZIO SQL can be used as a library for modeling SQL in a type-safe ADT. In addition, ZIO SQL has a JDBC interface, which utilizes the type-safe SQL ADT for interacting with common JDBC databases.\n\nFor the JDBC module:\n\n- Like Slick, ZIO SQL has an emphasis on type-safe SQL construction using Scala values and methods. However, ZIO SQL utilizes reified lenses, contravariant intersection types, and in-query nullability to improve ergonomics for end-users. Unlike Slick, the intention is to use names resembling SQL instead of trying to mimic the Scala collections.\n- Like Doobie, ZIO SQL is purely functional, but ZIO SQL does compile-time query validation that catches most issues, and has rich ZIO integration, offering improved type-safety compared to monofunctor effects and minimal dependencies (depending only on ZIO).\n\nZIO SQL does not offer Language Integrated Queries (LINQ) or similar functionality. It is intended only as a data model for representing SQL queries and an accompanying lightweight JDBC-based executor.\n\n## Current status: Non-production release\n\n### Progress report towards 0.1\n\n:heavy_check_mark: - good to go\n\n:white_check_mark: - some more work needed\n\n#### General features:\n\n| Feature          | Progress           |\n|:-----------------|:-------------------|\n| Type-safe schema | :heavy_check_mark: |\n| Type-safe DSL    | :heavy_check_mark: |\n| Running Reads    | :heavy_check_mark: |\n| Running Deletes  | :heavy_check_mark: |\n| Running Updates  | :heavy_check_mark: |\n| Running Inserts  | :heavy_check_mark: |\n| Transactions     | :white_check_mark: |\n| Connection pool  | :white_check_mark: |\n\n#### Db-specific features:\n\n| Feature       | PostgreSQL         | SQL Server         | Oracle             | MySQL              |\n|:--------------|:-------------------|:-------------------|:-------------------|:-------------------|\n| Render Read   | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |\n| Render Delete | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |\n| Render Update | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |\n| Render Insert | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |\n| Functions     | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |\n| Types         | :white_check_mark: |                    |                    | :white_check_mark: |\n| Operators     |                    |                    |                    |                    |\n\n## Installation\n\nZIO SQL is packaged into separate modules for different databases. Depending on which of these (currently supported) systems you're using, you will need to add one of the following dependencies:\n\n```scala\n//PostgreSQL\nlibraryDependencies += \"dev.zio\" %% \"zio-sql-postgres\" % \"0.1.2\" \n\n//MySQL\nlibraryDependencies += \"dev.zio\" %% \"zio-sql-mysql\" % \"0.1.2\"\n\n//Oracle\nlibraryDependencies += \"dev.zio\" %% \"zio-sql-oracle\" % \"0.1.2\"\n\n//SQL Server\nlibraryDependencies += \"dev.zio\" %% \"zio-sql-sqlserver\" % \"0.1.2\"\n```\n\n## Imports and modules\n\nMost of the needed imports will be resolved with\n\n```scala\nimport zio.sql._\n```\n\nZIO SQL relies heavily on path dependent types, so to use most of the features you need to be in the scope of one of the database modules:\n\n```scala\ntrait MyRepositoryModule extends PostgresModule {\n\n  // your ZIO SQL code here\n\n}\n\n// other available modules are MysqlModule, OracleModule and SqlServerModule\n```\n\nWe will assume this scope in the following examples.\n\n## Table schema\n\nIn order to construct correct and type-safe queries, we need to describe tables by writing user defined data type - case class in which\nname of the case class represents table name, field names represent column names and field types represent column types.\n\nValues that will represent tables in DSL are then created by calling `defineTable` method which takes case class type parameter.\nIn order for `defineTable` to work, user need to provide implicit `Schema` of data type.\n\n```scala\nimport zio.schema.DeriveSchema\nimport zio.sql.postgresql.PostgresJdbcModule\nimport zio.sql.table.Table._\n\nimport java.time._\nimport java.util.UUID\n\nobject Repository extends PostgresJdbcModule {\n  final case class Product(id: UUID, name: String, price: BigDecimal)\n  implicit val productSchema = DeriveSchema.gen[Product]\n\n  val products = defineTableSmart[Product]\n  \n  final case class Order(id: UUID, productId: UUID, quantity: Int, orderDate: LocalDate)\n  implicit val orderSchema = DeriveSchema.gen[Order]\n  \n  val orders = defineTable[Order]\n}\n```\n\n`defineTable` method is overloaded with an alternative that takes table name as an input. User can also specify table name using `@name` annotation.\nAlternatively user can use `defineTableSmart` method which will smartly pluralize table name according to english grammar.\n`OrderOrigin` -\u003e `order_origins`\n`Foot` -\u003e `feet`\n`PersonAddress` -\u003e `person_addresses`\nField names are also converted to lowercase and snake case.\n`productId` -\u003e `product_id` and so on.\n\n\n## Table schema decomposition\n\nOnce we have our table definition we need to decompose table into columns which we will use in queries.\nUsing the previous example with `Product` and `Order` table\n\n```scala\nval (id, name, price) = products.columns\n\nval (orderId, productId, quantity, date) = orders.columns\n```\n\n## Selects\n\nSimple select.\n\n```scala\nval allProducts = select(id, name, price).from(products)\n```\n\nUsing `where` clause.\n\n```scala\ndef productById(uuid: UUID) = \n  select(id, name, price).from(products).where(id === uuid)\n```\n\nInner join.\n\n```scala\nval ordersWithProductNames = \n  select(orderId, name).from(products.join(orders).on(productId === id))\n```\n\nLeft outer join.\n\n```scala\nval leftOuter = \n  select(orderId, name).from(products.leftOuter(orders).on(productId === id))\n```\n\nRight outer join.\n\n```scala\nval rightOuter = \n  select(orderId, name).from(products.rightOuter(orders).on(productId === id))\n```\n\nUsing `limit` and `offset`\n\n```scala\nval limitedResults = \n  select(orderId, name)\n    .from(products.join(orders)\n    .on(productId === id))\n    .limit(5)\n    .offset(10)\n```\n\n## Inserts\n\n```scala\ndef insertProduct(uuid: UUID) =\n  insertInto(products)(id, name, price)\n    .values((uuid, \"Zionomicon\", 10.5))\n```\n\n## Updates\n\n```scala\ndef updateProduct(uuid: UUID) =\n  update(products)\n    .set(name, \"foo\")\n    .set(price, price * 1.1)\n    .where(id === uuid)\n```\n\n## Deletes\n\n```scala\ndef deleteProduct(uuid: UUID) =\n    deleteFrom(products)\n      .where(id === uuid)\n```\n\n## Transactions\n\nTODO: details\n\n## Printing queries\n\nTODO: details\n\n## Running queries\n\nTODO: details\n\n## Documentation\n\nLearn more on the [ZIO SQL homepage](https://zio.dev/zio-sql/)!\n\n## Contributing\n\nFor the general guidelines, see ZIO [contributor's guide](https://zio.dev/about/contributing).### TL;DR\nPrerequisites (installed):\n\n| Technology | Version |  \n|------------|---------|\n| sbt        | 1.4.3   |\n| Docker     | 3.1     |\n \nTo set up the project follow below steps:\n1. Fork the repository.\n2. Setup the upstream (Extended instructions can be followed [here](https://docs.github.com/en/free-pro-team@latest/github/getting-started-with-github/fork-a-repo)).\n3. Make sure you have installed `sbt` and `Docker`.\n4. In project directory execute `sbt test`.\n5. Pick up an issue \u0026 you are ready to go!\n\n## Code of Conduct\n\nSee the [Code of Conduct](https://zio.dev/about/code-of-conduct)\n\n## Support\n\nCome chat with us on [![Badge-Discord]][Link-Discord].\n\n[Badge-Discord]: https://img.shields.io/discord/629491597070827530?logo=discord \"chat on discord\"\n[Link-Discord]: https://discord.gg/2ccFBr4 \"Discord\"\n\n## License\n\n[License](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzio-archive%2Fzio-sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzio-archive%2Fzio-sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzio-archive%2Fzio-sql/lists"}