Skip to content
y-yoshinoya edited this page Feb 16, 2013 · 23 revisions

Database Settings

Running modes

A running mode is defined by setting system property run.mode, and you can separate database configuration.

Note : default value is dev.

Configuration file

Configuration file named application.conf, located on classpath (e.g. src/main/resources/application.conf), and written in HOCON format.

application.conf example

The format is [running mode].[setting key] = [setting value].

dev {
  schema = "models.Tables"
  driver = "org.postgresql.Driver"
  jdbcurl = "jdbc:postgresql://hostname:5432/dbname"
  username = "user"
  password = "xxxxxxxx"
  partitionCount = 5
  maxConnectionsPerPartition = 1
  minConnectionsPerPartition = 5
}

test {
  schema = "models.Tables"
  driver = "org.h2.Driver"
  jdbcurl = "jdbc:h2:mem:test"
}

If you set system property "run.mode" is test, H2 JDBC driver is used.

Configuration items

This is a list of available configuration items.

Note : JDBC datasource is managed by BoneCP.

Key name Type Description Default value
schema String Schema definition class "models.Tables"
driver String JDBC driver "org.h2.Driver"
jdbcurl String JDBC URL "jdbc:h2:mem:activerecord"
username String Username for connection (none)
password String Password for connection (none)
partitionCount Integer BoneCP partitionCount (none)
maxConnectionsPerPartition Integer BoneCP maxConnectionsPerPartition (none)
minConnectionsPerPartition Integer BoneCP minConnectionsPerPartition (none)

Settings for table configurations

Default naming convention

Type Description Default
table name model class name is underscored and pluralized ModelClass => "model_classes"
intermediate table name table names are sorted and joined with underscore User, Group => groups_users
column name field name is underscored fieldName => field_name
foreign key field name camelized model class name + "Id" ModelClass => modelClassId

Override settings

Tables for Scala ActiveRecord objects are named in plural form by default. If you need to change the table name, you can override the default behavior in com.github.aselab.activerecord.ActiveRecordTables.

For example:

object Tables extends ActiveRecordTables {
  // change the convention of table name into ModelClass => "MODEL_CLASS"
  override def tableNameFromClass(c: Class[_]): String =
    c.getSimpleName.underscore.toUpperCase

  // change the convention of intermediate table name into (ModelClass1, ModelClass2) => "MODEL_CLASS1___MODEL_CLASS2"
  override def tableNameFromClasses(c1: Class[_], c2: Class[_]): String =
    Seq(c1, c2).map(tableNameFromClass).sorted.mkString("___")

  // change the convention of column name into ModelField => "MODEL_FIELD"
  override def columnNameFromPropertyName(propertyName: String): String  =
     propertyName.underscore.toUpperCase

  // change the convention of foreign key field name into ModelClass => "modelClass_id"
  override def foreignKeyFromClass(c: Class[_]): String =
    c.getSimpleName.camelize + "_id"
}
Clone this wiki locally