How to return a list from a database?

136 Views Asked by At

In my code, which is presented below, I convert my group into a database model and add it to the database. Then I return the group object. and I need to return a list of groups that are added to the database. How can I create a method that returns a list of groups from those that are added to the database?

class GroupRepository extends BaseRepository<GroupDao, GroupDBData, Group> {
  @override
  GroupDao dao = injector<AppDb>().groupDao;
  @override
  BaseConverter<GroupDBData, Group> converter = GroupDbConverter();
  Future<Group> convertGroup(Group group) async {
    final convert = converter.outToIn(group);
    final groupId = await dao.insert(convert);
    Group groupWithID = Group(
      id: groupId,
      groupName: group.groupName,
    );
    return groupWithID;
  }
}

1

There are 1 best solutions below

0
Jitesh Mohite On

Inside Dao write Query to fetch groups, like below

  @Query('SELECT * FROM group_table)
  Future<List<Group>> findGroups();