反标准化数据模型:django / sql - >应用引擎 [英] de-normalizing data model: django/sql -> app engine

查看:193
本文介绍了反标准化数据模型:django / sql - >应用引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始关注非关系型数据库,所以我想问一些帮助,将这些传统的SQL / django模型转换成Google App Engine模型。

I'm just starting to get my head around non-relational databases, so I'd like to ask some help with converting these traditional SQL/django models into Google App Engine model(s).

示例是针对事件列表,其中每个事件都有一个类别,属于一个场所,并且一个场所有多张照片。

The example is for event listings, where each event has a category, belongs to a venue, and a venue has a number of photos attached to it.

在django中,我将对数据建模如下:

In django, I would model the data like this:

class Event(models.Model)
    title = models.CharField()
    start = models.DatetimeField()
    category = models.ForeignKey(Category)
    venue = models.ForeignKey(Venue)

class Category(models.Model):
    name= models.CharField()

class Venue (models.Model):
    name = models.CharField()
    address = models.CharField()

class Photo(models.Model):
    venue = models.ForeignKey(Venue)
    source = models.CharField()

如何使用App Engine模型完成等同操作? >

How would I accomplish the equivalent with App Engine models?

推荐答案

这里没有什么可以取消规范化必须才能使用App Engine。您可以将ForeignKey更改为ReferenceProperty,将CharField更改为StringProperty,将DatetimeField更改为DateTimeProperty并完成。将类别存储为字符串而不是引用可能更有效,但这取决于用法上下文。

There's nothing here that must be de-normalized to work with App Engine. You can change ForeignKey to ReferenceProperty, CharField to StringProperty and DatetimeField to DateTimeProperty and be done. It might be more efficient to store category as a string rather than a reference, but this depends on usage context.

在开始设计查询时,非规范化变得非常重要。与传统SQL不同,您不能编写可访问每个表的每一行的特别查询。您要查询的任何内容都必须通过索引来满足。如果你今天运行的查询依赖于表扫描和复杂的连接,你必须确保查询参数在写时被索引,而不是即时计算。

Denormalization becomes important when you start designing queries. Unlike traditional SQL, you can't write ad-hoc queries that have access to every row of every table. Anything you want to query for must be satisfied by an index. If you're running queries today that depend on table scans and complex joins, you'll have to make sure that the query parameters are indexed at write-time instead of calculating them on the fly.

例如,如果你想对事件标题进行不区分大小写的搜索,你必须在写入时在每个实体上存储一个小写的标题副本。没有猜测你的查询要求,我真的不能提供更具体的建议。

As an example, if you wanted to do a case-insensitive search by event title, you'd have to store a lower-case copy of the title on every entity at write time. Without guessing your query requirements, I can't really offer more specific advice.

这篇关于反标准化数据模型:django / sql - >应用引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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