Android 12 Developer Preview is here! Try it out, and give us your feedback!

RoomDatabase

abstract class RoomDatabase
kotlin.Any
   ↳ androidx.room.RoomDatabase

Base class for all Room databases. All classes that are annotated with Database must extend this class.

RoomDatabase provides direct access to the underlying database implementation but you should prefer using Dao classes.

Summary

Nested classes
open

Builder for RoomDatabase.

abstract

Callback for RoomDatabase.

Journal modes for SQLite database.

open

A container to hold migrations.

abstract

Callback for Builder#createFromAsset(String), Builder#createFromFile(File) and Builder#createFromInputStream(Callable)

abstract

Callback interface for when SQLite queries are executed.

Public constructors

Creates a RoomDatabase.

Public methods
open Unit

Wrapper for SupportSQLiteDatabase#beginTransaction().

abstract Unit

Deletes all rows from all the tables that are registered to this database as Database#entities().

open Unit

Closes the database if it is already open.

open SupportSQLiteStatement!
compileStatement(@NonNull sql: String)

Wrapper for SupportSQLiteDatabase#compileStatement(String).

open Unit

Wrapper for SupportSQLiteDatabase#endTransaction().

open InvalidationTracker

Returns the invalidation tracker for this database.

open SupportSQLiteOpenHelper

Returns the SQLite open helper used by this database.

open Executor

open Executor

open T?
getTypeConverter(@NonNull klass: Class<T>)

Gets the instance of the given Type Converter.

open Boolean

Returns true if current thread is in a transaction.

open Unit
init(@NonNull configuration: DatabaseConfiguration)

Called by Room when it is initialized.

open Boolean

Returns true if database connection is open and initialized.

open Cursor
query(@NonNull query: String, @Nullable args: Array<Any!>?)

Convenience method to query the database with arguments.

open Cursor
query(@NonNull query: SupportSQLiteQuery)

Wrapper for SupportSQLiteDatabase#query(SupportSQLiteQuery).

open Cursor
query(@NonNull query: SupportSQLiteQuery, @Nullable signal: CancellationSignal?)

Wrapper for SupportSQLiteDatabase#query(SupportSQLiteQuery).

open Unit
runInTransaction(@NonNull body: Runnable)

Executes the specified Runnable in a database transaction.

open V
runInTransaction(@NonNull body: Callable<V>)

Executes the specified Callable in a database transaction.

open Unit

Wrapper for SupportSQLiteDatabase#setTransactionSuccessful().

Protected methods
abstract InvalidationTracker

Called when the RoomDatabase is created.

abstract SupportSQLiteOpenHelper

Creates the open helper to access the database.

open MutableMap<Class<*>!, MutableList<Class<*>!>!>

Returns a Map of String -> List<Class> where each entry has the `key` as the DAO name and `value` as the list of type converter classes that are necessary for the database to function.

open Unit

Called by the generated code when database is open.

Extension functions
From androidx.room
suspend R
RoomDatabase.withTransaction(block: suspend () -> R)

Calls the specified suspending block in a database transaction.

Properties
SupportSQLiteDatabase!

Set by the generated open helper.

Public constructors

<init>

RoomDatabase()