How to store a list of objects in sqflite? How to store a list of objects in sqflite? dart dart

How to store a list of objects in sqflite?


You need to create 3 tables:

  1. Foos:[fields]:
  • id
  1. Bars:[fields]:
  • foo_id: a foreign key that points to the id field of Foo
  • bar_id: which is the bar's id
  1. Bazs:[fields]:
  • foo_id: a foreign key that points to the id field of Foo
  • 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

  1. fetch the foo record:
SELECT * FROM foo WHERE id = 3;
  1. fetch bar where foo_id = 3
SELECT bar_idFROM barsINNER JOIN Foo on B.id = bars.foo_id;
  1. 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