I follow the instruction to integrate SQLDelight 2.0.1 to Kotlin multiplatform project https://cashapp.github.io/sqldelight/2.0.1/multiplatform_sqlite/#constructing-driver-instances

I got error when trying to build app:

Android:

None of the following functions can be called with the arguments supplied: 
public constructor AndroidSqliteDriver(database: SupportSQLiteDatabase, cacheSize: Int = ..., windowSizeBytes: Long? = ...) defined in app.cash.sqldelight.driver.android.AndroidSqliteDriver
private constructor AndroidSqliteDriver(openHelper: SupportSQLiteOpenHelper? = ..., database: SupportSQLiteDatabase? = ..., cacheSize: Int, windowSizeBytes: Long? = ...) defined in app.cash.sqldelight.driver.android.AndroidSqliteDriver
public constructor AndroidSqliteDriver(schema: SqlSchema<QueryResult.Value<Unit>>, context: Context, name: String? = ..., factory: SupportSQLiteOpenHelper.Factory = ..., callback: SupportSQLiteOpenHelper.Callback = ..., cacheSize: Int = ..., useNoBackupDirectory: Boolean = ..., windowSizeBytes: Long? = ...) defined in app.cash.sqldelight.driver.android.AndroidSqliteDriver

iOS:

error: None of the following functions can be called with the arguments supplied: 
public constructor NativeSqliteDriver(schema: SqlSchema<QueryResult.Value<Unit>>, name: String, maxReaderConnections: Int = ..., onConfiguration: (DatabaseConfiguration) -> DatabaseConfiguration = ..., vararg callbacks: AfterVersion) defined in app.cash.sqldelight.driver.native.NativeSqliteDriver
public constructor NativeSqliteDriver(configuration: DatabaseConfiguration, maxReaderConnections: Int = ...) defined in app.cash.sqldelight.driver.native.NativeSqliteDriver
public constructor NativeSqliteDriver(databaseManager: DatabaseManager, maxReaderConnections: Int = ...) defined in app.cash.sqldelight.driver.native.NativeSqliteDriver

I declared actual method to create SqlDriver for specific platform follows the instruction.

Android:

actual class DatabaseDriverFactory(private val context: Context) {
    actual fun createDriver(): SqlDriver {
        return AndroidSqliteDriver(AppDatabase.Schema, context, "test.db")
    }
} 

iOS:

actual class DatabaseDriverFactory {
    actual fun createDriver(): SqlDriver {
        return NativeSqliteDriver(AppDatabase.Schema, "test.db")
    }
}

But the instruction is missing some parameters of the constructors. The constructor of AndroidSqliteDriver and NativeSqliteDriver actually are:

AndroidSqliteDriver(
  schema: SqlSchema<QueryResult.Value<Unit>>, 
  context: Context, 
  name: String?, 
  factory: SupportSQLiteOpenHelper.Factory, 
  callback: SupportSQLiteOpenHelper.Callback, 
  cacheSize: Int, 
  useNoBackupDirectory: Boolean, 
  windowSizeBytes: Long?
)
NativeSqliteDriver(
  schema: SqlSchema<QueryResult.Value<Unit>>, 
  name: String, 
  maxReaderConnections: Int, 
  onConfiguration: (DatabaseConfiguration) -> DatabaseConfiguration, 
  vararg callbacks: AfterVersion
)

How to define these missing parameters?

1

There are 1 best solutions below

0
Kevin Galligan On

Your constructor calls are correct. The rest of the defined params are optional. They have default values.

See NativeSqlDatabase.kt.

constructor(
    schema: SqlSchema<QueryResult.Value<Unit>>,
    name: String,
    // The rest are optional
    maxReaderConnections: Int = 1,
    onConfiguration: (DatabaseConfiguration) -> DatabaseConfiguration = { it },
    vararg callbacks: AfterVersion,
  )