# Why Locality IDB?

IndexedDB is a powerful browser-native database that supports storing significant amounts of structured data, including files and blobs. However, the raw browser IndexedDB API is low-level, verbose, and uses event-driven listeners instead of promises or modern control flows.

`Locality IDB` was built to address these shortcomings by providing a developer-friendly query builder that feels like a modern SQL ORM (specifically Drizzle ORM).

## Why Not Raw IndexedDB?

If you are weighing whether to use `Locality IDB` or write raw `IndexedDB` API calls, consider the advantages of Locality IDB:

* **Type safety**: Schema-driven types reduce compile-time and runtime errors. Your queries automatically infer the return types of selected tables.
* **Query ergonomics**: A fluent, chainable builder replaces hundreds of lines of cursor, transaction, and request handler boilerplate.
* **Built-in Validation**: Column type checks and constraints run automatically before writing to the database.
* **Consistency**: Declaring a single source of truth (the schema) makes it easy to keep data access uniform across your application.

## Comparisons

| Feature                | Raw IndexedDB                   | Locality IDB                                 |
| :--------------------- | :------------------------------ | :------------------------------------------- |
| **Type Safety**        | ✘ Manual casting               | ✓ Full TypeScript inference                 |
| **Query Syntax**       | ✘ Complex event loop / cursors | ✓ SQL-like chainable builder                |
| **Schema Validation**  | ✘ Hand-written logic           | ✓ Automatic type checks & custom validators |
| **Transactions**       | ✘ Verbose state management     | ✓ Simple callbacks with auto-rollback       |
| **Data Import/Export** | ✘ Manual serialization         | ✓ Built-in `$export()` and `$import()`      |
