Google App Engine Datastore和其他NoSQL DB的免关系设计指南 [英] Schema-less design guidelines for Google App Engine Datastore and other NoSQL DBs

查看:130
本文介绍了Google App Engine Datastore和其他NoSQL DB的免关系设计指南的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从关系数据库背景来看,正如我相信许多其他人,我正在寻找一些在Google App Engine上设置/设计数据存储区的准确性指南。人们有建立这些无模式数据存储的好习惯吗?我理解一些基础知识,如非规范化,因为你不能加入,但我想知道别人有什么其他建议。

Coming from a relational database background, as I'm sure many others are, I'm looking for some solid guidelines for setting up / designing my datastore on Google App Engine. Are there any good rules of thumb people have for setting up these kinds of schema-less data stores? I understand some of the basics such as denormalizing since you can't do joins, but I was wondering what other recommendations people had.

我正在使用的一个简单的例子关注存储搜索及其结果。例如,我使用Python在Google App Engine应用程序中定义了以下两个模型:

The particular simple example I am working with concerns storing searches and their results. For example I have the following two models defined in my Google App Engine app using Python:

class Search(db.Model):
    who = db.StringProperty()
    what = db.StringProperty()
    where = db.StringProperty()

    createDate = db.DateTimeProperty(auto_now_add=True)

class SearchResult(db.Model):
    title = db.StringProperty()
    content = db.StringProperty()

    who = db.StringProperty()
    what = db.StringProperty()
    where = db.StringProperty()

    createDate = db.DateTimeProperty(auto_now_add=True)

为了进行非规范化,我在模型之间复制了一堆属性,因为我可以'一起加入搜索 SearchResult 。这有意义吗?或者我应该在 SearchResult 模型中存储搜索ID,并在从数据存储区检索它们时有效地加入两个模型代码?请记住,这是一个简单的例子。这两个模型都将有更多的属性和我现在接近的方式,我将把我放在Search模型中的任何属性在 SearchResult 模型中。

I'm duplicating a bunch of properties between the models for the sake of denormalization since I can't join Search and SearchResult together. Does this make sense? Or should I store a search ID in the SearchResult model and effectively "join" the two models in code when I retrieve them from the datastore? Please keep in mind that this is a simple example. Both models will have a lot more properties and the way I'm approaching this right now, I would put any property I put in the Search model in the SearchResult model as well.

推荐答案

如果 SearchResult

Don't duplicate the properties if they'll always be the same between the SearchResult and a Search. If a SearchResult should have a reference to a Search, keep a ReferenceProperty pointing to the Search. This basically stores the related Search's Key in the model.

class SearchResult(db.Model):
    search = db.ReferenceProperty(Search, required=True)
    # other stuff...

我还强烈建议您观看一些 App Engine视频(以及 2008 ),特别是这个由Brett Slatkin和
这一个 Ryan Barrett。如果你有时间,他们都是非常有用的视频,但我发现这两个特别是非常棒的。

I also highly recommend you watch some of the App Engine videos from last year's Google I/O (and from 2008), in particular this one by Brett Slatkin, and this one by Ryan Barrett. They're all pretty helpful videos if you have the time, but I found those two in particular to be really great.

这篇关于Google App Engine Datastore和其他NoSQL DB的免关系设计指南的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆