Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
下の方に日本語の説明があります
import json_stock as jst
# open DB
test_db = jst.JsonStock("./test_db/")
print(test_db)
# create table
test_db["test_table"] = {}
# get table
test_table = test_db["test_table"]
print(test_table)
# create new value
test_table["test"] = {"hello": "world!!"}
# read value
print(test_table["test"])
# show table
print(test_table)
# iterate (listup all keys in the table)
print([key for key in test_table])
# delete value
del test_table["test"]
# delete table
del test_db["test_table"]
# lock the "test" key
with test_table.lock("test") as rec:
rec.value["new_key"] = "hell"
rec.value["hello"] += "!!"
If you rewrite rec.value in "WITH" as you like, the rec.value value at the moment of leaving "with" is automatically reflected in the DB ("commit" in general DB).
Example of locking multiple keys
# lock the "test" key
with test_table.lock("test") as rec, test_table.lock("test2") as rec2:
rec.value["hello"] += "!!"
rec2.value["new_key"] = rec.value["hello"] + "hell" # This prevents unintentional rewriting of rec just before changing rec2, and can be used for complex transactions such as money transfer processing
rec = test_table.lock("test")
rec.value = "hoge"
rec.unlock()
rec = test_table.lock("test")
rec.value = "fuga"
test_table.unlock("test")
with test_table.lock("test") as rec:
test_table["test"] = "hoge" # NG
with test_table.lock("test") as rec:
rec.value = "hoge" # OK
import json_stock as jst
# DBを開く (存在しない場合はディレクトリが自動的に作成される)
test_db = jst.JsonStock("./test_db/")
print(test_db)
# テーブルの作成 (右辺は必ず空の辞書である必要がある)
test_db["test_table"] = {}
# テーブルの取得
test_table = test_db["test_table"]
print(test_table)
# テーブルの"test"キーにデータを登録 (すでにキーが存在する場合は上書き)
test_table["test"] = {"hello": "world!!"}
# テーブルの"test"キーに束縛されたデータを読み出す
print(test_table["test"])
# テーブルの可視化 (soutを用いれば表示レコード数上限もカスタマイズ可能)
print(test_table)
# for文脈でテーブルの全キーを巡回
print([key for key in test_table])
# "test"キーの値を削除
del test_table["test"]
# テーブルの削除
del test_db["test_table"]
# "test"キーをロックする
with test_table.lock("test") as rec:
rec.value["new_key"] = "hell"
rec.value["hello"] += "!!"
with内でrec.valueを好きなように書き換えると、withを抜けた瞬間のrec.value値が自動的にDBに反映される (一般的なDBでいうところの「コミット」)
複数のkeyをロックする例
# lock the "test" key
with test_table.lock("test") as rec, test_table.lock("test2") as rec2:
rec.value["hello"] += "!!"
rec2.value["new_key"] = rec.value["hello"] + "hell" # このように書けば、rec2を変更する直前に意図せずrecが書き換わってしまう等が防げるため、送金処理などの複雑なトランザクションにも利用できる
rec = test_table.lock("test")
rec.value = "hoge"
rec.unlock()
rec = test_table.lock("test")
rec.value = "fuga"
test_table.unlock("test")
with test_table.lock("test") as rec:
test_table["test"] = "hoge" # NG
with test_table.lock("test") as rec:
rec.value = "hoge" # OK
FAQs
JSON-based database
We found that json-stock demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.