Key-Value Model for Detabase
Project description
Key-Value Model for Detabase
API
constructor
class KVModel(dict)
example:
from kv_deta import KVModel
class Example(KVModel):
class Config(KVModel.Config):
deta_key = DETA_BASE_KEY
# or
deta = Deta(DETA_BASE_KEY)
table_name = "my_kv_table" # optional
hash = my_hash_function # default lambda x: hashlib.sha256(str(x).encode('utf8')).hexdigest()
kv = Example({"key":"value"})
update
kv.update({"k2":42})
like for dictionary
save
kv.save()
commit all data to detabase
get
mixed dict.get(key), deta.get(key), dict.setdefault(key, default)
kv.get(key="some key"[, default="newer data"])
returns value from deta.get(key)
or update it by default
if deta.get() returned None
incr, decr
based on Deta.Base.Util.incremental()
kv.incr(key="counter"[, quantity=1])
returns incremented value for key
.
if detabase have not specific key
, creates it and set value=quantity
query
kv.query(param=criteria, limit=1000, last=None) -> Dict
- return dict(key:value)
- query param see also https://deta.space/docs/en/build/reference/deta-base/queries
- update current model: kv.update(kv.query(criteria)) (??? refactoring required?)
keys
kv.keys(param=None) -> List
return list(key)
Table Struct
field | description |
---|---|
key | hash(key) |
path | origin key, hidden field |
value | data |
News
- v0.1.22 bigint's bug is not a bug
Base currently supports maximum 16 digit numbers (integers and floating points), please store larger numbers as a string.
-
@classmethod query() -> dict
by rules. you can search key(s) like a other regular fields -
read()
used query() and replaced all data in current object -
- v0.1.20 methods implementation exchanged
incr2 <--> incr
- v0.1.20 methods implementation exchanged
-
bug detected: Deta.Base.Util.incremental() doesn't work with bigint
-
v0.1.18 setup repaired
-
v0.1.17 hotfix
-
v0.1.16
query(), keys()
-
v0.1.15
rename()
-
v0.1.13 backward compatibility broken
-
v0.1.12
incr()
rewritten with Deta.Base.Util.incremental() -
v0.1.11
incr(key: str, quantity=1)
,decr(key: str, quantity=1): return incr(key, -quantity)
-
v0.1.8
get()
fix -
get(key, default)
-
save()
License
- It's opensource and free software, see the LICENSE for more details
similar projects
TODO
-
keys()
get keys list - save() refactor
- set, get, del
-
rename(key, new_key)
-
query()
return dict - TTL
-
incr()
,decr()
-
get(key)
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 Distributions
Built Distribution
Hashes for kv_deta-0.1.22a0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a604790695a0943346ab8985b3a8a7ccda93cc592ed0a29dd97af34bfadfe7f |
|
MD5 | fc232087db03eb94ffec43a059951e78 |
|
BLAKE2b-256 | 3b75ac786dde31a55be28c38b818110a3ab841a859242fd22a020c6104944268 |