Skip to main content

Databases

SADU supports four databases. Each one has its own module. Add the module for every database you want to use.

DatabaseModuleDatabase classDefault mappersColumn types
PostgreSQLsadu-postgresqlPostgreSqlPostgresqlMapperPostgreSqlTypes
MariaDBsadu-mariadbMariaDbMariaDbMapperMariaDbTypes
MySQLsadu-mysqlMySqlMySqlMapperMySqlTypes
SQLitesadu-sqliteSqLiteSqLiteMapperSqLiteTypes

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.

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")
}

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:

ClassTypes
PostgreSqlTypesCHAR, TEXT, VARCHAR, SMALLINT, INTEGER, BIGINT, DECIMAL, NUMERIC, REAL, DOUBLE, BOOLEAN, BYTEA, JSON, JSONB, DATE, TIME, TIMESTAMPTZ, TIMESTAMP
MariaDbTypes, MySqlTypesCHAR, VARCHAR, TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT, TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT, DECIMAL, DOUBLE, FLOAT, BOOLEAN, BINARY, VARBINARY, TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB, DATE, TIME, TIMESTAMP
SqLiteTypesTEXT, 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.