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

Livid,关于数字ID的计算?

  •  
  •   darcy · May 2, 2010 · 5988 views
    This topic created in 6040 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
    muxi
    May 2, 2010
    1
    big table 的ID是不连续的,这个应该是自己算好,然后存进去的
    vvoody
    vvoody
    May 2, 2010
    2
    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
    vvoody
    May 2, 2010
    3
    @Livid 空格被吃掉啦
    Livid
    Livid
    MOD
    PRO
    May 2, 2010
    4
    嗯,确实是自己维护一组 counter。
    darcy
    darcy
    OP
    May 2, 2010
    5
    @vvoody @Livid
    看来也只有这样了,谢谢。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1860 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 01:41 · PVG 09:41 · LAX 17:41 · JFK 20:41
    ♥ Do have faith in what you're doing.