Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Room first in getting started, generally discourage direct database access. #509

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 34 additions & 64 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,40 @@

## Getting a database

### Using Room

=== "Kotlin"
``` kotlin
private fun deriveKey(): ByteArray? = TODO(
"Optional key, must be exactly 32-bytes long.")

private val factory = createSupportSQLiteOpenHelperFactory(
SQLiteJournalMode.WAL,
deriveKey()
)

val database = Room.databaseBuilder(context, MyAppDatabase::class.java, "app")
.openHelperFactory(factory)
.build()
```

=== "Java"
``` java
private byte[] deriveKey() {
// TODO Optional key, must be exactly 32-bytes long.
}

private SupportSQLiteOpenHelper.Factory factory =
SupportSQLiteOpenHelperKt.createSupportSQLiteOpenHelperFactory(
SQLiteJournalMode.WAL,
deriveKey());

final RoomDatabase database = Room.databaseBuilder(
context, MyAppDatabase.class, "app"
).openHelperFactory(factory)
.build();
```

### Using an open helper

=== "Kotlin"
Expand Down Expand Up @@ -95,70 +129,6 @@
);
```

### Using Room

=== "Kotlin"
``` kotlin
private fun deriveKey(): ByteArray? = TODO(
"Optional key, must be exactly 32-bytes long.")

private val factory = createSupportSQLiteOpenHelperFactory(
SQLiteJournalMode.WAL,
deriveKey()
)

val database = Room.databaseBuilder(context, MyAppDatabase::class.java, "app")
.openHelperFactory(factory)
.build()
```

=== "Java"
``` java
private byte[] deriveKey() {
// TODO Optional key, must be exactly 32-bytes long.
}

private SupportSQLiteOpenHelper.Factory factory =
SupportSQLiteOpenHelperKt.createSupportSQLiteOpenHelperFactory(
SQLiteJournalMode.WAL,
deriveKey());

final RoomDatabase database = Room.databaseBuilder(
context, MyAppDatabase.class, "app"
).openHelperFactory(factory)
.build();
```

### Directly

=== "Kotlin"
``` kotlin
private fun deriveKey(): ByteArray? = TODO(
"Optional key, must be exactly 32-bytes long.")

SQLiteDatabase.openOrCreateDatabase(
context.getDatabasePath("sample"),
SQLiteJournalMode.WAL.databaseConfiguration,
deriveKey()
).apply {
exec("PRAGMA journal_mode=${SQLiteJournalMode.WAL}")
}
```

=== "Java"
``` java
private byte[] deriveKey() {
// TODO Optional key, must be exactly 32-bytes long.
}

final SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(
targetContext.getDatabasePath("sample"),
SQLiteJournalMode.WAL.databaseConfiguration,
deriveKey()
);
database.exec("PRAGMA journal_mode=WAL");
```

## Interaction

### Querying the database
Expand Down
Loading