# RoomDatabase

Artifact: [androidx.room3:room3-runtime](https://developer.android.com/jetpack/androidx/releases/room3) [View Source](https://cs.android.com/search?q=file:androidx/room3/RoomDatabase.+class:androidx.room3.RoomDatabase) Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

*** ** * ** ***


```
public abstract class RoomDatabase
```

<br />

*** ** * ** ***

Base class for all Room databases. All classes that are annotated with `https://developer.android.com/reference/androidx/room3/Database` must extend this class.

RoomDatabase provides direct access to the underlying database implementation, but you should prefer using `https://developer.android.com/reference/androidx/room3/Dao` classes.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/room3/Database` |   |

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<T extends https://developer.android.com/reference/androidx/room3/RoomDatabase>` Builder for `https://developer.android.com/reference/androidx/room3/RoomDatabase`. |
| `public abstract class https://developer.android.com/reference/androidx/room3/RoomDatabase.Callback` Callback for `https://developer.android.com/reference/androidx/room3/RoomDatabase` |
| `public enum https://developer.android.com/reference/androidx/room3/RoomDatabase.JournalMode extends https://developer.android.com/reference/java/lang/Enum.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.JournalMode>` Journal modes for SQLite database. |
| `public final class https://developer.android.com/reference/androidx/room3/RoomDatabase.MigrationContainer` A container to hold migrations. |
| `public abstract class https://developer.android.com/reference/androidx/room3/RoomDatabase.PrepackagedDatabaseCallback` Callback for `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#createFromAsset(kotlin.String)`, `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#createFromFile(java.io.File)` and `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#createFromInputStream(java.util.concurrent.Callable)` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/room3/RoomDatabase#RoomDatabase()()` |

| ### Public methods |
|---|---|
| `abstract void` | `https://developer.android.com/reference/androidx/room3/RoomDatabase#clearAllTables()()` Deletes all rows from all the tables that are registered to this database as `https://developer.android.com/reference/androidx/room3/Database#entities()`. |
| `void` | `https://developer.android.com/reference/androidx/room3/RoomDatabase#close()()` Closes the database. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/InvalidationTracker` | `https://developer.android.com/reference/androidx/room3/RoomDatabase#getInvalidationTracker()()` The invalidation tracker for this database. |

| ### Extension functions |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase` | `https://developer.android.com/reference/androidx/room3/RoomSupportSQLite.https://developer.android.com/reference/androidx/room3/RoomDatabase#(androidx.room3.RoomDatabase).getSupportWrapper()(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase receiver)` Gets a new `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase` implementation that is backed by a `https://developer.android.com/reference/androidx/room3/RoomDatabase` for compatibility with existing usages of `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase`. |

## Public constructors

### RoomDatabase

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
public RoomDatabase()
```

## Public methods

### clearAllTables

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
public abstract void clearAllTables()
```

Deletes all rows from all the tables that are registered to this database as `https://developer.android.com/reference/androidx/room3/Database#entities()`.

This does NOT reset the auto-increment value generated by `https://developer.android.com/reference/androidx/room3/PrimaryKey#autoGenerate()`.

After deleting the rows, Room will set a WAL checkpoint and run `VACUUM`. This means that the data is completely erased. The space will be reclaimed by the system if the amount surpasses the threshold of database file size.

See SQLite documentation for details. [FileFormat](https://www.sqlite.org/fileformat.html)

### close

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
public void close()
```

Closes the database.

Once a `https://developer.android.com/reference/androidx/room3/RoomDatabase` is closed it should no longer be used.

### getInvalidationTracker

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
public @NonNull InvalidationTracker getInvalidationTracker()
```

The invalidation tracker for this database.

You can use the invalidation tracker to get notified when certain tables in the database are modified.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/InvalidationTracker` | The invalidation tracker for the database. |

## Extension functions

### RoomSupportSQLite.getSupportWrapper

Artifact: [androidx.room3:room3-sqlite-wrapper](https://developer.android.com/jetpack/androidx/releases/room3) [View Source](https://cs.android.com/search?q=file:androidx/room3/support/RoomSupportSQLite.kt+function:getSupportWrapper)

```
public final @NonNull SupportSQLiteDatabase RoomSupportSQLite.getSupportWrapper(@NonNull RoomDatabase receiver)
```

Gets a new `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase` implementation that is backed by a `https://developer.android.com/reference/androidx/room3/RoomDatabase` for compatibility with existing usages of `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase`.