项目作者: evometric

项目描述 :
A Key-Value database for the command-line and in Python, backed by SQLite3
高级语言: Python
项目地址: git://github.com/evometric/PesdaDB.git
创建时间: 2020-05-21T22:13:25Z
项目社区:https://github.com/evometric/PesdaDB

开源协议:MIT License

下载


PesdaDB

A Key-Value database for the command-line and in Python, backed by SQLite3

Overview

  1. you@computer:~ $ python3 ~/PesdaDB/pesdadb.py
  2. ERROR: No command specified
  3. usage: settings.py [-h]
  4. [--get KEY DEFAULT | --set KEY VALUE | --set-default KEY VALUE | --del KEY | --create]
  5. [--db DATABASE]
  6. Get/Set Key-Values in a database
  7. optional arguments:
  8. -h, --help show this help message and exit
  9. --get KEY DEFAULT GET a value with key KEY and value DEFAULT if not set
  10. --set KEY VALUE SET a value with key KEY and value VALUE
  11. --set-default KEY VALUE
  12. SET a value ONLY IF KEY does NOT already exist (used
  13. for populating defaults)
  14. --del KEY DELETE a key and value with key KEY
  15. --create Create schema
  16. --db DATABASE Specify Database path (you can also set an environment
  17. variable 'PESDADB' which will be overriden by --db)

Specify path to database

(you can also use --db <path> on every call if you like)

  1. you@computer:~ $ export PESDADB=/tmp/my_pesdadb_store.db

Manually create it first

  1. you@computer:~ $ python3 ~/PesdaDB/pesdadb.py --create

Set and Get a string

  1. you@computer:~ $ python3 ~/PesdaDB/pesdadb.py --set foo bar
  2. you@computer:~ $ python3 ~/PesdaDB/pesdadb.py --get foo ""
  3. bar

It always wants a default value

…in case the key does not exist, but just specify an empty string if you don’t care, (as above)

  1. you@computer:~ $ python3 ~/PesdaDB/pesdadb.py --get foo2 bar2
  2. bar2

Set a default value

If you want to overwrite a set of new default settings for your program, then this won’t replace any existing ones

  1. you@computer:~ $ python3 ~/PesdaDB/pesdadb.py --set-default foo fuzz
  2. you@computer:~ $ python3 ~/PesdaDB/pesdadb.py --get foo ""
  3. bar

Send in JSON, get back JSON

In fact it will only store valid json. Then you can chain it to JQ or something, if you like

  1. you@computer:~ $ python3 ~/PesdaDB/pesdadb.py --set my_array '["zuli", "kyan", "lars", "fozz"]'
  2. you@computer:~ $ python3 ~/PesdaDB/pesdadb.py --get my_array "[]"
  3. ["zuli", "kyan", "lars", "fozz"]
  4. you@computer:~ $ python3 ~/PesdaDB/pesdadb.py --get my_array "[]" | jq '.'
  5. [
  6. "zuli",
  7. "kyan",
  8. "lars",
  9. "fozz"
  10. ]
  11. you@computer:~ $ python3 ~/PesdaDB/pesdadb.py --get my_array "[]" | jq '.[2]'
  12. "lars"
  13. you@computer:~ $ python3 ~/PesdaDB/pesdadb.py --set my_object '{"goodies": ["elsa", "anna", "kristoff", "sven", "olaf"], "baddies": ["marshmallow", "hans", "weaselman"]}'
  14. you@computer:~ $ python3 ~/PesdaDB/pesdadb.py --get my_object "{}" | jq '.baddies[0]'
  15. "marshmallow"

Why

I needed a robust key/value store that can be:

  • Used simulataneously between many programs at the same time.
  • Used in Python and on the CLI
  • Handle JSON & with safe defaults

It’s built upon the ubiquitous and amazing Sqlite3 which does all of the hard work to satisfy my wishlist above, and so PesdaDB is just a Python wrapper for some SQL commands.

License

PesdaDB is provided under the MIT license,
but if you use it commercially or otherwise, please consider sending a postcard, by mail from wherever you live, to:

  1. Rob & Family
  2. EvoMetric
  3. G58
  4. Menai Science Park
  5. Gaerwen
  6. Anglesey
  7. LL60 6AG
  8. UNITEC KINGDOM