使用 moor_flutter 包在 sqlite 数据库 table 中获取所有具有相同列值的记录

get all records with same column value in an sqlite db table using moor_flutter package

我有一个 table 叫联系人。我想获取下面 contacts table 中的所有记录 where person_id = 1

class Contacts extends Table {
  IntColumn get id => integer().autoIncrement()();
  TextColumn get contact_type => text().withLength(min: 1, max: 50)();
  TextColumn get contact => text().withLength(min: 1, max: 100)();
  IntColumn get person_id =>
      integer().customConstraint('REFERENCES persons(id)')();
  DateTimeColumn get created => dateTime()();
  DateTimeColumn get updated => dateTime()();
}

如何使用 moor_flutter 执行 select * from contacts where person_id = 1?谢谢,用爱发帖。

你应该看看docs

您正在寻找这样的东西:

@UseMoor(tables: [Contacts])
class MyDatabase extends _$MyDatabase {  

    Future<List<Contact>> getContactByPersonId(int id) {
        return (select(contacts)..where((c) => c.person_id.equals(id))).get();
    }
}