0

我有一张叫做联系人的表。我想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()();
}

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

4

1 回答 1

1

你应该看看文档

你正在寻找这样的东西:

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

    Future<List<Contact>> getContactByPersonId(int id) {
        return (select(contacts)..where((c) => c.person_id.equals(id))).get();
    }
}
于 2020-01-16T08:37:29.430 回答