From cb67ba9ef5c60489141ceefe3c605e0a9d411b30 Mon Sep 17 00:00:00 2001 From: "Kenneth J. Shackleton" Date: Mon, 12 Feb 2024 08:02:53 +0000 Subject: [PATCH] Room first in getting started, generally discourage direct database access. Signed-off-by: Kenneth J. Shackleton --- docs/getting_started.md | 98 ++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 64 deletions(-) diff --git a/docs/getting_started.md b/docs/getting_started.md index cfedccdfd4..c1e6eee04c 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -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" @@ -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