i have this kind of json data->
{
"author": "Chinua Achebe",
"country": "Nigeria",
"imageLink": "images/things-fall-apart.jpg",
"language": "English",
"link": "https://en.wikipedia.org/wiki/Things_Fall_Apart\n",
"pages": 209,
"title": "Things Fall Apart",
"year": 1958
}
now i have created two entities->
Author.kt
@Entity(tableName = "author_data")
data class Author(
@PrimaryKey(autoGenerate = true)
val id: Int,
val author_name: String,
val country: String
)
Book.kt
@Entity(tableName = "book_data", indices = [Index(value = ["title"], unique = true)])
data class Book(
@PrimaryKey(autoGenerate = true)
val id: Int,
val title: String,
val image_link: String,
val language: String,
val link: String,
val age: Int,
val year: Int
)
now i want to add from json data to local storage but this is the thing->
Book must have int foreign key referencing Author entity.
how do i do that? someone help please. i am stuck.
i am using kotlin.
EDIT: above problem solved.
Now what i want to know-> is there any way to check if these tables already exist in local storage than i dont want to download the data again?