本文整理匯總了Python中PyDbLite.Base.update方法的典型用法代碼示例。如果您正苦於以下問題:Python Base.update方法的具體用法?Python Base.update怎麽用?Python Base.update使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyDbLite.Base
的用法示例。
在下文中一共展示了Base.update方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from PyDbLite import Base [as 別名]
# 或者: from PyDbLite.Base import update [as 別名]
class BARTSIDEE_CONFIG:
def __init__(self):
self.path_temp = mc.GetTempDir()
self.path_module = os.path.join(CWD, "modules")
if not os.path.exists(self.path_module):
os.makedirs(self.path_module)
sys.path.append(self.path_module)
self.app_version = VERSION
self.db_version = 11
self.initDB()
GA.debug = self.get("debug")
def initDB(self):
self.db = Base("maindb")
self.db.create("id", "data", mode="open")
self.searchdb = Base("searchdb")
self.searchdb.create("module", "id", "timestamp", "data", mode="open")
self.cache = tools.storage()
try:
if len(self.db) < 3:
self.default()
except:
self.default()
records = self.db(id="version")
if records[0]["data"] < self.db_version:
self.default()
def get(self, key):
records = self.db(id=key)
if records:
return records[0]["data"]
else:
return False
def set(self, key, data):
records = self.db(id=key)
if records:
self.db.update(records, data=data)
else:
self.db.insert(id=key, data=data)
self.db.commit()
def default(self):
self.clearDB()
try:
pointer = os.path.join(CWD, "settings.json")
file = open(pointer, "r")
defaults = json.load(file)
file.close()
except:
print traceback.format_exc()
defaults = {}
for key in defaults.keys():
self.db.insert(str(key), defaults[key])
self.db.insert("version", self.db_version)
self.db.commit()
def clearDB(self):
try:
records = self.db()
self.db.delete(records)
except:
self.db.create("id", "data", mode="override")
self.db.commit()
def clearCache(self):
self.cache.empty()
def clearSearch(self):
try:
records = self.searchdb()
self.searchdb.delete(records)
except:
self.searchdb.create("module", "id", "timestamp", "data", mode="override")
self.searchdb.commit()
def clearAll(self):
self.default()
self.clearCache()
self.clearSearch()