Creation of tables Sqlite(Room) on Android with the standard Repository (very simple question.. but I need a clarification)

Asked

Viewed 55 times

1

Guys I have a question in the creation of tables and another in the issue of Repository, so come on.

EX:

data class Carro(
    val marca: Marca,
    val motor: Motor
)

data class Marca(
    val nome: String
)

data class Motor(
    val potencia: Double
)

The question is: 1) Will I have to create three sqlite tables for each object? Two with the second and the third? A single car containing everything?

  1. Using the Repository pattern and viewModel. When I create the class that implements Repository, from what I understand, I have to pass the Daos to the constructor of this EX

      class DatabaseDataSource(
    
          val carroDAO: CarroDAO,
          val marcaDAO: MarcaDAO,
          val motorDAO: MotorDAO
    
      ): InterfaceExemploRepository {
    
     override fun insertCarro(carro: Carro){
           marcaDAO.insert(carro.marca)
           motorDAO.insert(carro.motor)
           carroDAO.insert ????
     }
    
     ....outras funções CRUD.....
    

    }

Obviously this example is not correct and was only created for the purpose of explaining the question, who can tell me how would be the correct way I will be very grateful.

In a real problem if I use this concept of a DAO for each table, in classes with many dependencies (5 or 10 objects) I have to pass all these Daos to the Repository? That’s a good practice?

Thank you to anyone who can help me

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.