DAOCLOUD
推荐学习书目
Python Cookbook
Using Google App Engine
推荐下载
Latest Google App Engine SDK
其他兼容技术
AppScale
darcy

Livid,关于数字ID的计算?

  •  
  •   darcy · May 2, 2010 · 5616 views
    This topic created in 5893 days ago, the information mentioned may be changed or developed.
    http://v2ex.appspot.com/t/213
    请问一下最后213这个ID,你每次处理是自己计算该使用的编号还是直接数据库的key_id,貌似使用key_id数字不是连续的
    5 replies    1970-01-01 08:00:00 +08:00
    muxi
        1
    muxi  
       May 2, 2010
    big table 的ID是不连续的,这个应该是自己算好,然后存进去的
    vvoody
        2
    vvoody  
       May 2, 2010
    from google.appengine.ext import db

    class Accumulator(db.Model):
    counter = db.IntegerProperty()

    def increment_counter(key, amount):
    obj = db.get(key)
    obj.counter += amount
    obj.put()

    q = db.GqlQuery("SELECT * FROM Accumulator")
    acc = q.get()

    db.run_in_transaction(increment_counter, acc.key(), 5)

    可以自己这么维护一个counter
    vvoody
        3
    vvoody  
       May 2, 2010
    @Livid 空格被吃掉啦
    Livid
        4
    Livid  
    MOD
    PRO
       May 2, 2010
    嗯,确实是自己维护一组 counter。
    darcy
        5
    darcy  
    OP
       May 2, 2010
    @vvoody @Livid
    看来也只有这样了,谢谢。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1152 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 17:44 · PVG 01:44 · LAX 10:44 · JFK 13:44
    ♥ Do have faith in what you're doing.