Simple Document database Library
Project description
kudb
simple document database for python
Features
- Simple and convenient Document database and Key-value Store Library
- Easy to install (Use SQLite for the back end)
Installation
$ python3 -m pip install kudb
Repository
Documents
Usage
- (1) connect to database --- kudb.connect()
- (2) CRUD
- insert data --- kudb.insert()
- update data --- kudb.update()
- get data --- kudb.get_all() / kudb.get()
- delete data --- kudb.delete()
- (3) close --- kudb.close()
- functions
Basic Sample
Basic sample
import kudb
kudb.connect('test.db')
# insert data
kudb.insert({'name': 'Tako', 'age': 18})
kudb.insert({'name': 'Ika', 'age': 19})
kudb.insert({'name': 'Poko', 'age': 12})
kudb.insert({'name': 'Foo', 'age': 13})
# get all data
for row in kudb.get_all():
print('get_all >', row) # all
# close
kudb.close()
Find data
Find data
import kudb
kudb.connect('test.db')
# clear all data
kudb.clear()
# insert many data
kudb.insert_many([
{'name': 'Tako', 'age': 18},
{'name': 'Ika', 'age': 19},
{'name': 'Hirame', 'age': 20},
])
# get by id
print('id=2 >', kudb.get(id=2))
# find by keys
for row in kudb.find(keys={'name': 'Tako'}):
print('name=Tako >', row)
# find by lambda
for row in kudb.find(lambda v: v['name'] == 'Tako'):
print('name=Tako >', row)
# get recent data
for row in kudb.recent(2):
print('recent(2) =>', row) # => Ika, Hirame
Search data with tag
The doc data can set tag. When use data with tag, you can search data quickly. And use data with tag, you can update/delete data quickly.
import kudb
kudb.connect('test.db')
kudb.clear()
# insert data with tag
kudb.insert({'name': 'Tako', 'age': 18}, tag='Tako')
kudb.insert({'name': 'Ika', 'age': 19}, tag='Ika')
kudb.insert({'name': 'Poko', 'age': 12}, tag='Poko')
# get data by tag
print('tag=Ika =>', kudb.get(tag='Ika')[0])
# insert many data with tag_name
kudb.insert_many([
{"name": "A", "age": 10},
{"name": "B", "age": 11},
{"name": "C", "age": 12}], tag_name='name')
# get data by tag
print('tag=B =>', kudb.get(tag='B')[0])
# get data by id (most speedy)
print('id=1 =>', kudb.get(id=1)) # => Tako
# get data by tag
for row in kudb.get(tag="Ika"):
print('tag=Ika =>', row) # Ika
# find data with keys
for row in kudb.find(keys={"name": "Ika"}): # enum data when name=Ika
print('find.keys={name:ika} => ', row) # Ika
for row in kudb.find(keys={"age": 19}): # enum data when age=19
print('find.keys={age:19} => ',row) # 19 (Ika)
# find data with lambda function
for row in kudb.find(lambda v: v['name'] == 'Ika'): # enum data when name=Ika
print('lambda.name=Ika =>', row) # => Ika
for row in kudb.find(lambda v: v['age'] >= 12): # enum data when age >= 12
print('lambda.age=12 =>', row) # => Ika
Update and delete
Update and delete sample:
import kudb
kudb.connect('test.db')
kudb.clear()
# insert many data with tag_name
kudb.insert_many([
{"name": "A", "age": 10},
{"name": "B", "age": 11},
{"name": "C", "age": 12},
{"name": "D", "age": 13},
{"name": "E", "age": 14}], tag_name='name')
# delete by id
kudb.delete(id=5)
# delete by tag
kudb.delete(tag='C')
# update data by id
kudb.update_by_id(1, {'name': 'A', 'age': 22})
print('update.A=22 >', kudb.get(id=1))
# update dagta by tag
kudb.update_by_tag('B', {'name': 'B', 'age': 23})
print('update.B=23 >', kudb.get(tag='B'))
Key-Value Store
Key-Value Store sample:
import kudb
kudb.connect('test.db')
kudb.set_key('hoge', 1234)
print(kudb.get_key('hoge'))
# get data that does not exists
print(kudb.get_key('hoge_1st', 'not exists'))
kudb.close()
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
kudb-0.2.4.tar.gz
(9.5 kB
view details)
Built Distribution
kudb-0.2.4-py3-none-any.whl
(8.1 kB
view details)
File details
Details for the file kudb-0.2.4.tar.gz
.
File metadata
- Download URL: kudb-0.2.4.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c33e4b51fe9bb440a8117ebfb5efad00a2894350481c0367d793dacd43c4c09 |
|
MD5 | e09677c2f97747633a3c1fd83eab7220 |
|
BLAKE2b-256 | 9f31af564dc5a307746b19faeda539aa7ad6d2f5c50e20a2f83ec3e4dedf3544 |
File details
Details for the file kudb-0.2.4-py3-none-any.whl
.
File metadata
- Download URL: kudb-0.2.4-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c77aebca3c63c9aaaca963a9fdc170409fb101b2c43d7314671e39b30539c0a |
|
MD5 | 9c6a70f91cf0c91b289c3bb22321698c |
|
BLAKE2b-256 | 6cc40884c19a2032e49f38238f61d66a171ae1d3cf74bf62859f75da9d9287dc |