DEV Community

William Rodriguez
William Rodriguez

Posted on

Complex types made simple: Native JSON dictionaries and lists.

Complex types made simple: Native JSON dictionaries and lists.

You shouldn't have to manually write json.dumps() and json.loads() every time you want to store a list of tags or a configuration dictionary in SQLite. wsqlite handles nested JSON fields transparently.

Here is how you use Automatic JSON & Complex Type Serialization in production with wsqlite:

from typing import Dict, List, Any
from pydantic import BaseModel
from wsqlite import WSQLite

class ServiceConfig(BaseModel):
    id: int
    name: str
    settings: Dict[str, Any]  # Nested JSON dictionary!
    tags: List[str]            # Nested JSON list!

db = WSQLite(ServiceConfig, "configs.db")

# Insert real Python dictionary and list
db.insert(ServiceConfig(
    id=1,
    name="PaymentGateway",
    settings={"timeout": 30, "sandbox": False, "retries": 3},
    tags=["finance", "critical", "stripe"]
))

# Automatically deserialized back into typed Python structures!
config = db.get_by_field(id=1)[0]
print(config.settings["timeout"])  # Output: 30 (int, not string!)
print(config.tags[0])             # Output: 'finance'
Enter fullscreen mode Exit fullscreen mode

Why developers love wsqlite:

  • Define database tables using standard Pydantic v2 models.
  • Auto-syncs columns on startup without writing manual migrations.
  • Thread-safe connection pooling with WAL mode enabled by default (5,000+ inserts/sec).
  • Full sync and async/await support.

Check out the repo on GitHub!

Top comments (1)

Collapse
 
william_rodriguez_65a5898 profile image
William Rodriguez •

SQLite in WAL mode frequently outperforms external datastores for localized state tracking, eliminating network hops and multi-tenant connection contention.

Have you utilized embedded transactional storage for checkpointing intermediate pipeline states in production?