-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: issues with foreign key consistency accross different targets (#19)
- Loading branch information
1 parent
408732c
commit 8df0234
Showing
20 changed files
with
191 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...n/com/attafitamim/kabin/core/database/configuration/KabinDatabaseConfiguration.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.attafitamim.kabin.core.database.configuration | ||
|
||
import android.content.Context | ||
import app.cash.sqldelight.async.coroutines.synchronous | ||
import app.cash.sqldelight.db.QueryResult | ||
import app.cash.sqldelight.db.SqlDriver | ||
import app.cash.sqldelight.db.SqlSchema | ||
import app.cash.sqldelight.driver.android.AndroidSqliteDriver | ||
|
||
private const val DEFAULT_CACHE_SIZE = 20 | ||
|
||
actual class KabinDatabaseConfiguration( | ||
val context: Context, | ||
val name: String? = null, | ||
val cacheSize: Int = DEFAULT_CACHE_SIZE, | ||
val useNoBackupDirectory: Boolean = false, | ||
val windowSizeBytes: Long? = null, | ||
actual val extendedConfig: KabinExtendedConfig = KabinExtendedConfig() | ||
) { | ||
|
||
private fun createCallback( | ||
schema: SqlSchema<QueryResult.Value<Unit>> | ||
) = object : AndroidSqliteDriver.Callback(schema) {} | ||
|
||
actual fun createSqlDriver( | ||
schema: SqlSchema<QueryResult.AsyncValue<Unit>>, | ||
): SqlDriver { | ||
val synchronousSchema = schema.synchronous() | ||
return AndroidSqliteDriver( | ||
synchronousSchema, | ||
context, | ||
name, | ||
cacheSize = cacheSize, | ||
useNoBackupDirectory = useNoBackupDirectory, | ||
windowSizeBytes = windowSizeBytes, | ||
callback = createCallback(synchronousSchema) | ||
).configure(this) | ||
} | ||
} |
24 changes: 0 additions & 24 deletions
24
...in/kotlin/com/attafitamim/kabin/core/database/configuration/KabinDatabaseConfiguration.kt
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
...ry/core/src/androidMain/kotlin/com/attafitamim/kabin/core/driver/DriverFactory.android.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 14 additions & 1 deletion
15
...in/kotlin/com/attafitamim/kabin/core/database/configuration/KabinDatabaseConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,18 @@ | ||
package com.attafitamim.kabin.core.database.configuration | ||
|
||
import app.cash.sqldelight.db.QueryResult | ||
import app.cash.sqldelight.db.SqlDriver | ||
import app.cash.sqldelight.db.SqlSchema | ||
import com.attafitamim.kabin.core.utils.toggleForeignKeys | ||
|
||
expect class KabinDatabaseConfiguration { | ||
val extendedConfig: KabinExtendedConfig | ||
} | ||
|
||
fun createSqlDriver( | ||
schema: SqlSchema<QueryResult.AsyncValue<Unit>>, | ||
): SqlDriver | ||
} | ||
|
||
fun SqlDriver.configure(configuration: KabinDatabaseConfiguration) = apply { | ||
toggleForeignKeys(configuration.extendedConfig.foreignKeyConstraintsEnabled) | ||
} |
10 changes: 0 additions & 10 deletions
10
library/core/src/commonMain/kotlin/com/attafitamim/kabin/core/driver/DriverFactory.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.