简体   繁体   English

用于产品和库存的Google Cloud Datastore

[英]Google Cloud Datastore for a Products and Stock

I'm trying Google Cloud Datastore, but I have some doubts. 我正在尝试Google Cloud Datastore,但我有一些疑问。 I know that the ideal is to use a relational database for make a shop online, but I would like to try using Google Cloud Datastore. 我知道理想的情况是使用关系数据库在网上开店,但是我想尝试使用Google Cloud Datastore。

How would a database of 2 tables be made? 如何创建一个包含2个表的数据库? Stock and Products. 库存和产品。 The stock table has 2 columns (ref and units) and the product table has 3 columns (name, ref and price). 库存表有2列(参考和单位),产品表有3列(名称,参考和价格)。

How would you do to get all the products that have stock?... like a join, I know that we do not have joins, that's why my doubt. 您将如何获得所有有库存的产品?...像联接一样,我知道我们没有联接,这就是为什么我对此表示怀疑。

There has to be an efficient way to get the stock related to the products. 必须有一种有效的方法来获取与产品相关的库存。

There are no tables in the Datastore, you have just entities with properties. 数据存储区中没有表,只有具有属性的实体。 And, depending on the client library you use, you might have entity models. 并且,根据您使用的客户端库,您可能具有实体模型。

The Stock entities can have a Key property pointing to the corresponding Product entities. Stock实体可以具有指向相应Product实体的Key属性。 You query for the Stock entities, from the results you obtain the Product keys with which you pull the respective entities. 您查询Stock实体,从结果中获得用于拉动相应实体的Product密钥。

Or, if they're always in a 1:1 relationship I could use the exact same entity IDs for the corresponding Stock and Product entities, so I can make a Stock query and from the Stock entities in the result (or rather from their keys/IDs as I'd probably make keys_only queries) I can immediately compute the Product keys and get the respective entities (see re-using an entity's ID for other entities of different kinds - sane idea? ). 或者,如果它们始终保持1:1关系,则可以为相应的StockProduct实体使用完全相同的实体ID,这样我就可以从结果中的Stock实体(或者更确切地说,从它们的键)进行Stock查询/ IDs,就像我可能会进行keys_only查询一样),我可以立即计算Product键并获取相应的实体(请参阅将实体的ID重新用于其他种类的其他实体-理智的想法? )。

But, in general, you might want to reconsider the general SQL approach of querying data to generate a report when you need it (and expecting that to be fast) and instead make the habit of performing the necessary computations ahead of time - whenever the data used in those computations changes. 但是,总的来说,您可能需要重新考虑查询数据的常规SQL方法,以便在需要时生成报告(并希望它很快),而养成了习惯,即在数据出现时提前执行必要的计算在这些计算中使用的变化。 This is a much more scalable approach which works hand in hand with the datastore (and I guess with nosql in general). 这是一种更具可扩展性的方法,可与数据存储区协同工作(我想通常与nosql一起使用)。 And for which you do not need to perform equivalent to SQL-style join ops. 并且您不需要执行等效于SQL风格的联接操作。 Basically raise the stock empty flag for a product right when you decrement its stock value, when you already know the product in question, so that you don't have to query for it later. 基本上,当您已经知道所讨论的产品时,在减少其库存值时就提高该产品的库存空位标志,这样您以后就不必再查询它了。 While there also add it to the report (so that you'll have it ready when needed) and maybe trigger the restocking activity as well. 同时还将其添加到报告中(以便您在需要时可以准备好它),并可能还会触发补货活动。

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

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