# Magic Local Storage

**A local SQLite database, ready for Magic.**

`DB` and `Schema` facades, migrations, seeders, factories and a push-then-pull sync skeleton on one local SQLite connection.

## One connection. Every model.

Your Magic app gets a local SQLite database with facades, migrations and seeders that Laravel developers will find familiar. Listed targets: Android, iOS, macOS, Windows, Linux and web.

### Migrations and Schema

`Migration` classes with `up` and `down`, the `Schema` facade (`create`, `table`, `drop`, `dropIfExists`, `rename`) and a `Migrator` that runs them with savepoints.

[Learn more about Migrations and Schema](https://anilcancakir.com/magic/docs/local_storage/basics/migrations.md)

### The DB facade

`DB.table(name)` returns a `QueryBuilder`, and the facade also runs raw SQL and `DB.transaction`.

[Learn more about The DB facade](https://anilcancakir.com/magic/docs/local_storage/basics/queries.md)

### Local model storage

A Magic model that sets `useLocal` reads and writes the local database: the package binds a `local_model_store` behind the model methods.

[Learn more about Local model storage](https://anilcancakir.com/magic/docs/local_storage/basics/models.md)

### Seeders and factories

`Seeder` classes run with `Seeding.run(list)`. `Factory<T>` classes (`definition`, `count`, `create`) build fake rows for seeds and tests.

[Learn more about Seeders and factories](https://anilcancakir.com/magic/docs/local_storage/basics/seeding.md)

### A sync skeleton

A push-then-pull skeleton: `SyncFeed.run`, a sync ledger and a cursors table on the same connection. It is a skeleton, not a finished sync.

[Learn more about A sync skeleton](https://anilcancakir.com/magic/docs/local_storage/guides/sync.md)

### One SQLite engine

Native targets use the `sqlite3` package over FFI, with the file in the application documents directory. The web uses `sqlite3.wasm` on an IndexedDB-backed file system.

[Learn more about One SQLite engine](https://anilcancakir.com/magic/docs/local_storage/basics/configuration.md)

## Add it in seconds

```bash
flutter pub add magic_local_storage
```

Or add to `pubspec.yaml`:

```yaml
dependencies:
  magic_local_storage: ^1.0.1
```

Or give your AI agent this prompt:

```text
Read https://anilcancakir.com/magic/docs/local_storage/llms.txt and install the Magic Local Storage package in this project.
```

## Docs

### Getting Started

- [Installation](https://anilcancakir.com/magic/docs/local_storage/getting-started/installation.md)

### The Basics

- [Configuration](https://anilcancakir.com/magic/docs/local_storage/basics/configuration.md)
- [Models](https://anilcancakir.com/magic/docs/local_storage/basics/models.md)
- [Queries](https://anilcancakir.com/magic/docs/local_storage/basics/queries.md)
- [Migrations](https://anilcancakir.com/magic/docs/local_storage/basics/migrations.md)
- [Seeding](https://anilcancakir.com/magic/docs/local_storage/basics/seeding.md)

### Guides

- [Generators](https://anilcancakir.com/magic/docs/local_storage/guides/generators.md)
- [Sync](https://anilcancakir.com/magic/docs/local_storage/guides/sync.md)
- [Testing](https://anilcancakir.com/magic/docs/local_storage/guides/testing.md)
