Artifact it.czerwinski.android.room:room-extensions
aggregates artifacts:
room-database
,room-database-sql
.
You can either use room-extensions
or any combination of the other artifacts, whichever suites your project.
Kotlin
dependencies {
implementation("androidx.room:room-runtime:2.4.2")
implementation("it.czerwinski.android.room:room-extensions:[VERSION]")
}
Groovy
dependencies {
implementation 'androidx.room:room-runtime:2.4.2'
implementation 'it.czerwinski.android.room:room-extensions:[VERSION]'
}
Kotlin
dependencies {
implementation("androidx.room:room-runtime:2.4.2")
implementation("it.czerwinski.android.room:room-database:[VERSION]")
}
Groovy
dependencies {
implementation 'androidx.room:room-runtime:2.4.2'
implementation 'it.czerwinski.android.room:room-database:[VERSION]'
}
Creates a RoomDatabase.Builder
for a persistent database with type T
and the given name
.
val database = context.roomDatabaseBuilder<MyDatabase>().build()
or:
val database = context.roomDatabaseBuilder<MyDatabase>(name = "database").build()
Creates a RoomDatabase.Builder
for an in memory database with type T
.
val database = context.roomInMemoryDatabaseBuilder<MyDatabase>().build()
Kotlin
dependencies {
implementation("androidx.room:room-runtime:2.3.0")
implementation("it.czerwinski.android.room:room-database-sql:[VERSION]")
}
Groovy
dependencies {
implementation 'androidx.room:room-runtime:2.3.0'
implementation 'it.czerwinski.android.room:room-database-sql:[VERSION]'
}
val database: SupportSQLiteDatabase
val sqlScriptExecutor = SQLScriptExecutor {
+"""
insert into users(id, username, password) values (1, 'root', 'qwerty');
insert into user_roles(user_id, role_id) values (1, 1);
"""
}
sqlScriptExecutor.executeOn(database)
Configures Room to populate a newly created database with an SQL script.
val database = context.roomDatabaseBuilder<MyDatabase>()
.populateFromSql {
+"""
insert into users(id, username, password) values (1, 'root', 'qwerty');
insert into user_roles(user_id, role_id) values (1, 1);
"""
}
.build()
Configures Room to populate a newly created database with an SQL script located in the application assets/
folder.
val database = context.roomDatabaseBuilder<MyDatabase>()
.populateFromSqlAsset(context, "sql/populate.sql")
.build()
Adds an SQL script migration to the builder.
val database = context.roomDatabaseBuilder<MyDatabase>()
.addMigrationFromSql(startVersion = 1, endVersion = 2) {
+"""
create table if not exists users (
id integer primary key asc,
username text not null,
password text not null
);
"""
}
.build()
Adds a migration to the builder, executing an SQL script located in the application assets/
folder.
val database = context.roomDatabaseBuilder<MyDatabase>()
.addMigrationFromSqlAsset(startVersion = 1, endVersion = 2, context, "sql/migrate_1_2.sql")
.build()
Adds migrations to the builder, executing an SQL scripts located in the application assets/
folder,
matching the given format.
val database = context.roomDatabaseBuilder<MyDatabase>()
.addMigrationsFromSqlAssets(context, sqlFilePathFormat = "sql/migrate_{}_{}.sql")
.build()
Removed in v1.2.0: Room 2.3.0 offers built-in enum
support.
Latest release of the library no longer includes artifacts:
it.czerwinski.android.room:room-converters
it.czerwinski.android.room:room-converters-processor
Removed in v1.2.0: Room 2.3.0 offers built-in enum
support.