Skip to content

Commit

Permalink
Allow custom SupportSQLiteOpenHelper.Callback in the SqlNormalizedCac…
Browse files Browse the repository at this point in the history
…heFactory (#5488)

* Allow custom SupportSQLiteOpenHelper.Callback in the SqlNormalizedCacheFactory

* Use getSchema instead of schema

* Only expose onConfigure for now

* Update api file

---------

Co-authored-by: Rohan Dhruva <rdhruva@netflix.com>
  • Loading branch information
rohandhruva and rohandhruva authored Dec 19, 2023
1 parent 109e2df commit e0e32d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ public final class com/apollographql/apollo3/cache/normalized/sql/SqlNormalizedC
public fun <init> (Landroid/content/Context;)V
public fun <init> (Landroid/content/Context;Ljava/lang/String;)V
public fun <init> (Landroid/content/Context;Ljava/lang/String;Landroidx/sqlite/db/SupportSQLiteOpenHelper$Factory;)V
public fun <init> (Landroid/content/Context;Ljava/lang/String;Landroidx/sqlite/db/SupportSQLiteOpenHelper$Factory;Z)V
public synthetic fun <init> (Landroid/content/Context;Ljava/lang/String;Landroidx/sqlite/db/SupportSQLiteOpenHelper$Factory;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Landroid/content/Context;Ljava/lang/String;Landroidx/sqlite/db/SupportSQLiteOpenHelper$Factory;Lkotlin/jvm/functions/Function1;)V
public fun <init> (Landroid/content/Context;Ljava/lang/String;Landroidx/sqlite/db/SupportSQLiteOpenHelper$Factory;Lkotlin/jvm/functions/Function1;Z)V
public synthetic fun <init> (Landroid/content/Context;Ljava/lang/String;Landroidx/sqlite/db/SupportSQLiteOpenHelper$Factory;Lkotlin/jvm/functions/Function1;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;)V
public synthetic fun <init> (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun create ()Lcom/apollographql/apollo3/cache/normalized/api/NormalizedCache;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.apollographql.apollo3.cache.normalized.sql

import android.content.Context
import androidx.sqlite.db.SupportSQLiteDatabase
import androidx.sqlite.db.SupportSQLiteOpenHelper
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory
import com.apollographql.apollo3.cache.normalized.api.NormalizedCacheFactory
Expand All @@ -18,20 +19,29 @@ actual class SqlNormalizedCacheFactory internal constructor(
/**
* @param [name] Name of the database file, or null for an in-memory database (as per Android framework implementation).
* @param [factory] Factory class to create instances of [SupportSQLiteOpenHelper]
* @param [configure] Optional callback, called when the database connection is being configured, to enable features such as
* write-ahead logging or foreign key support. It should not modify the database except to configure it.
* @param [useNoBackupDirectory] Sets whether to use a no backup directory or not.
*/
@JvmOverloads
constructor(
context: Context,
name: String? = "apollo.db",
factory: SupportSQLiteOpenHelper.Factory = FrameworkSQLiteOpenHelperFactory(),
configure: ((SupportSQLiteDatabase) -> Unit)? = null,
useNoBackupDirectory: Boolean = false,
) : this(
AndroidSqliteDriver(
getSchema(),
context.applicationContext,
name,
factory,
object : AndroidSqliteDriver.Callback(getSchema()) {
override fun onConfigure(db: SupportSQLiteDatabase) {
super.onConfigure(db)
configure?.invoke(db)
}
},
useNoBackupDirectory = useNoBackupDirectory
),
)
Expand Down

0 comments on commit e0e32d7

Please sign in to comment.