How to store a list of objects in sqflite?
You need to create 3 tables:
- Foos:[fields]:
id
- Bars:[fields]:
foo_id
: a foreign key that points to theid
field ofFoo
bar_id
: which is the bar's id
- Bazs:[fields]:
foo_id
: a foreign key that points to theid
field ofFoo
baz_id
: which is the baz's id
Now lets say that you want fetch a Foo
record with and Id = 3 along with the bar
and bazs
- fetch the foo record:
SELECT * FROM foo WHERE id = 3;
- fetch bar where
foo_id = 3
SELECT bar_idFROM barsINNER JOIN Foo on B.id = bars.foo_id;
- fetch bazs where
foo_id = 3
SELECT baz_idFROM bazsINNER JOIN Foo on B.id = bazs.foo_id;
It would be easier if you use moor
package to implement a sqllite DB