Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sake92/squery
Simple SQL queries in Scala 3
https://github.com/sake92/squery
h2-database jdbc mysql oracle-db postgresql scala scala3 sql sql-library
Last synced: 26 days ago
JSON representation
Simple SQL queries in Scala 3
- Host: GitHub
- URL: https://github.com/sake92/squery
- Owner: sake92
- License: apache-2.0
- Created: 2023-02-20T11:25:29.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-21T18:43:32.000Z (about 2 months ago)
- Last Synced: 2024-10-04T20:39:43.752Z (about 1 month ago)
- Topics: h2-database, jdbc, mysql, oracle-db, postgresql, scala, scala3, sql, sql-library
- Language: Scala
- Homepage: https://sake92.github.io/squery
- Size: 983 KB
- Stars: 16
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-scala - squery - activity/y/sake92/squery) (Table of Contents / Database)
README
# squery
Simple SQL queries in Scala 3.
No DSLs, no fuss, just plain SQL.
Supports *any* JDBC driver.
Additional support for Postgres, MySql, MariaDb, Oracle, H2.---
Scastie example: https://scastie.scala-lang.org/JArud6GGSLOmYyxCNsNdNw---
Hello world:
```scala// table rows
case class Customer(id: Int, name: String) derives SqlReadRow
case class Phone(id: Int, number: String) derives SqlReadRow// joined row
case class CustomerWithPhone(c: Customer, p: Phone) derives SqlReadRowval ds = JdbcDataSource()
ds.setURL("jdbc:h2:mem:")val ctx = SqueryContext(ds)
ctx.run {
val res: Seq[CustomerWithPhone] = sql"""
SELECT c.id, c.name,
p.id, p.number
FROM customers c
JOIN phones p ON p.customer_id = c.id
""".readRows[CustomerWithPhone]()
}
```