Skip to content

외래 키

드라이버의 onOpen 콜백을 통해 Android SQLite 드라이버에 대한 외래 키 제약 조건을 활성화할 수 있습니다.

kotlin
AndroidSqliteDriver(
  schema = Database.Schema,
  callback = object : AndroidSqliteDriver.Callback(Database.Schema) {
    override fun onOpen(db: SupportSQLiteDatabase) {
      db.setForeignKeyConstraintsEnabled(true)
    }
  }
)

JVM SQLite 드라이버의 경우, 드라이버 속성에 설정을 전달하여 외래 키 제약 조건을 활성화할 수 있습니다.

kotlin
JdbcSqliteDriver(
  url = "...", 
  properties = Properties().apply { put("foreign_keys", "true") }
)



데이터베이스 구성에서 외래 키 제약 조건을 활성화하여 네이티브 SQLite 드라이버에 대해 외래 키 제약 조건을 사용할 수 있습니다.

```kotlin
NativeSqliteDriver(
  schema = Database.Schema,
  onConfiguration = { config: DatabaseConfiguration ->
    config.copy(
      extendedConfig = DatabaseConfiguration.Extended(foreignKeyConstraints = true)
    )
  }
)