从两个表中获取数据 Floor Flutter

Get Data from Two Tables Floor Flutter

我想在 flutter 中使用 floor 从两个 table 中获取数据,我该怎么做?

此代码用于从一个 table 获取数据。这个函数里面 database.g.dart:

Stream<List<Item>> getItems() {
    return _queryAdapter.queryListStream(
        'SELECT * FROM Item WHERE is_active = 1',
        mapper: (Map<String, Object?> row) => Item(
            id: row['id'] as int?,
            item_id: row['item_id'] as String,
            description: row['description'] as String,
            salePrice: row['sale_price'] as double,
            purchasePrice: row['purchase_price'] as double,
            isActive: row['is_active'] as int),
        queryableName: 'Item',
        isView: false);
  }

所以 return 将是 Item 对象,但是如果我有来自另一个 table 的连接 table 并且命令将是这样的:

SELECT junctiont.*, item.*, client.*
FROM item
INNER JOIN junctiont
ON item.id = junctiont.item_id
INNER JOIN client
ON junctiont.client_id = client.id

功能会怎样?什么会 return?.

我通过为 return 整个后续专栏创建新对象找到了答案,或者您可以 return 列出

@override
  Stream<List<List>> getBillsMainInfo() {
    return _queryAdapter.queryListStream(
        'SELECT Bills.id, Biils.bill_number, Bills.total, Bills.datetime, Clients.name FROM Bills INNER JOIN Clients ON Bills.client_id = Clients.id WHERE Bills.is_active = 1',
        mapper: (Map<String, Object?> row) => [
          row['id'] as int,
          row['bill_number'] as int,
          row['datetime'] as String,
          row['name'] as String,
          row['total'] as double
        ],
        queryableName: 'Bills',
        isView: false);
  }