Databases
SADU supports four databases. Each one has its own module. Add the module for every database you want to use.
| Database | Module | Database class | Default mappers | Column types |
|---|---|---|---|---|
| PostgreSQL | sadu-postgresql | PostgreSql | PostgresqlMapper | PostgreSqlTypes |
| MariaDB | sadu-mariadb | MariaDb | MariaDbMapper | MariaDbTypes |
| MySQL | sadu-mysql | MySql | MySqlMapper | MySqlTypes |
| SQLite | sadu-sqlite | SqLite | SqLiteMapper | SqLiteTypes |
A database module brings sadu-updater and sadu-mapper with it. It does not bring the JDBC driver. Add the driver
of your database yourself.
- Gradle (Kotlin DSL)
- Gradle (Groovy)
- Maven
dependencies {
implementation("de.chojo.sadu:sadu-postgresql:2.4.0")
implementation("de.chojo.sadu:sadu-mariadb:2.4.0")
implementation("de.chojo.sadu:sadu-mysql:2.4.0")
implementation("de.chojo.sadu:sadu-sqlite:2.4.0")
}
dependencies {
implementation 'de.chojo.sadu:sadu-postgresql:2.4.0'
implementation 'de.chojo.sadu:sadu-mariadb:2.4.0'
implementation 'de.chojo.sadu:sadu-mysql:2.4.0'
implementation 'de.chojo.sadu:sadu-sqlite:2.4.0'
}
<dependency>
<groupId>de.chojo.sadu</groupId>
<artifactId>sadu-postgresql</artifactId>
<version>2.4.0</version>
</dependency>
The other modules follow the same pattern: sadu-mariadb, sadu-mysql and sadu-sqlite.
The database class
Several parts of SADU need to know which database you use: the data source builder and the
updater. You tell them with the database class. Each class has one instance. Get it with
get() or with the method named after the database:
PostgreSql postgres = PostgreSql.get(); // or PostgreSql.postgresql()
MariaDb mariadb = MariaDb.get(); // or MariaDb.mariadb()
MySql mysql = MySql.get(); // or MySql.mysql()
SqLite sqlite = SqLite.get(); // or SqLite.sqlite()
The database class knows:
- the name of the database (
postgresql,mariadb,mysql,sqlite). The updater uses it as the name of the directory with your SQL files. - the JDBC settings for the data source builder.
- how to split an SQL file into statements, and whether the database has schemas. Only PostgreSQL has schemas in SADU.
Column types
Each module has a class with the column types of its database, for example PostgreSqlTypes.INTEGER or
MariaDbTypes.VARCHAR. A type has a name and some aliases.
You need them in two places:
- to bind an array or a list as a parameter, see Parameters,
- in the default mappers, which pick a column by its type.
| Class | Types |
|---|---|
PostgreSqlTypes | CHAR, TEXT, VARCHAR, SMALLINT, INTEGER, BIGINT, DECIMAL, NUMERIC, REAL, DOUBLE, BOOLEAN, BYTEA, JSON, JSONB, DATE, TIME, TIMESTAMPTZ, TIMESTAMP |
MariaDbTypes, MySqlTypes | CHAR, VARCHAR, TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT, TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT, DECIMAL, DOUBLE, FLOAT, BOOLEAN, BINARY, VARBINARY, TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB, DATE, TIME, TIMESTAMP |
SqLiteTypes | TEXT, INTEGER, REAL, BOOLEAN, BLOB |
If a type is missing, create your own with SqlType.ofName("name", "alias", ...).
JPMS
Every module has a module-info.java. The module names are de.chojo.sadu.core, de.chojo.sadu.datasource,
de.chojo.sadu.mapper, de.chojo.sadu.queries, de.chojo.sadu.updater, de.chojo.sadu.testing,
de.chojo.sadu.postgresql, de.chojo.sadu.mariadb, de.chojo.sadu.mysql and de.chojo.sadu.sqlite.