Current section

Files

Jump to
ash_arcadic usage-rules.md
Raw

usage-rules.md

<!--
SPDX-FileCopyrightText: 2026 BaseLabs Holdings LLC

SPDX-License-Identifier: MIT
-->

# AshArcadic usage rules

Follow these rules when writing Ash resources, actions, or maintenance code
against ArcadeDB. See [Compatibility](documentation/topics/about-ash-arcadic/compatibility.md)
for toolchains, database versions, and dependency requirements.

## Declare the resource and the client

Use `AshArcadic.DataLayer` and supply an implementation of
`AshArcadic.Client` in the `arcade` block. Use Ash attribute names in
application queries and physical property names in host-side DDL.

Require `Ash.Query` before calling its filter macro. For an attribute declared
as `attribute :title, :string, source: :display_title`, this is correct.

```elixir
Ash.Query.filter(MyApp.Document, title == ^title)
```

This is incorrect because the filter must name an Ash attribute.

```elixir
Ash.Query.filter(MyApp.Document, display_title == ^title)
```

Bind values when issuing host-side Cypher. Validate identifiers separately
before placing them in statement text. See
[Resources and connections](documentation/topics/resources/resources.md).

## Scope actions and guard sensitive fields

Pass `tenant:` on tenant-scoped reads, writes, loads, and streams. Keep
the discriminator out of `sensitive` and keep edge scoping enabled for
attribute-tenant graph edges that carry a tenant stamp.

Correct for a tenant-scoped resource:

```elixir
Ash.read!(MyApp.Document, tenant: tenant)
```

Incorrect for the same resource:

```elixir
Ash.read!(MyApp.Document)
```

Store ciphertext in a declared binary storage type or skip the field.
Filter sensitive fields only for presence, and enforce a host policy
when presence is itself sensitive. See
[Multitenancy and sensitive data](documentation/topics/resources/multitenancy.md)
and [Relationships and traversal](documentation/topics/resources/relationships.md).

## Choose supported reads and writes

Sort keyset pages by a stored field the actor can read. Filter narrowly
before an in-memory combination. Use a separate authorized read when
filtering an authorizer-protected relationship. See
[Reads and expressions](documentation/topics/queries/reads.md).

Enforce a database uniqueness constraint when concurrent upserts can
create the same identity. Keep session operations in the caller process
and retry the entire transaction on `AshArcadic.Errors.TransactionConflict`.
See [Writes and transactions](documentation/topics/queries/writes.md).

## Provision search and replication explicitly

Create the declared physical indexes before writing searchable records.
Run ranked search through a read action with
`AshArcadic.Preparations.VectorSearch`. See
[Ranked search](documentation/topics/queries/ranked-search.md).

Add Replicant only in an application that uses the CDC sink. Keep
mirror resources and their checkpoint in one database, deny ordinary
writes by policy, and configure full replica identity for tenant-scoped
source tables. See [PostgreSQL change data capture](documentation/topics/replication/cdc.md).