|
|
|
|
@ -14,15 +14,16 @@
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.google.samples.apps.nowinandroid.core.database
|
|
|
|
|
package com.google.samples.apps.nowinandroid.core.database.di
|
|
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
|
|
|
|
import app.cash.sqldelight.async.coroutines.synchronous
|
|
|
|
|
import app.cash.sqldelight.db.QueryResult
|
|
|
|
|
import app.cash.sqldelight.db.QueryResult.AsyncValue
|
|
|
|
|
import app.cash.sqldelight.db.SqlDriver
|
|
|
|
|
import app.cash.sqldelight.db.SqlSchema
|
|
|
|
|
import app.cash.sqldelight.driver.android.AndroidSqliteDriver
|
|
|
|
|
import app.cash.sqldelight.driver.android.AndroidSqliteDriver.Callback
|
|
|
|
|
import me.tatarka.inject.annotations.Component
|
|
|
|
|
import me.tatarka.inject.annotations.Provides
|
|
|
|
|
|
|
|
|
|
@ -31,18 +32,18 @@ internal actual abstract class DriverModule(private val context: Context) {
|
|
|
|
|
|
|
|
|
|
@Provides
|
|
|
|
|
actual suspend fun provideDbDriver(
|
|
|
|
|
schema: SqlSchema<QueryResult.AsyncValue<Unit>>,
|
|
|
|
|
schema: SqlSchema<AsyncValue<Unit>>,
|
|
|
|
|
): SqlDriver {
|
|
|
|
|
val synchronousSchema = schema.synchronous()
|
|
|
|
|
return AndroidSqliteDriver(
|
|
|
|
|
schema = synchronousSchema,
|
|
|
|
|
context = context,
|
|
|
|
|
name = "nia-database.db",
|
|
|
|
|
callback = object : AndroidSqliteDriver.Callback(synchronousSchema) {
|
|
|
|
|
callback = object : Callback(synchronousSchema) {
|
|
|
|
|
override fun onOpen(db: SupportSQLiteDatabase) {
|
|
|
|
|
db.setForeignKeyConstraintsEnabled(true)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|