Google数据存储Python中的好模型是什么
您好,我是数据存储和Python的新手,但我必须对数据建模并将其摄取到google数据存储,我有点迷路了 我阅读了有关Python中实体关系建模和数据建模的所有内容(因此我了解一对多或多对多关系)。但我有一个简单的问题,我不知道如何回答 例如,我的数据是体育比赛的结果。在基本SQL数据库中,我会有如下内容: 表:比赛| IDmatch 比赛名称Google数据存储Python中的好模型是什么,python,google-app-engine,google-cloud-datastore,nosql,Python,Google App Engine,Google Cloud Datastore,Nosql,您好,我是数据存储和Python的新手,但我必须对数据建模并将其摄取到google数据存储,我有点迷路了 我阅读了有关Python中实体关系建模和数据建模的所有内容(因此我了解一对多或多对多关系)。但我有一个简单的问题,我不知道如何回答 例如,我的数据是体育比赛的结果。在基本SQL数据库中,我会有如下内容: 表:比赛| IDmatch 比赛名称 比赛日 赢家 IDteam1 IDteam2 然后 表:团队| IDteam 玩家名称 玩家出生 球员位置 因此,我可以简单地知道所有在比赛中使用特定i
比赛日 赢家 IDteam1 IDteam2 然后 表:团队| IDteam 玩家名称 玩家出生 球员位置 因此,我可以简单地知道所有在比赛中使用特定id的球员的姓名。它在数据库中是如何工作的?我必须使用一对多或多对多关系还是其他什么 感谢您的帮助:)您将为比赛、球队和球员做出贡献。你可以选择让球队成为一个由球员组成的球队,但是如果球员移动球队,你可以选择将两者联系起来。您可以选择将团队数据反规范化到匹配中,以便于检索(因为您无法执行联接查询) 典型模型可能如下所示:
class Team(ndb.Model):
name = ndb.StringProperty()
class Player(ndb.Model):
name = ndb.StringProperty()
date_of_birth = ndb.DateProperty()
position = ndb.StringProperty()
team = ndb.KeyProperty(kind=Team)
# denormalized properties
team_name = ndb.StringProperty()
class Match(ndb.Model):
name = ndb.StringProperty()
team1 = ndb.KeyProperty(kind=Team)
team2 = ndb.KeyProperty(kind=Team)
winning_team = ndb.KeyProperty(kind=Team)
# denormalized properties
team1_name = ndb.StringProperty()
team2_name = ndb.StringProperty()
winning_team_name = ndb.StringProperty()
这应该是你前进的起点。你会为比赛、球队和球员而努力。你可以选择让球队成为一个由球员组成的球队,但是如果球员移动球队,你可以选择将两者联系起来。您可以选择将团队数据反规范化到匹配中,以便于检索(因为您无法执行联接查询)
典型模型可能如下所示:
class Team(ndb.Model):
name = ndb.StringProperty()
class Player(ndb.Model):
name = ndb.StringProperty()
date_of_birth = ndb.DateProperty()
position = ndb.StringProperty()
team = ndb.KeyProperty(kind=Team)
# denormalized properties
team_name = ndb.StringProperty()
class Match(ndb.Model):
name = ndb.StringProperty()
team1 = ndb.KeyProperty(kind=Team)
team2 = ndb.KeyProperty(kind=Team)
winning_team = ndb.KeyProperty(kind=Team)
# denormalized properties
team1_name = ndb.StringProperty()
team2_name = ndb.StringProperty()
winning_team_name = ndb.StringProperty()
这应该是你前进的起点。你会为比赛、球队和球员而努力。你可以选择让球队成为一个由球员组成的球队,但是如果球员移动球队,你可以选择将两者联系起来。您可以选择将团队数据反规范化到匹配中,以便于检索(因为您无法执行联接查询)
典型模型可能如下所示:
class Team(ndb.Model):
name = ndb.StringProperty()
class Player(ndb.Model):
name = ndb.StringProperty()
date_of_birth = ndb.DateProperty()
position = ndb.StringProperty()
team = ndb.KeyProperty(kind=Team)
# denormalized properties
team_name = ndb.StringProperty()
class Match(ndb.Model):
name = ndb.StringProperty()
team1 = ndb.KeyProperty(kind=Team)
team2 = ndb.KeyProperty(kind=Team)
winning_team = ndb.KeyProperty(kind=Team)
# denormalized properties
team1_name = ndb.StringProperty()
team2_name = ndb.StringProperty()
winning_team_name = ndb.StringProperty()
这应该是你前进的起点。你会为比赛、球队和球员而努力。你可以选择让球队成为一个由球员组成的球队,但是如果球员移动球队,你可以选择将两者联系起来。您可以选择将团队数据反规范化到匹配中,以便于检索(因为您无法执行联接查询)
典型模型可能如下所示:
class Team(ndb.Model):
name = ndb.StringProperty()
class Player(ndb.Model):
name = ndb.StringProperty()
date_of_birth = ndb.DateProperty()
position = ndb.StringProperty()
team = ndb.KeyProperty(kind=Team)
# denormalized properties
team_name = ndb.StringProperty()
class Match(ndb.Model):
name = ndb.StringProperty()
team1 = ndb.KeyProperty(kind=Team)
team2 = ndb.KeyProperty(kind=Team)
winning_team = ndb.KeyProperty(kind=Team)
# denormalized properties
team1_name = ndb.StringProperty()
team2_name = ndb.StringProperty()
winning_team_name = ndb.StringProperty()
这应该是一个开始。好的,谢谢你帮了我很大的忙,但是当你写“去规范化团队”的时候,你是什么意思?它不在我读到的google文档中。典型的sql查询可能是SELECT Player.Name AS PlayerName,team.Name AS TeamName FROM PLAYERNER在Players.TeamID=Teams.TeamID,但这不可能使用数据存储,因为您无法执行联接查询。因此,要获得团队名称,您需要执行2次查询,如果您要查询很多玩家,这可能会很昂贵,或者将团队名称反规范化到玩家实体上。不过,你需要小心,因为如果球队名称发生变化或者球员更换了球队,你需要确保数据保持最新。好的,谢谢你,这对我帮助很大,但是当你写“去规范化团队”时,你的意思是什么?我读到的google文档中没有提到,典型的sql查询可能是SELECT player.name as PlayerName,Team.Name作为TeamName从Players.TeamID=Teams.TeamID上的Players内部加入Teams,但这不可能使用数据存储,因为您无法执行加入查询。因此,要获得团队名称,您需要执行2次查询,如果您要查询很多玩家,这可能会很昂贵,或者将团队名称反规范化到玩家实体上。不过,你需要小心,因为如果球队名称发生变化或者球员更换了球队,你需要确保数据保持最新。好的,谢谢你,这对我帮助很大,但是当你写“去规范化团队”时,你的意思是什么?我读到的google文档中没有提到,典型的sql查询可能是SELECT player.name as PlayerName,Team.Name作为TeamName从Players.TeamID=Teams.TeamID上的Players内部加入Teams,但这不可能使用数据存储,因为您无法执行加入查询。因此,要获得团队名称,您需要执行2次查询,如果您要查询很多玩家,这可能会很昂贵,或者将团队名称反规范化到玩家实体上。不过,你需要小心,因为如果球队名称发生变化或者球员更换了球队,你需要确保数据保持最新。好的,谢谢你,这对我帮助很大,但是当你写“去规范化团队”时,你的意思是什么?我读到的google文档中没有提到,典型的sql查询可能是SELECT player.name as PlayerName,Team.Name作为TeamName从Players.TeamID=Teams.TeamID上的Players内部加入Teams,但这不可能使用数据存储,因为您无法执行加入查询。因此,要获得团队名称,您需要执行2次查询,如果您要查询很多玩家,这可能会很昂贵,或者将团队名称反规范化到玩家实体上。不过,您需要小心,就像球队名称更改或球员更改球队一样,您需要确保数据保持最新。