dqv2743 2013-02-23 10:38
浏览 32
已采纳

在GAE中<->“ CompositKey”查找的双向键?

Am writing a Go application on GAE And I have a type called Connection{Token, ToAdress, FromAdress}

I want to store it in the datastore so that I can look it up via GetConnectionByT(Token string) But also via GetConnectionByA(FromAdress,ToAdress string)

What is the best way of doing this? Right now my Connect type have two different .key() functions and I insert duplicate entry's with different keys every time I add but this feels really really wrong :)

Is datastore.NewQuery("Connection").Filter the way to go? Seames that a key should be faster and cheaper? But if not how do I filter multiple fields?

  • 写回答

1条回答 默认 最新

  • dshdb64088 2013-02-23 22:20
    关注

    If you check the documentation for datastore.Query.Filter you'll note that multiple filters are ANDed together. So you can do this kind of thing:

    q := datastore.NewQuery("Connection").
        Filter("FromAddress =", a1).
        Filter("ToAddress =", a2).
        Order("-FromAddress")
    

    If you have a key for the entity in question then yes, using the key will probably be faster. However it's a bit difficult to tell from the description in your question.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥15 pyqt信号槽连接写法
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注