Creating a Data Model
Last updated
Last updated
Let's create a for our note entry that conforms to the structure of our .
The BriteDatabase
from the package allows us to create and fetch data from the SQL database in JSON format. Hence, we need to add a JSON serialization/deserialization feature to our NoteEntryModel
.
In addition, we will also include a feature for mapping the Data Model
into an and vice-versa.
Under the note_app/modules/infrastructure/lib/data_sources/sqlbrite/
directory, create a file named note_entry_model.dart
and paste the following code:
Once done, build the JSON serializable class for the NoteEntryModel
using the build_runner
:
This is a good example for highlighting the difference between an Entity
and Data Model
. That is, an Entity
is entirely independent from a , whereas a Data Model
is defined from a specific Data Source
.
Tip: You can use a to run the build_runner
for multiple modules in one go.