小编Dan*_*ath的帖子

将长字符串转换为int64 - Go

我找到了将长字符串格式的整数转换为Go中的int64的方法.我使用了strconv.Atoi,但它给了我一个错误,称"值超出范围".我搜索了我找到的答案

ParseInt(s string, base int, bitSize int) (i int64, err error)

在strconv包中.但是,我不明白我应该为函数参数提供什么值,包括base和bitSize.

我试图将我从HTTP请求收到的字符串格式的datastore.Key.IntID()解析回int64,以创建在数据存储上执行查询的新密钥.

任何人都可以向我解释一下base和bitSize参数以及我应该在这种情况下在参数中提供什么值?

google-app-engine go google-cloud-datastore

1
推荐指数
1
解决办法
2492
查看次数

Google App Engine数据存储存储默认路径

pathGoogle App Engine数据存储区的数据的默认Windows是什么?我很好奇在devserver.py期间我的笔记本电脑上保存了这些数据的位置.

google-app-engine development-environment path local-storage google-cloud-datastore

1
推荐指数
1
解决办法
793
查看次数

GAE ndb.JsonProperty()默认列表

我有以下设置.为什么JsonProperty的默认列表属性保留在其他实体中为其分配的先前值.我错过了什么吗?

class Item(ndb.Model):
    foo = ndb.JsonProperty(default=[])

    def add_to_foo(self, value):
        self.foo.append(value)
        return

item1 = Item()
item1.add_to_foo('one')
item1.put()

item2 = Item()
item2.add_to_foo('two')
item2.put()

print item2.foo  # prints out ['one', 'two']
Run Code Online (Sandbox Code Playgroud)

为什么打印出来'['one','two']?我只给了'两个'.这是预期的行为吗?

python google-app-engine json app-engine-ndb google-cloud-datastore

1
推荐指数
1
解决办法
847
查看次数

如何在NDB数据存储中获取模型列表

我想以编程方式删除数据存储区中的所有数据。

为此,我需要遍历所有模型,并为每个模型删除所有模型的实体。

那么,如何以编程方式获取NDB数据存储区中所有模型的列表?

app-engine-ndb google-cloud-datastore

1
推荐指数
1
解决办法
260
查看次数

为什么我的应用引擎查询找不到我的实例?

我一直在玩App Engine,但我似乎误解了NDB数据存储区查询.我把抛出的错误放在查询旁边.

在交互式控制台中玩游戏:

from google.appengine.ext import ndb  

class Client(ndb.Model):  
    email =  ndb.StringProperty()  
    name = ndb.StringProperty(indexed=True)  

#instantiated client instance with the parameters below. ID is 6578378068983808  
#client = Client(email = "bryan@gmail.com", name = "Bryan Wheelock" ).put()  

client = Client.query( Client.name == 'Bryan Wheelock')  
#client = Client.query( Client.ID == 6578378068983808 ) #AttributeError: type object 'Client' has no attribute 'ID'  
#client = Client.all() #AttributeError: type object 'Client' has no attribute 'all'    
#client = Client.get_by_id(6578378068983808) #THIS WORKS returns u'Bryan Wheelock'   

pprint.pprint(client.name)  
Run Code Online (Sandbox Code Playgroud)

我所做的示例查询完全取决于App Engine文档,我做错了什么?

python google-app-engine app-engine-ndb google-cloud-datastore

1
推荐指数
1
解决办法
107
查看次数

祖先钥匙和父钥匙的明显区别是什么?

祖先钥匙和父钥匙的明显区别是什么?

它基本相同吗?它如何以不同方式影响get()方法和Query方法?

从GAE KeyFactory课程中,我们只能看到Key父母而没有这样的祖先Key.

public static Key createKey(Key parent, String kind, String name) {
    return createKey(parent, kind, name, (AppIdNamespace)null);
}
Run Code Online (Sandbox Code Playgroud)

然后使用这样的键:

Entity e = new Entity(key); // key may include a parent Key
Run Code Online (Sandbox Code Playgroud)

在典型的查询中,例如在留言簿应用中.我们可以将密钥作为祖先,因此我们可以使用不同的留言簿来保存实体,例如:

Key guestbookKey = KeyFactory.createKey("Guestbook", guestbookName);
Query q = new Query(kind, guestbookKey); // guestbookKey = ancestor
Run Code Online (Sandbox Code Playgroud)

那么父母和祖先的区别是什么,他们基本上是一样的没有任何区别,只是不同的符号是一样的吗?

google-app-engine google-cloud-datastore

1
推荐指数
1
解决办法
144
查看次数

DataStore超过配额,同时启用了计费和数据存储API

尝试放入数据时出现以下错误:

抱歉,意外错误:API调用datastore_v3.Put()需要的配额多于可用配额

问题是我没有超额配额,并启用了结算和Google Cloud Datastore API.我究竟做错了什么?

google-api app-engine-ndb google-cloud-datastore

1
推荐指数
1
解决办法
183
查看次数

我可以从_pre_put_hook导致失败吗?

我在每次放置之前使用预置挂钩从api中获取一些数据.如果该api没有响应或处于脱机状态,我希望请求失败.我是否必须围绕put()调用编写一个包装器,或者是否有某种方式使我们仍然可以键入My_model.put()并使其失败?

python google-app-engine app-engine-ndb google-cloud-datastore

1
推荐指数
1
解决办法
227
查看次数

Google App Engine NDB排序会丢失实体

我试图根据得分对从数据集中提取的几个实体进行排序,但目前它只返回1个实体而不是当前数据存储区中的4个实体.

该模型定义如下:

class Place(ndb.Model):
    """Model for places."""
    title = ndb.StringProperty()
    url = ndb.StringProperty()
    longitude = ndb.StringProperty()
    latitude = ndb.StringProperty()
    score = ndb.IntegerProperty()
    votes = ndb.KeyProperty(repeated = True, kind = 'Vote')
    reviews = ndb.KeyProperty(repeated = True, kind = 'Review')
Run Code Online (Sandbox Code Playgroud)

我试图获取10个得分最高的地方的查询是:

places = Place.query().order(Place.score).fetch(10)
Run Code Online (Sandbox Code Playgroud)

我拥有的当前数据集: 数据存储的屏幕截图

这导致仅A返回地点而不是其他实体.

如何从最高到最低对实体进行排序score

PS:我已经谷歌搜索过,无法找到任何有效的解决方案.

python sorting google-app-engine app-engine-ndb google-cloud-datastore

1
推荐指数
1
解决办法
57
查看次数

GAE Python NDB .put在开发时不同步(但在生产中工作)?

下面的代码应创建一个Counter模型并使用(延迟)任务将计数器增加到10.访问时'/'应该创建一个单独的Counter对象count = 10.这在生产中发生.在开发(localhost)Counter中,创建了多个对象,其中最大的对象为10:

在此输入图像描述

我怀疑这是因为put开发时不同步(但似乎总是在生产中).有没有办法让它们同步?

以下代码段:

class Counter(ndb.Model):
  count = ndb.IntegerProperty(indexed=False)

def reset():
  ndb.delete_multi(Counter().query().fetch(keys_only=True, use_cache=False, use_memcache=False))

def increment():
  counter = Counter().query().get(use_cache=False, use_memcache=False)
  if not counter:
    counter = Counter(count=0)

  counter.count += 1
  counter.put()

  if counter.count < 10:
    deferred.defer(increment)

@app.route('/')
def hello():
  """Return a friendly HTTP greeting."""
  reset()
  deferred.defer(increment)
  return 'Hello World!'
Run Code Online (Sandbox Code Playgroud)

我有一个git repo,可以在这里重现这种行为.您可以在此处找到进行最后更改的提交.

python google-app-engine app-engine-ndb google-cloud-datastore

1
推荐指数
1
解决办法
281
查看次数