# `AshScylla`
[🔗](https://github.com/ohhi-vn/ash_scylla/blob/main/lib/ash_scylla.ex#L15)

AshScylla is a data layer for Ash Framework that uses ScyllaDB (via Xandra).

## Usage

Configure your Ash resource to use AshScylla.DataLayer:

    defmodule MyApp.MyResource do
      use Ash.Resource,
        data_layer: AshScylla.DataLayer

      attributes do
        uuid_primary_key :id
        attribute :name, :string
        attribute :email, :string
      end
    end

Configure your repo to use AshScylla:

    defmodule MyApp.Repo do
      use AshScylla.Repo,
        otp_app: :my_app
    end

Then configure your resource to use the repo:

    # In your resource configuration
    use Ash.Resource,
      data_layer: AshScylla.DataLayer,
      repo: MyApp.Repo

## Top-Level Functions

- `verify/2` — Verify repo connection, keyspace, and resource tables
- `verify!/2` — Same as `verify/2` but raises on failure
- `migrate/2` — Run migrations for all resources
- `create_keyspace/2` — Create the configured keyspace
- `version/0` — Return the AshScylla version string

# `create_keyspace`

```elixir
@spec create_keyspace(
  module(),
  keyword()
) :: :ok | {:error, term()}
```

Creates the keyspace for a repo if it doesn't exist.

## Examples

    AshScylla.create_keyspace(MyApp.Repo)

    AshScylla.create_keyspace(MyApp.Repo, strategy: :network_topology, topologies: [{"dc1", 3}, {"dc2", 3}])

# `migrate`

```elixir
@spec migrate(
  module(),
  keyword()
) :: :ok | {:error, term()}
```

Runs migrations for all AshScylla resources against the given repo.

This is a convenience function for use in release tasks or scripts.

## Options

- `:resources` - List of specific resource modules to migrate (default: auto-discover)
- `:dry_run` - If true, only log statements without executing
- `:create_keyspace` - Create the keyspace before migrating

## Examples

    AshScylla.migrate(MyApp.Repo)

    AshScylla.migrate(MyApp.Repo, resources: [MyApp.User])

    AshScylla.migrate(MyApp.Repo, dry_run: true)

# `verify`

```elixir
@spec verify(
  module(),
  keyword()
) :: {:ok, map()} | {:error, term()}
```

Verifies that a repo can connect to ScyllaDB.

By default this checks the configured nodes and keyspace. Pass `resources:` to
also verify that each resource's table exists in the configured keyspace.

## Options

- `:nodes` - Override the configured nodes
- `:keyspace` - Override the configured keyspace
- `:connect_timeout` - Override the connection timeout
- `:resources` - Resource modules whose tables should be verified
- `:check_connection?` - Whether to open a temporary connection. Defaults to `true`.

## Examples

    AshScylla.verify(MyApp.Repo)

    AshScylla.verify(MyApp.Repo, resources: [MyApp.User])

    AshScylla.verify(MyApp.Repo, check_connection?: false)

# `verify!`

```elixir
@spec verify!(
  module(),
  keyword()
) :: map() | no_return()
```

Verifies a repo, raising if verification fails.

# `version`

```elixir
@spec version() :: String.t()
```

Returns the version of AshScylla.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
