---
name: sqlite-transactions
description: "Build a small durable SQLite backend with explicit invariants. Use for SQLite, schema, transactions."
---

# SQLite и транзакции

Build a small durable SQLite backend with explicit invariants.

## Implementation decisions

1. Use uniqueness, foreign-key and nonnegative-stock constraints.
2. Enable foreign keys per connection and set a busy timeout.
3. Use BEGIN IMMEDIATE for inventory read-modify-write and roll back failures.
4. Version schema changes and verify them against disposable databases.

## Working source

Read [starters/commerce/server.py](../webcraft-shared/source/starters/commerce/server.py) when implementing this capability. The example belongs to the WEBCRAFT React/Three.js playground except the Python commerce starter, which runs without third-party dependencies. Use [shared catalog](../webcraft-shared/source/lib/catalog.ts) only to resolve related examples. Adapt the source to the target framework and preserve existing project conventions.

## Verify observable behavior

- Values are parameterized.
- Restart preserves records.
- Failed checkout cannot partially decrement stock.

## Scope

Use only the parts relevant to the requested task. This skill does not grant permission to publish, spend money, change account access or expose secrets. The original brief and environment rules remain authoritative.

Version 2.0.0 · Original WEBCRAFT content · MIT
