SDBC is a collection of database APIs for Scala. It originally was meant to be an alternative to Anorm, but has also borrowed ideas from from Doobie. SDBC is not an ORM, but the JDBC and Cassandra APIs contain some basic ORM functionality.
It currently supports Apache Cassandra, H2, MariaDB, Microsoft SQL Server, and PostgreSQL.
JDBC connection pools are provided by HikariCP. The pools can be created with a HikariConfig or Typesafe Config object.
- Java 8
- Scala 2.11, 2.12 or 2.13.
- Cassandra, H2, MariaDB, Microsoft SQL Server, or PostgreSQL
Include an implementation of the SLF4J logging interface, turn on debug logging, and all your query executions will be logged with the query text and the parameter name-value map.
Packages exist on Maven Central for Scala 2.11 and 2.12.
"com.rocketfuel.sdbc" %% "cassandra-datastax" % "4.0.0"
"com.rocketfuel.sdbc" %% "h2-jdbc" % "4.0.0"
"com.rocketfuel.sdbc" %% "mariadb-jdbc" % "4.0.0"
"com.rocketfuel.sdbc" %% "sqlserver-jdbc" % "4.0.0"
"com.rocketfuel.sdbc" %% "postgresql-jdbc" % "4.0.0"
BSD 3-Clause, so SDBC can be used anywhere Scala is used.
- Use generics and implicit conversions to retrieve column or row values.
- Get tuples or case classes from rows without any extra work. (thanks to shapeless)
- Use tuples or case classes to set query parameters. (thanks to shapeless)
- Use named parameters with queries.
- Use Scala collection combinators to manipulate result sets.
- Log queries with SLF4J.
- Supports Java 8's java.time package.
- FS2 Streams for streaming to or from a DBMS.
- Easily add column or row types.
- Type classes for each query type.
- The H2 JDBC driver does not support getResultSet on inner arrays, so only 1 dimensional arrays are supported.
- The H2 JDBC driver does not support ResultSet#updateArray, so updating arrays is not supported.
column type | column time zone | java.time type |
---|---|---|
timestamp or datetime | GMT | Instant |
timestamp or datetime | same as client | LocalDateTime |
timestamp or datetime | not GMT and not client's | Timestamp, then convert to LocalDateTime with desired time zone |
timestamptz or timestamp with time zone or datetimeoffset | OffsetDateTime | |
date | LocalDate | |
time | LocalTime | |
timetz or time with time zone | OffsetTime |
Starting with 2.0, there are benchmarks to ensure that some common operations don't have too much overhead over jdbc. There are two so far. The first batch inserts a collection of a case class. The second selects a colletion of a case class.
- Scala 2.13 support
- Support Circe and Json4s Native for PostgreSQL
- JSON libraries for PostgreSQL are no longer required dependencies. You can pick the one you want to use.
- CloseableIterator behaves better
- Select, Selectable, Query, and Queryable now have map methods
- The wrong index was used for null parameters in jdbc queries.
- Correct publishing to Maven Central
- MariaDB & MySQL support
- JDBC Connection types are now per-DBMS (i.e. they are path dependent).
- Update scalaz streams to FS2.
- Stream support is built-in. Try using methods such as stream, pipe, and sink.
- Support for multiple result sets per query from MariaDB and SQL Server using MultiQuery.
- A datetime without an offset from a DBMS is interpreted as being in UTC rather than the system default time zone.
- No longer supports Scala 2.10.
- Moved database objects to
com.rocketfuel.sdbc.{Cassandra, H2, PostgreSql, SqlServer}
. - Renamed Execute to Ignore.
- Added Insert, Delete, and their type classes.
- Typeclass methods are now in their respective companion objects. For example,
Selectable.select
. - There are objects you can import to have type class methods added to type class members. For example
import com.rocketfuel.sdbc.PostgreSql.syntax._
would let you do something likePerson.Name(3, "Judy").update()
to update the name of record 3 to Judy. - SelectForUpdate takes the update function as an argument. It returns a summary of the number of rows deleted, inserted, and updated.
- Maven package names changed again. Hopefully the last time.
- The sigil for a parameter is
'@'
(was'$'
). - Added support for string interpolation for parameters.
- Cassandra support.
- Scalaz streaming helpers in com.rocketfuel.sdbc.scalaz.
- Connections and other types are no longer path dependent.
- Package paths are implementation dependent. (E.G.
import ...postgresql.jdbc
to use the JDBC driver to access PostgreSQL.) - You can use scodec's
ByteVector
instead ofArray[Byte]
. - Remove Byte getters, setters, and updaters from PostgreSQL (the JDBC driver uses Short under the hood).
- Added Joda Time support.
- Only Hikari configuration parameters are sent to the HikariConfig constructor.
- Added support for Java 7.
- XML getters and setters use Node instead of Elem.
- PostgreSQL was missing some keywords in its Identifier implementation.
- Add support for H2.
- Test packages have better support for building and destroying test catalogs.
- Some method names were shortened:
executeBatch()
tobatch()
,executeUpdate()
toupdate()
.