简体   繁体   English

如何在objectBox flutter中连接表

[英]How to join tables in objectBox flutter

In my flutter project im doing offline module using objectBox database .In this module i have three tables ItemMaster table, customerMaster table and customerWiseStock table.在我的颤振项目中,我使用objectBox 数据库做离线模块。在这个模块中,我有三个表ItemMaster表、 customerMaster表和customerWiseStock表。 I have the data of itemMaster and customerMaster tables and i want to get stock it depends on itemId(ItemMaster) and salestypeId(CustomerMaster) .我有 itemMaster 和 customerMaster 表的数据,我想获得取决于itemId(ItemMaster)salestypeId(CustomerMaster) 的库存

How to do anyone help?别人帮忙怎么办?

here i have attach the picture for refrence.在这里我附上了图片以供参考。在此处输入图片说明

First, it's important to acknowledge that ObjectBox is not relational DB and that one cannot always apply relational mechanisms.首先,重要的是要承认 ObjectBox 不是关系数据库,并且不能总是应用关系机制。

Here's how you would typically approach this using ObjectBox:以下是您通常使用 ObjectBox 处理此问题的方法:

  1. Define relations between your entities (you don't need to model ID properties)定义实体之间的关系(您不需要建模 ID 属性)
  2. Define your query for the main result type and use links to "join" the other types in the query定义主要结果类型的查询并使用链接“加入”查询中的其他类型
  3. From the result objects, you traverse the relations from a "main type" object to get the other types and thus to any property.从结果对象中,您可以遍历“主要类型”对象的关系以获取其他类型,从而获取任何属性。

Note: ObjectBox is extremely fast when it comes to creating objects.注意:ObjectBox 在创建对象时非常快。 So traversing related objects is usually a no-issue, especially when done in a transaction .所以遍历相关对象通常不是问题,尤其是在事务中完成时。

Mixing up "columns" from separate "tables" is not something you can do with ObjectBox.从单独的“表”中混合“列”不是你可以用 ObjectBox 做的事情。 It is statically typed (and withs static schema), meaning the Dart objects are mapped directly to the data stored in the database.它是静态类型的(并且具有静态模式),这意味着 Dart 对象直接映射到存储在数据库中的数据。 What you're describing is something you'd expect from an SQL database, with dynamic results (Dart type could be something like List<Map<String, dynamic>> ).您所描述的是您期望从 SQL 数据库获得的内容,具有动态结果(Dart 类型可能类似于List<Map<String, dynamic>> )。

If you want to use an object database (not limited to ObjectBox), I suggest you think about de-normalizing your data where it makes sense.如果您想使用对象数据库(不限于 ObjectBox),我建议您考虑在有意义的地方对数据进行反规范化。 With ObjectBox relations (links) you should be able to achieve the same, but with fewer classes and still in a type-safe manner.使用 ObjectBox 关系(链接),您应该能够实现相同的目标,但使用更少的类并且仍然以类型安全的方式实现。

If you have some concrete Dart code (classes for the "entities") and an the data you want to query, I may be able to provide suggestion on how to clean things up.如果您有一些具体的 Dart 代码(“实体”的类)和要查询的数据,我可以提供有关如何清理内容的建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM