A database interface that mimics a python dictionary.
Project description
A database interface that acts like a python dictionary
Install
pip install dictabase
Create a new table
# Create a table representing users from dictabase import BaseTable, RegisterDBURI RegisterDBURI() # pass nothing to default to sqlite class UserClass(BaseTable): pass newUser = New(UserClass, name='Grant', age=31) newUser = New(UserClass, name='Bob', age=99) # there is now a sqlite database containing the 2 users. Yup, thats it!
Look up items in the database
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
Read/Write to the database
# 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'] += 1 # Thats it! the database has now been updated with the new age
Drop a table
from dictabase import Drop Drop(UserClass, confirm=True) # the table has been removed from the database
Delete a specific row in a table
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Dictabase-4.0.10.tar.gz
(6.2 kB
view hashes)
Built Distribution
Close
Hashes for Dictabase-4.0.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c31e0986e561987d8359b3438b960ae610561c32955e8ba5878eb9c41b1bd562 |
|
MD5 | 101d78ae91a1439b5a7e6381add6e43c |
|
BLAKE2b-256 | b10610a85cea2231e67601f8a10cc7a84f06d12a948b345ad53db5db81d5a110 |