當(dāng)熟悉 hash db
python bsddb (db-key 轉(zhuǎn))
使用確實很方便,但是沒有 想 關(guān)系數(shù)據(jù)庫中的 select order by 查詢 ,感覺比較郁悶! 上網(wǎng) 一頓 google ......
import bsddb
db = bsddb.btopen('/tmp/spam.db', 'c')
for i in range(10): db['%d'%i] = '%d'% (i*i)
db['3'] # 9
db.keys() # ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
db.set_location('6') # 36
db.previous() # 25
db.next() # 36
db.next() # 47
這可以定位,并且 previous , next 什么的 (不過目前好像是針對 string 自然 排序!)
這里比較實用的 demo
import bsddb
db = bsddb.btopen('/tmp/spam2.db', 'c')
db["2009-08-14 22:00"]="gg"
db["2009-08-15 22:00"]="cc"
db["2009-07-15 00:00"]="tt"
db["2009-08-16 22:00"]="gg"
# 注意 這 統(tǒng)配 等價 正則 = 2009-08-15.*
# 開始 以為能使用 正則 ,但不能 。只能簡單的 xxx.* 形式的
db.set_location('2009-08-15') # ('2009-08-15 22:00', 'cc')
db.next() # ('2009-08-16 22:00', 'gg')
db.set_location('2009-08-15') # ('2009-08-15 22:00', 'cc')
db.previous() #('2009-08-14 22:00', 'gg')
整理 www.tkk7.com/Good-Game