Skip to main content

Interface to Google Datastore, mimicking aspects of ndb, but allowing for different backends and caching

Project description

NQDB

Not quite the DB Google used to have, not quite the DB Google has now. Of course, better than both.

This is a mock of NDB, almost. It enables interfacing to Google Datastore, or to other DBs, by changing the client.

Usage

Models

from nqdb import *

client = DatastoreClient()

class Person(Model):
    _client = client
    first_name = StringProperty('first_name')
    last_name = StringProperty('last_name')

p = Person()
p.first_name = "Luca"
p.last_name = "de Alfaro"
p.put()
id = p.key_id
print("id:", id)
q = Person(id=id)
q.get()
print("First name:", q.first_name)
print("Last name:", q.last_name)

Keys

p = Person()
p.first_name = "Joe"
p.last_name = "Falchetto"
put(p)
id = p.key_id
k = Key(Person, id)
q = k.get()

Batch operations

from nqdb import put_multi

p = Person()
p.first_name = "Joe"
p.last_name = "Falchetto"
q = Person()
q.first_name = "Luca"
q.last_name = "de Alfaro"
put_multi([p, q])

The client used by put_multi is derived from the client used for p and q. You cannot mix in the same batch operations models with different clients.

Queries

q = Person.query()
q.filter(Person.first_name == 'Luca')
q.filter(Person.gender == 'Male')
for p in q.fetch():
    print(p.last_name)

You can add an ordering to a query by:

q.order(+Person.first_name)

You can use both +Person.first_name and -Person.first_name, but one of +, - should be present.

Caching

client = DatastoreClient(cache=MyCache())

Look at cache.Cache to see the (very few) methods you need to implement to use a new cache.

And as usual, look at the test files, because those do not lie.

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

nqdb-0.1.0.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

nqdb-0.1.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file nqdb-0.1.0.tar.gz.

File metadata

  • Download URL: nqdb-0.1.0.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.7

File hashes

Hashes for nqdb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 86b92a3649353a1b380a6f024c40d5e0dd17e611f1b87d836250f7dc5daf8fa3
MD5 f361f2f25032b4a37828b7d2b2634d30
BLAKE2b-256 aedbb27a0d0a98d44b859257a8949c245af8b9b59173d994b2c22d7c40971d6a

See more details on using hashes here.

File details

Details for the file nqdb-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: nqdb-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.7

File hashes

Hashes for nqdb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c48c2a39e1a66ae88ac795e2f0b649b3212f3d34e90bfdbf04b211a9e3cfe6e2
MD5 b33ff961b739a13f5261a67502fa7d58
BLAKE2b-256 3a8b4e828fe60950cf744909f58c696725f7ba3755a590a40ccd3b4002b4c40c

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