A Table is represented as a DataSource, and a Row in the table is represented as an Entity.
Performing CRUD operations on the ProductDataSource(product table) will go like this:
ProductDataSource productDataSource = ProductDataSource();
// open connection to database
await productDataSource.open();
// insert entity(row)
await productDataSource.insert(ProductEntity(..args));
// get entity(row)
ProductEntity productEntity = await productDataSource.get(id);
// get all entities(rows)
List<ProductEntity> list = await productDataSource.all();
// update entity(row)
await productDataSource.update(ProductEntity(..args));
// delete entity(row)
await productDataSource.delete(id);
// delete all entities(rows)
await productDataSource.deleteAll();
// close connection to database
await productDataSource.close();
The folder structure is organized as:
features
tests
all_tests.dart
config.dart
data_source.dart
entity.dart
config.dart contains variables for setting the database name, database version, and all the createTableQueries for the database.
data_source.dart is an abstract class that represents a table. It also contains methods that can be called on a table. All data sources must implement this class. E.g: ProductDataSource implements this class.
entity.dart
This abstract class represents a row or record in a table. All entities must implement this class.
E.g: ProductEntity implements this class.
features
It contains classes for the different data sources(tables) and their respective entities(rows). The folders are organized by features.
tests
It contains test suites for testing the different data sources(tables). The folders are organized by features.
all_tests.dart
Use flutter run -t lib/local_db/tests/all_tests.dartto run tests on all the data sources(tables) at a go.
A Table is represented as a DataSource, and a Row in the table is represented as an Entity.
Performing CRUD operations on the ProductDataSource(product table) will go like this:
The folder structure is organized as:
config.dart contains variables for setting the database name, database version, and all the createTableQueries for the database.
data_source.dart is an abstract class that represents a table. It also contains methods that can be called on a table. All data sources must implement this class. E.g: ProductDataSource implements this class.
entity.dart This abstract class represents a row or record in a table. All entities must implement this class. E.g: ProductEntity implements this class.
features It contains classes for the different data sources(tables) and their respective entities(rows). The folders are organized by features.
tests It contains test suites for testing the different data sources(tables). The folders are organized by features.
all_tests.dart Use
flutter run -t lib/local_db/tests/all_tests.dart
to run tests on all the data sources(tables) at a go.