模拟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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java JNLP无法在浏览器中正确启动(与dtjava.js一起部署)   在执行下一个方法之前,java将等待线程执行结束   java如何将另一个LayoutManager应用于JComboBox?(多栏JComboBox尝试)   使用jPBC在java中实现双线性配对   java在使用@RequestMapping注释时获取请求的值(URL)   java如何控制流量   java如何获取IFC对象的绝对坐标?   java目标服务器无法使用htmlunit和tor响应异常   java需要帮助创建一个循环结构来运行我的程序   java有可能拥有一个Android APK并在应用程序中更改构建变体吗?   在Sphinx4中运行Ant的java   Java:从ArrayList获取子列表的有效方法   java如何使在循环内部创建的数组在循环外部工作?   apache poi通过java中的XSSF表从单元格读取日期值   安卓 java自己的SeqLock实现,避免spinlock会更好吗?   java的并发底层方法。util。同时发生的预定未来   java比较方法违反了它的一般约定,如何使它具有可传递性?   使用JAVA定向指定类的DB导出子类   一个方法中的java更改特定imageView