Skip to content

Core Operations

Lukatrum edited this page May 12, 2026 · 1 revision

Core Operations & Pythonic Syntax

Forget SQL! omni-json-db allows you to interact with your database using deeply Pythonic syntax, including standard dict methods, slicing, and set operations.

Magic Operators

The database supports intuitive Python operators for bulk data manipulation:

from omni_json_db import JDb
jdb = JDb()

# Update / Insert (equivalent to jdb.update())
jdb += {f'key{v}': v for v in range(100)}

# Remove (equivalent to jdb.remove())
jdb -= ['key10', 'key20', 'key30']

# Replace all existing matching keys (equivalent to jdb.replace())
jdb &= {f'key{v}': v + 100 for v in range(100)}

# Unmodify / Rollback (equivalent to jdb.unmodify())
jdb ^= {'key1', 'key2'}

Global Slicing Operations

You can modify all records in the database effortlessly using slicing:

# Set all records to 0
jdb[:] = 0

# Clear the entire database
jdb -= jdb  # or del jdb[:]

# Apply a Lambda function to all values
jdb[:] = lambda key, val: val + 1

Set Intersections & Unions

Treat your database like a Python Set to easily compare or merge data:

# Intersection: Find common keys
matches = jdb & {'key1', 'key99', 'unknown_key'}

# Union: Combine database keys with a new set
matches = jdb | {'new_key1', 'new_key2'}

# Difference: Find keys in DB but not in the provided set
matches = jdb - {'key1', 'key2'}

Clone this wiki locally