0

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?

mordor619
  • 154
  • 11
  • 1
    check these questions they might help you, [question 1](https://stackoverflow.com/q/47511750/7948109) [question 2](https://stackoverflow.com/q/68998209/7948109) – Rahul Gaur Dec 09 '21 at 12:39
  • ok thanks. problem solved. can you check again the last part? – mordor619 Dec 09 '21 at 13:57
  • you don't need to check if the tables exists or not, you need to check the data inside that table; for example check last entries like answered in [this question](https://stackoverflow.com/q/44364240/7948109) – Rahul Gaur Dec 10 '21 at 04:43

0 Answers0