Go App Engine嵌套对象不会存储在Cloud Datastore中。

huangapple go评论84阅读模式
英文:

Go App Engine nested objects are not stored in Cloud Datastore

问题

我有一个名为EmergencyCase的实体,它有两个嵌入结构(一个数组和一个结构体)。
当我尝试通过调用以下代码保存EmergencyCase时:

datastore.Put(c, key, &ec)

除了Pos字段(类型为Position)之外,其他所有内容都被正确存储。关于这个问题,没有错误或日志记录。它只是没有被存储。有什么建议吗?

以下是我的三个实体定义:

type Position struct{
    lon float32
    lat float32
}
type EmergencyCase struct{
    // 自动生成的ID,不存储在数据库中。
    ID string `datastore:"-"`
    CreatedAt time.Time
    Closed bool
    ClosedByUser bool `datastore:",noindex"`
    AutoClosed bool `datastore:",noindex"`
    Pos Position
    Events []Event
}

type Event struct{
    // 自动生成的ID,不存储在数据存储中。
    ID string `datastore:"-"`
    CreatedAt time.Time
    Name string `datastore:",noindex"`
}
英文:

I have a entity EmergencyCase that has 2 embedded structs (1 array and 1 struct)
When I try to save the EmergencyCase by calling:

datastore.Put(c, key, &ec)

Everything is stored fine except the Pos field (type Position). There is no error or log entry about this. It is just not stored. Any suggestions?

Here are my 3 entities definitions:

type Position struct{
	lon float32
	lat float32
}
type EmergencyCase struct{
	// Autogenerated id, not stored in the database.
	ID string `datastore:"-"`
	CreatedAt time.Time
	Closed bool
	ClosedByUser bool `datastore:",noindex"`
	AutoClosed bool `datastore:",noindex"`
	Pos Position
	Events []Event
}

type Event struct{
	// Autogenerated id, not stored in the datastore.
	ID string `datastore:"-"`
	CreatedAt time.Time
	Name string `datastore:",noindex"`
}

答案1

得分: 5

将Position字段的名称导出,通过将名称的第一个字母大写。数据存储只存储导出字段

type Position struct{
  Lon float32
  Lat float32
}

翻译结果:

将Position字段的名称通过将名称的第一个字母大写来导出。数据存储只存储导出字段

type Position struct{
  Lon float32
  Lat float32
}
英文:

Export the Position field names by uppercasing the first letter in the name. The datastore stores exported fields only.

type Position struct{
  Lon float32
  Lat float32
}

答案2

得分: 1

尝试使用appengine.GeoPoint作为一种替代/优化的类。

英文:

Try using appengine.GeoPoint as an altenative/optimised class

huangapple
  • 本文由 发表于 2015年11月8日 19:48:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/33593588.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定