Dialect System

Saferis supports multiple databases with compile-time type safety. Each dialect provides database-specific SQL generation and type mappings.

Available Dialects

import saferis.*

// PostgreSQL (default) - full feature support
// No additional import needed - it's the default

// MySQL:    import saferis.mysql.given
// SQLite:   import saferis.sqlite.given
// Spark SQL: import saferis.spark.given

// Switching dialect is a one-line import change; your query code adapts.
val pg = summon[Dialect]
summon[Dialect].getClass.getSimpleName
PostgresDialect$

Feature Comparison

FeaturePostgreSQLMySQLSQLiteSpark
RETURNING clauseYesNoYesNo
JSON operationsYesYesNoNo
Array typesYesNoNoNo
UPSERTYesNoNoNo
IF NOT EXISTS (indexes)YesNoYesYes
Window functionsYesYesYesYes
CTEsYesYesYesYes

Type Mappings

JDBC TypePostgreSQLMySQLSQLite
VARCHARvarchar(255)varchar(255)text
INTEGERintegerintinteger
BIGINTbigintbigintinteger
DOUBLEdouble precisiondoublereal
BOOLEANbooleanbooleaninteger
TIMESTAMPtimestamptimestamptext

Auto-Increment Syntax

DatabaseSyntax
PostgreSQLGENERATED ALWAYS AS IDENTITY
MySQLAUTO_INCREMENT
SQLiteAUTOINCREMENT

For a deeper look at how capabilities are enforced at compile time, see Type-Safe Capabilities.