I want to use the sqflite
package to store my objects. I read some articles, tutorials and examples about it. So far I understand everything. But none of them covers my use case:
I have a class named Foo
. This class holds beside some primitive fields an object of the class Bar
. Bar
has only primitive fields. Additionally Foo
has a list of objects of the type Baz
. Baz
has also only primitive fields.
class Foo {
// simple fields
String id;
Bar bar;
List<Baz> bazs;
}
class Bar {
// only primitive fields
String id;
}
class Baz {
// only primitive fields
String id;
}
I want to connect the bar
object with the foo
object in the database and the same with the bazs
objects. How do I do it? Whats the best way?
I'm not really experienced wit SQL. I know what SELECT, WHERE, ORDERBY and so on means but my knowledge does not get much further.
I found this qustion in Stack Overflow but I wonder if it is actually efficient to store all the values as a JSON. What happens if the JSON gets really big?
Currently my only idea is to store the id
of the bar
object as a field in the foo
object or vica versa. foo
could also hold a list of the id
s of the bazs
objects. Or each baz
objects holds the id
of the foo
object. Is this a good solution?
Is there a possibility to let sqflite
handle the relations between the objects?