Google App Engine Datastore 和其他 NoSQL 数据库的无架构设计指南 [英] Schema-less design guidelines for Google App Engine Datastore and other NoSQL DBs

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

问题描述

来自关系数据库背景,我相信很多其他人都是,我正在寻找一些可靠的指南,用于在 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)

为了非规范化,我在模型之间复制了一堆属性,因为我无法将 SearchSearchResult 连接在一起.这有意义吗?或者我应该在 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.

推荐答案

如果 SearchResultSearch.如果 SearchResult 应该引用 Search,请保留 ReferenceProperty 指向搜索.这基本上是在模型中存储了相关的SearchKey.

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 视频一年的 Google I/O(以及来自 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 数据库的无架构设计指南的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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