Skip to main content

couchdb with a simple (dict-like or list-like) interface

Project description

couchdol

couchdb with a simple (dict-like or list-like) interface

To install: pip install couchdol

A basic couchDB persister. Note that the couchDB persister is designed not to overwrite the value of a key if the key already exists. You can subclass it and use update_one instead of insert_one if you want to be able to overwrite data.

>>> from couchdol import CouchDbPersister
>>> s = CouchDbPersister()
>>> for _id in s:  # deleting all docs in tmp
...     del s[_id]
>>> k = {'_id': 'foo'}
>>> v = {'val': 'bar'}
>>> k in s  # see that key is not in store (and testing __contains__)
False
>>> len(s)
0
>>> s[k] = v
>>> len(s)
1
>>> list(s)
[{'_id': 'foo'}]
>>> s[k]
{'val': 'bar'}
>>> s.get(k)
{'val': 'bar'}
>>> s.get({'not': 'a key'}, {'default': 'val'})  # testing s.get with default
{'default': 'val'}
>>> list(s.values())
[{'val': 'bar'}]
>>> k in s  # testing __contains__ again
True
>>> del s[k]
>>> len(s)
0
>>>
>>> s = CouchDbPersister(db_name='py2store', key_fields=('name',), data_fields=('yob', 'proj', 'bdfl'))
>>> for _id in s:  # deleting all docs in tmp
...     del s[_id]
>>> s[{'name': 'guido'}] = {'yob': 1956, 'proj': 'python', 'bdfl': False}
>>> s[{'name': 'vitalik'}] = {'yob': 1994, 'proj': 'ethereum', 'bdfl': True}
>>> for key, val in s.items():
...     print(f"{key}: {val}")
{'name': 'guido'}: {'yob': 1956, 'proj': 'python', 'bdfl': False}
{'name': 'vitalik'}: {'yob': 1994, 'proj': 'ethereum', 'bdfl': True}

CouchDbStore using tuple keys.

>>> from couchdol import CouchDbTupleKeyStore
>>> s = CouchDbTupleKeyStore(key_fields=('_id', 'user'))
>>> k = (1234, 'user')
>>> v = {'name': 'bob', 'age': 42}
>>> if k in s:  # deleting all docs in tmp
...     del s[k]
>>> assert (k in s) == False  # see that key is not in store (and testing __contains__)
>>> orig_length = len(s)
>>> s[k] = v
>>> assert len(s) == orig_length + 1
>>> assert k in list(s)
>>> assert s[k] == v
>>> assert s.get(k) == v
>>> assert v in list(s.values())
>>> assert (k in s) == True # testing __contains__ again
>>> del s[k]
>>> assert len(s) == orig_length

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

couchdol-0.0.2.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

couchdol-0.0.2-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file couchdol-0.0.2.tar.gz.

File metadata

  • Download URL: couchdol-0.0.2.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for couchdol-0.0.2.tar.gz
Algorithm Hash digest
SHA256 cbcd75585061c46021af1743e3f5e72e3d61a40f3978fc24cdd7a02692b95ffc
MD5 e8656a37af176c853e34f4be5d452438
BLAKE2b-256 3635908e0b28292fd612f1ea34ab01acb1e4cbaa92e6d31a208b5159fd5b2dde

See more details on using hashes here.

File details

Details for the file couchdol-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: couchdol-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for couchdol-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 45770d6ccc336e6fe55bf4f9eadf9c7d2f9f9a6d564e38f83bf075acc0df7db7
MD5 8902f6fc7183b56036196f6be5bd4033
BLAKE2b-256 cde62628576245dc9d346a42a7a9eb9a35c8f5b04e5b129aad5634d0924003b2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page