模拟python字典的数据库接口。
Dictabase的Python项目详细描述
充当python字典的数据库接口
安装
pip安装数据库
示例
Click here to see a complete example main.py
创建新表
# Create a table representing users from dictabase import BaseDictabaseTable class UserClass(BaseDictabaseTable): pass newUser = UserClass(name='Grant', age=31) newUser = UserClass(name='Bob', age=99) # there is now a sqlite database containing the 2 users. Yup, thats it!
在数据库中查找项目
from dictabase import FindOne, FindAll allUsers = FindAll(UserClass) # allUsers is an iterable of all the UserClass objects that exists in the database print('allUsers=', list(allUsers)) >> allUsers= [<UserClass: name='Grant', age=31>, <UserClass: name='Bob', age=99>] user = FindOne(UserClass, name='Grant') print('user=', user) >>user= <UserClass: name='Grant', age=31> user = FindOne(UserClass, name='NotARealName') print('user=', user) >>user= None
读/写数据库
# find an object that was previously put in the database user = FindOne(UserClass, name='Grant') # increment the age of the user by 1 user['age'] = user['age'] + 1 # Thats it! the database has now been updated with the new age
放下桌子
from dictabase import Drop Drop(UserClass) # the table has been removed from the database
删除表中的特定行
from dictabase import Delete # find an object that was previously put in the database user = FindOne(UserClass, name='Grant') Delete(user) # the user has been removed from the database