#
tokens: 34026/50000 1/34 files (page 4/10)
lines: on (toggle) GitHub
raw markdown copy reset
This is page 4 of 10. Use http://codebase.md/m-gonzalo/cosa-sai?lines=true&page={x} to view the full context.

# Directory Structure

```
├── .gitignore
├── bun.lock
├── Dockerfile
├── package.json
├── prompts
│   └── default.txt
├── README.md
├── smithery.yaml
├── src
│   ├── db.ts
│   ├── gemini.ts
│   ├── index.ts
│   ├── logger.ts
│   └── types.ts
├── test
│   ├── docs
│   │   ├── ash-docs
│   │   │   ├── ash_admin.md
│   │   │   ├── ash_appsignal.md
│   │   │   ├── ash_archival.md
│   │   │   ├── ash_authentication_phoenix.md
│   │   │   ├── ash_authentication.md
│   │   │   ├── ash_cloak.md
│   │   │   ├── ash_csv.md
│   │   │   ├── ash_cubdb.md
│   │   │   ├── ash_double_entry.md
│   │   │   ├── ash_graphql.md
│   │   │   ├── ash_json_api.md
│   │   │   ├── ash_money.md
│   │   │   ├── ash_oban.md
│   │   │   ├── ash_phoenix.md
│   │   │   ├── ash_postgres.md
│   │   │   ├── ash_rbac.md
│   │   │   ├── ash_sqlite.md
│   │   │   ├── ash_state_machine.md
│   │   │   └── ash.md
│   │   ├── bun-elysia-docs
│   │   │   ├── bun.sh.md
│   │   │   └── elysiajs.com.md
│   │   ├── javascript-docs
│   │   │   └── sample.md
│   │   └── phoenix-docs
│   │       └── phx-docs.md
│   └── prompts
│       ├── ash-framework.txt
│       ├── bun-elysia.txt
│       ├── javascript.txt
│       └── phoenix.txt
└── tsconfig.json
```

# Files

--------------------------------------------------------------------------------
/test/docs/ash-docs/ash_sqlite.md:
--------------------------------------------------------------------------------

```markdown
   1 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
   2 | 
   3 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
   4 | 
   5 | v0.2.3
   6 | 
   7 | - Pages
   8 | - Modules
   9 | - Mix Tasks
  10 | 
  11 | <!--THE END-->
  12 | 
  13 | <!--THE END-->
  14 | 
  15 | <!--THE END-->
  16 | 
  17 | Search documentation of ash\_sqlite
  18 | 
  19 | Settings
  20 | 
  21 | # [View Source](https://github.com/ash-project/ash_sqlite "View Source") API Reference ash\_sqlite v0.2.3
  22 | 
  23 | ## [](api-reference.html#modules)Modules
  24 | 
  25 | [AshSqlite](AshSqlite.html)
  26 | 
  27 | The AshSqlite extension gives you tools to map a resource to a sqlite database table.
  28 | 
  29 | [AshSqlite.CustomExtension](AshSqlite.CustomExtension.html)
  30 | 
  31 | A custom extension implementation.
  32 | 
  33 | [AshSqlite.CustomIndex](AshSqlite.CustomIndex.html)
  34 | 
  35 | Represents a custom index on the table backing a resource
  36 | 
  37 | [AshSqlite.DataLayer](AshSqlite.DataLayer.html)
  38 | 
  39 | A sqlite data layer that leverages Ecto's sqlite capabilities.
  40 | 
  41 | [AshSqlite.DataLayer.Info](AshSqlite.DataLayer.Info.html)
  42 | 
  43 | Introspection functions for
  44 | 
  45 | [AshSqlite.Functions.ILike](AshSqlite.Functions.ILike.html)
  46 | 
  47 | Maps to the builtin sqlite function `ilike`.
  48 | 
  49 | [AshSqlite.Functions.Like](AshSqlite.Functions.Like.html)
  50 | 
  51 | Maps to the builtin sqlite function `like`.
  52 | 
  53 | [AshSqlite.ManualRelationship](AshSqlite.ManualRelationship.html)
  54 | 
  55 | A behavior for sqlite-specific manual relationship functionality
  56 | 
  57 | [AshSqlite.Reference](AshSqlite.Reference.html)
  58 | 
  59 | Represents the configuration of a reference (i.e foreign key).
  60 | 
  61 | [AshSqlite.Repo](AshSqlite.Repo.html)
  62 | 
  63 | Resources that use [`AshSqlite.DataLayer`](AshSqlite.DataLayer.html) use a `Repo` to access the database.
  64 | 
  65 | [AshSqlite.Statement](AshSqlite.Statement.html)
  66 | 
  67 | Represents a custom statement to be run in generated migrations
  68 | 
  69 | [AshSqlite.Type](AshSqlite.Type.html)
  70 | 
  71 | Sqlite specific callbacks for [`Ash.Type`](../ash/3.4.58/Ash.Type.html).
  72 | 
  73 | ## [](api-reference.html#mix-tasks)Mix Tasks
  74 | 
  75 | [mix ash\_sqlite.create](Mix.Tasks.AshSqlite.Create.html)
  76 | 
  77 | Create the storage for repos in all resources for the given (or configured) domains.
  78 | 
  79 | [mix ash\_sqlite.drop](Mix.Tasks.AshSqlite.Drop.html)
  80 | 
  81 | Drop the storage for the given repository.
  82 | 
  83 | [mix ash\_sqlite.generate\_migrations](Mix.Tasks.AshSqlite.GenerateMigrations.html)
  84 | 
  85 | Generates migrations, and stores a snapshot of your resources.
  86 | 
  87 | [mix ash\_sqlite.install](Mix.Tasks.AshSqlite.Install.html)
  88 | 
  89 | Installs AshSqlite. Should be run with `mix igniter.install ash_sqlite`
  90 | 
  91 | [mix ash\_sqlite.migrate](Mix.Tasks.AshSqlite.Migrate.html)
  92 | 
  93 | Runs the pending migrations for the given repository.
  94 | 
  95 | [mix ash\_sqlite.rollback](Mix.Tasks.AshSqlite.Rollback.html)
  96 | 
  97 | Reverts applied migrations in the given repository. Migrations are expected at "priv/YOUR\_REPO/migrations" directory of the current application but it can be configured by specifying the `:priv` key under the repository configuration. Runs the latest applied migration by default. To roll back to a version number, supply `--to version_number`. To roll back a specific number of times, use `--step n`. To undo all applied migrations, provide `--all`.
  98 | 
  99 | [Next Page → Home](readme.html)
 100 | 
 101 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
 102 | 
 103 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
 104 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
 105 | 
 106 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
 107 | 
 108 | v0.2.3
 109 | 
 110 | - Pages
 111 | - Modules
 112 | - Mix Tasks
 113 | 
 114 | <!--THE END-->
 115 | 
 116 | <!--THE END-->
 117 | 
 118 | <!--THE END-->
 119 | 
 120 | Search documentation of ash\_sqlite
 121 | 
 122 | Settings
 123 | 
 124 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/custom_extension.ex#L1 "View Source") AshSqlite.CustomExtension behaviour (ash\_sqlite v0.2.3)
 125 | 
 126 | A custom extension implementation.
 127 | 
 128 | # [](AshSqlite.CustomExtension.html#summary)Summary
 129 | 
 130 | ## [Callbacks](AshSqlite.CustomExtension.html#callbacks)
 131 | 
 132 | [install(version)](AshSqlite.CustomExtension.html#c:install/1)
 133 | 
 134 | [uninstall(version)](AshSqlite.CustomExtension.html#c:uninstall/1)
 135 | 
 136 | # [](AshSqlite.CustomExtension.html#callbacks)Callbacks
 137 | 
 138 | [](AshSqlite.CustomExtension.html#c:install/1)
 139 | 
 140 | # install(version)
 141 | 
 142 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/custom_extension.ex#L6)
 143 | 
 144 | ```
 145 | @callback install(version :: integer()) :: String.t()
 146 | ```
 147 | 
 148 | [](AshSqlite.CustomExtension.html#c:uninstall/1)
 149 | 
 150 | # uninstall(version)
 151 | 
 152 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/custom_extension.ex#L8)
 153 | 
 154 | ```
 155 | @callback uninstall(version :: integer()) :: String.t()
 156 | ```
 157 | 
 158 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
 159 | 
 160 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
 161 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
 162 | 
 163 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
 164 | 
 165 | v0.2.3
 166 | 
 167 | - Pages
 168 | - Modules
 169 | - Mix Tasks
 170 | 
 171 | <!--THE END-->
 172 | 
 173 | <!--THE END-->
 174 | 
 175 | <!--THE END-->
 176 | 
 177 | Search documentation of ash\_sqlite
 178 | 
 179 | Settings
 180 | 
 181 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/custom_index.ex#L1 "View Source") AshSqlite.CustomIndex (ash\_sqlite v0.2.3)
 182 | 
 183 | Represents a custom index on the table backing a resource
 184 | 
 185 | # [](AshSqlite.CustomIndex.html#summary)Summary
 186 | 
 187 | ## [Functions](AshSqlite.CustomIndex.html#functions)
 188 | 
 189 | [fields()](AshSqlite.CustomIndex.html#fields/0)
 190 | 
 191 | [name(table, map)](AshSqlite.CustomIndex.html#name/2)
 192 | 
 193 | [schema()](AshSqlite.CustomIndex.html#schema/0)
 194 | 
 195 | [transform(index)](AshSqlite.CustomIndex.html#transform/1)
 196 | 
 197 | # [](AshSqlite.CustomIndex.html#functions)Functions
 198 | 
 199 | [](AshSqlite.CustomIndex.html#fields/0)
 200 | 
 201 | # fields()
 202 | 
 203 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/custom_index.ex#L16)
 204 | 
 205 | [](AshSqlite.CustomIndex.html#name/2)
 206 | 
 207 | # name(table, map)
 208 | 
 209 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/custom_index.ex#L96)
 210 | 
 211 | [](AshSqlite.CustomIndex.html#schema/0)
 212 | 
 213 | # schema()
 214 | 
 215 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/custom_index.ex#L51)
 216 | 
 217 | [](AshSqlite.CustomIndex.html#transform/1)
 218 | 
 219 | # transform(index)
 220 | 
 221 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/custom_index.ex#L54)
 222 | 
 223 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
 224 | 
 225 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
 226 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
 227 | 
 228 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
 229 | 
 230 | v0.2.3
 231 | 
 232 | - Pages
 233 | - Modules
 234 | - Mix Tasks
 235 | 
 236 | <!--THE END-->
 237 | 
 238 | <!--THE END-->
 239 | 
 240 | <!--THE END-->
 241 | 
 242 | Search documentation of ash\_sqlite
 243 | 
 244 | Settings
 245 | 
 246 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer.ex#L1 "View Source") AshSqlite.DataLayer (ash\_sqlite v0.2.3)
 247 | 
 248 | A sqlite data layer that leverages Ecto's sqlite capabilities.
 249 | 
 250 | # [](AshSqlite.DataLayer.html#summary)Summary
 251 | 
 252 | ## [Functions](AshSqlite.DataLayer.html#functions)
 253 | 
 254 | [add\_known\_binding(query, data, known\_binding)](AshSqlite.DataLayer.html#add_known_binding/3)
 255 | 
 256 | [codegen(args)](AshSqlite.DataLayer.html#codegen/1)
 257 | 
 258 | [from\_ecto(other)](AshSqlite.DataLayer.html#from_ecto/1)
 259 | 
 260 | [install(igniter, \_, \_, \_)](AshSqlite.DataLayer.html#install/4)
 261 | 
 262 | [install(igniter, module, arg, path, argv)](AshSqlite.DataLayer.html#install/5)
 263 | 
 264 | [migrate(args)](AshSqlite.DataLayer.html#migrate/1)
 265 | 
 266 | [rollback(args)](AshSqlite.DataLayer.html#rollback/1)
 267 | 
 268 | [setup(args)](AshSqlite.DataLayer.html#setup/1)
 269 | 
 270 | [sqlite(body)](AshSqlite.DataLayer.html#sqlite/1)
 271 | 
 272 | [tear\_down(args)](AshSqlite.DataLayer.html#tear_down/1)
 273 | 
 274 | [to\_ecto(value)](AshSqlite.DataLayer.html#to_ecto/1)
 275 | 
 276 | # [](AshSqlite.DataLayer.html#functions)Functions
 277 | 
 278 | [](AshSqlite.DataLayer.html#add_known_binding/3)
 279 | 
 280 | # add\_known\_binding(query, data, known\_binding)
 281 | 
 282 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer.ex#L1496)
 283 | 
 284 | [](AshSqlite.DataLayer.html#codegen/1)
 285 | 
 286 | # codegen(args)
 287 | 
 288 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer.ex#L393)
 289 | 
 290 | [](AshSqlite.DataLayer.html#from_ecto/1)
 291 | 
 292 | # from\_ecto(other)
 293 | 
 294 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer.ex#L1005)
 295 | 
 296 | [](AshSqlite.DataLayer.html#install/4)
 297 | 
 298 | # install(igniter, \_, \_, \_)
 299 | 
 300 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer.ex#L390)
 301 | 
 302 | [](AshSqlite.DataLayer.html#install/5)
 303 | 
 304 | # install(igniter, module, arg, path, argv)
 305 | 
 306 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer.ex#L366)
 307 | 
 308 | [](AshSqlite.DataLayer.html#migrate/1)
 309 | 
 310 | # migrate(args)
 311 | 
 312 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer.ex#L301)
 313 | 
 314 | [](AshSqlite.DataLayer.html#rollback/1)
 315 | 
 316 | # rollback(args)
 317 | 
 318 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer.ex#L306)
 319 | 
 320 | [](AshSqlite.DataLayer.html#setup/1)
 321 | 
 322 | # setup(args)
 323 | 
 324 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer.ex#L398)
 325 | 
 326 | [](AshSqlite.DataLayer.html#sqlite/1)
 327 | 
 328 | # sqlite(body)
 329 | 
 330 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer.ex#L293)(macro)
 331 | 
 332 | [](AshSqlite.DataLayer.html#tear_down/1)
 333 | 
 334 | # tear\_down(args)
 335 | 
 336 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer.ex#L404)
 337 | 
 338 | [](AshSqlite.DataLayer.html#to_ecto/1)
 339 | 
 340 | # to\_ecto(value)
 341 | 
 342 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer.ex#L1036)
 343 | 
 344 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
 345 | 
 346 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
 347 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
 348 | 
 349 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
 350 | 
 351 | v0.2.3
 352 | 
 353 | - Pages
 354 | - Modules
 355 | - Mix Tasks
 356 | 
 357 | <!--THE END-->
 358 | 
 359 | <!--THE END-->
 360 | 
 361 | <!--THE END-->
 362 | 
 363 | Search documentation of ash\_sqlite
 364 | 
 365 | Settings
 366 | 
 367 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L1 "View Source") AshSqlite.DataLayer.Info (ash\_sqlite v0.2.3)
 368 | 
 369 | Introspection functions for
 370 | 
 371 | # [](AshSqlite.DataLayer.Info.html#summary)Summary
 372 | 
 373 | ## [Functions](AshSqlite.DataLayer.Info.html#functions)
 374 | 
 375 | [base\_filter\_sql(resource)](AshSqlite.DataLayer.Info.html#base_filter_sql/1)
 376 | 
 377 | A stringified version of the base\_filter, to be used in a where clause when generating unique indexes
 378 | 
 379 | [custom\_indexes(resource)](AshSqlite.DataLayer.Info.html#custom_indexes/1)
 380 | 
 381 | The configured custom\_indexes for a resource
 382 | 
 383 | [custom\_statements(resource)](AshSqlite.DataLayer.Info.html#custom_statements/1)
 384 | 
 385 | The configured custom\_statements for a resource
 386 | 
 387 | [exclusion\_constraint\_names(resource)](AshSqlite.DataLayer.Info.html#exclusion_constraint_names/1)
 388 | 
 389 | The configured exclusion\_constraint\_names
 390 | 
 391 | [foreign\_key\_names(resource)](AshSqlite.DataLayer.Info.html#foreign_key_names/1)
 392 | 
 393 | The configured foreign\_key\_names
 394 | 
 395 | [global\_upsert\_keys(resource)](AshSqlite.DataLayer.Info.html#global_upsert_keys/1)
 396 | 
 397 | A list of keys to always include in upserts.
 398 | 
 399 | [identity\_index\_names(resource)](AshSqlite.DataLayer.Info.html#identity_index_names/1)
 400 | 
 401 | The configured identity\_index\_names
 402 | 
 403 | [migrate?(resource)](AshSqlite.DataLayer.Info.html#migrate?/1)
 404 | 
 405 | Whether or not the resource should be included when generating migrations
 406 | 
 407 | [migration\_defaults(resource)](AshSqlite.DataLayer.Info.html#migration_defaults/1)
 408 | 
 409 | A keyword list of customized migration defaults
 410 | 
 411 | [migration\_ignore\_attributes(resource)](AshSqlite.DataLayer.Info.html#migration_ignore_attributes/1)
 412 | 
 413 | A list of attributes to be ignored when generating migrations
 414 | 
 415 | [migration\_types(resource)](AshSqlite.DataLayer.Info.html#migration_types/1)
 416 | 
 417 | A keyword list of customized migration types
 418 | 
 419 | [polymorphic?(resource)](AshSqlite.DataLayer.Info.html#polymorphic?/1)
 420 | 
 421 | The configured polymorphic? for a resource
 422 | 
 423 | [polymorphic\_name(resource)](AshSqlite.DataLayer.Info.html#polymorphic_name/1)
 424 | 
 425 | The configured polymorphic\_reference\_name for a resource
 426 | 
 427 | [polymorphic\_on\_delete(resource)](AshSqlite.DataLayer.Info.html#polymorphic_on_delete/1)
 428 | 
 429 | The configured polymorphic\_reference\_on\_delete for a resource
 430 | 
 431 | [polymorphic\_on\_update(resource)](AshSqlite.DataLayer.Info.html#polymorphic_on_update/1)
 432 | 
 433 | The configured polymorphic\_reference\_on\_update for a resource
 434 | 
 435 | [reference(resource, relationship)](AshSqlite.DataLayer.Info.html#reference/2)
 436 | 
 437 | The configured reference for a given relationship of a resource
 438 | 
 439 | [references(resource)](AshSqlite.DataLayer.Info.html#references/1)
 440 | 
 441 | The configured references for a resource
 442 | 
 443 | [repo(resource)](AshSqlite.DataLayer.Info.html#repo/1)
 444 | 
 445 | The configured repo for a resource
 446 | 
 447 | [skip\_identities(resource)](AshSqlite.DataLayer.Info.html#skip_identities/1)
 448 | 
 449 | Identities not to include in the migrations
 450 | 
 451 | [skip\_unique\_indexes(resource)](AshSqlite.DataLayer.Info.html#skip_unique_indexes/1)
 452 | 
 453 | Skip generating unique indexes when generating migrations
 454 | 
 455 | [table(resource)](AshSqlite.DataLayer.Info.html#table/1)
 456 | 
 457 | The configured table for a resource
 458 | 
 459 | [unique\_index\_names(resource)](AshSqlite.DataLayer.Info.html#unique_index_names/1)
 460 | 
 461 | The configured unique\_index\_names
 462 | 
 463 | # [](AshSqlite.DataLayer.Info.html#functions)Functions
 464 | 
 465 | [](AshSqlite.DataLayer.Info.html#base_filter_sql/1)
 466 | 
 467 | # base\_filter\_sql(resource)
 468 | 
 469 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L109)
 470 | 
 471 | A stringified version of the base\_filter, to be used in a where clause when generating unique indexes
 472 | 
 473 | [](AshSqlite.DataLayer.Info.html#custom_indexes/1)
 474 | 
 475 | # custom\_indexes(resource)
 476 | 
 477 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L44)
 478 | 
 479 | The configured custom\_indexes for a resource
 480 | 
 481 | [](AshSqlite.DataLayer.Info.html#custom_statements/1)
 482 | 
 483 | # custom\_statements(resource)
 484 | 
 485 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L49)
 486 | 
 487 | The configured custom\_statements for a resource
 488 | 
 489 | [](AshSqlite.DataLayer.Info.html#exclusion_constraint_names/1)
 490 | 
 491 | # exclusion\_constraint\_names(resource)
 492 | 
 493 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L79)
 494 | 
 495 | The configured exclusion\_constraint\_names
 496 | 
 497 | [](AshSqlite.DataLayer.Info.html#foreign_key_names/1)
 498 | 
 499 | # foreign\_key\_names(resource)
 500 | 
 501 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L94)
 502 | 
 503 | The configured foreign\_key\_names
 504 | 
 505 | [](AshSqlite.DataLayer.Info.html#global_upsert_keys/1)
 506 | 
 507 | # global\_upsert\_keys(resource)
 508 | 
 509 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L104)
 510 | 
 511 | A list of keys to always include in upserts.
 512 | 
 513 | [](AshSqlite.DataLayer.Info.html#identity_index_names/1)
 514 | 
 515 | # identity\_index\_names(resource)
 516 | 
 517 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L84)
 518 | 
 519 | The configured identity\_index\_names
 520 | 
 521 | [](AshSqlite.DataLayer.Info.html#migrate?/1)
 522 | 
 523 | # migrate?(resource)
 524 | 
 525 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L99)
 526 | 
 527 | Whether or not the resource should be included when generating migrations
 528 | 
 529 | [](AshSqlite.DataLayer.Info.html#migration_defaults/1)
 530 | 
 531 | # migration\_defaults(resource)
 532 | 
 533 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L34)
 534 | 
 535 | A keyword list of customized migration defaults
 536 | 
 537 | [](AshSqlite.DataLayer.Info.html#migration_ignore_attributes/1)
 538 | 
 539 | # migration\_ignore\_attributes(resource)
 540 | 
 541 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L39)
 542 | 
 543 | A list of attributes to be ignored when generating migrations
 544 | 
 545 | [](AshSqlite.DataLayer.Info.html#migration_types/1)
 546 | 
 547 | # migration\_types(resource)
 548 | 
 549 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L29)
 550 | 
 551 | A keyword list of customized migration types
 552 | 
 553 | [](AshSqlite.DataLayer.Info.html#polymorphic?/1)
 554 | 
 555 | # polymorphic?(resource)
 556 | 
 557 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L69)
 558 | 
 559 | The configured polymorphic? for a resource
 560 | 
 561 | [](AshSqlite.DataLayer.Info.html#polymorphic_name/1)
 562 | 
 563 | # polymorphic\_name(resource)
 564 | 
 565 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L64)
 566 | 
 567 | The configured polymorphic\_reference\_name for a resource
 568 | 
 569 | [](AshSqlite.DataLayer.Info.html#polymorphic_on_delete/1)
 570 | 
 571 | # polymorphic\_on\_delete(resource)
 572 | 
 573 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L54)
 574 | 
 575 | The configured polymorphic\_reference\_on\_delete for a resource
 576 | 
 577 | [](AshSqlite.DataLayer.Info.html#polymorphic_on_update/1)
 578 | 
 579 | # polymorphic\_on\_update(resource)
 580 | 
 581 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L59)
 582 | 
 583 | The configured polymorphic\_reference\_on\_update for a resource
 584 | 
 585 | [](AshSqlite.DataLayer.Info.html#reference/2)
 586 | 
 587 | # reference(resource, relationship)
 588 | 
 589 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L22)
 590 | 
 591 | The configured reference for a given relationship of a resource
 592 | 
 593 | [](AshSqlite.DataLayer.Info.html#references/1)
 594 | 
 595 | # references(resource)
 596 | 
 597 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L17)
 598 | 
 599 | The configured references for a resource
 600 | 
 601 | [](AshSqlite.DataLayer.Info.html#repo/1)
 602 | 
 603 | # repo(resource)
 604 | 
 605 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L7)
 606 | 
 607 | The configured repo for a resource
 608 | 
 609 | [](AshSqlite.DataLayer.Info.html#skip_identities/1)
 610 | 
 611 | # skip\_identities(resource)
 612 | 
 613 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L89)
 614 | 
 615 | Identities not to include in the migrations
 616 | 
 617 | [](AshSqlite.DataLayer.Info.html#skip_unique_indexes/1)
 618 | 
 619 | # skip\_unique\_indexes(resource)
 620 | 
 621 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L114)
 622 | 
 623 | Skip generating unique indexes when generating migrations
 624 | 
 625 | [](AshSqlite.DataLayer.Info.html#table/1)
 626 | 
 627 | # table(resource)
 628 | 
 629 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L12)
 630 | 
 631 | The configured table for a resource
 632 | 
 633 | [](AshSqlite.DataLayer.Info.html#unique_index_names/1)
 634 | 
 635 | # unique\_index\_names(resource)
 636 | 
 637 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/data_layer/info.ex#L74)
 638 | 
 639 | The configured unique\_index\_names
 640 | 
 641 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
 642 | 
 643 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
 644 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
 645 | 
 646 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
 647 | 
 648 | v0.2.3
 649 | 
 650 | - Pages
 651 | - Modules
 652 | - Mix Tasks
 653 | 
 654 | <!--THE END-->
 655 | 
 656 | <!--THE END-->
 657 | 
 658 | <!--THE END-->
 659 | 
 660 | Search documentation of ash\_sqlite
 661 | 
 662 | Settings
 663 | 
 664 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/functions/ilike.ex#L1 "View Source") AshSqlite.Functions.ILike (ash\_sqlite v0.2.3)
 665 | 
 666 | Maps to the builtin sqlite function `ilike`.
 667 | 
 668 | # [](AshSqlite.Functions.ILike.html#summary)Summary
 669 | 
 670 | ## [Functions](AshSqlite.Functions.ILike.html#functions)
 671 | 
 672 | [args()](AshSqlite.Functions.ILike.html#args/0)
 673 | 
 674 | Callback implementation for [`Ash.Query.Function.args/0`](../ash/3.4.58/Ash.Query.Function.html#c:args/0).
 675 | 
 676 | # [](AshSqlite.Functions.ILike.html#functions)Functions
 677 | 
 678 | [](AshSqlite.Functions.ILike.html#args/0)
 679 | 
 680 | # args()
 681 | 
 682 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/functions/ilike.ex#L8)
 683 | 
 684 | Callback implementation for [`Ash.Query.Function.args/0`](../ash/3.4.58/Ash.Query.Function.html#c:args/0).
 685 | 
 686 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
 687 | 
 688 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
 689 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
 690 | 
 691 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
 692 | 
 693 | v0.2.3
 694 | 
 695 | - Pages
 696 | - Modules
 697 | - Mix Tasks
 698 | 
 699 | <!--THE END-->
 700 | 
 701 | <!--THE END-->
 702 | 
 703 | <!--THE END-->
 704 | 
 705 | Search documentation of ash\_sqlite
 706 | 
 707 | Settings
 708 | 
 709 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/functions/like.ex#L1 "View Source") AshSqlite.Functions.Like (ash\_sqlite v0.2.3)
 710 | 
 711 | Maps to the builtin sqlite function `like`.
 712 | 
 713 | # [](AshSqlite.Functions.Like.html#summary)Summary
 714 | 
 715 | ## [Functions](AshSqlite.Functions.Like.html#functions)
 716 | 
 717 | [args()](AshSqlite.Functions.Like.html#args/0)
 718 | 
 719 | Callback implementation for [`Ash.Query.Function.args/0`](../ash/3.4.58/Ash.Query.Function.html#c:args/0).
 720 | 
 721 | # [](AshSqlite.Functions.Like.html#functions)Functions
 722 | 
 723 | [](AshSqlite.Functions.Like.html#args/0)
 724 | 
 725 | # args()
 726 | 
 727 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/functions/like.ex#L8)
 728 | 
 729 | Callback implementation for [`Ash.Query.Function.args/0`](../ash/3.4.58/Ash.Query.Function.html#c:args/0).
 730 | 
 731 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
 732 | 
 733 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
 734 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
 735 | 
 736 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
 737 | 
 738 | v0.2.3
 739 | 
 740 | - Pages
 741 | - Modules
 742 | - Mix Tasks
 743 | 
 744 | <!--THE END-->
 745 | 
 746 | <!--THE END-->
 747 | 
 748 | <!--THE END-->
 749 | 
 750 | Search documentation of ash\_sqlite
 751 | 
 752 | Settings
 753 | 
 754 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/ash_sqlite.ex#L1 "View Source") AshSqlite (ash\_sqlite v0.2.3)
 755 | 
 756 | The AshSqlite extension gives you tools to map a resource to a sqlite database table.
 757 | 
 758 | For more, check out the [getting started guide](getting-started-with-ash-sqlite.html)
 759 | 
 760 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
 761 | 
 762 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
 763 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
 764 | 
 765 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
 766 | 
 767 | v0.2.3
 768 | 
 769 | - Pages
 770 | - Modules
 771 | - Mix Tasks
 772 | 
 773 | <!--THE END-->
 774 | 
 775 | <!--THE END-->
 776 | 
 777 | <!--THE END-->
 778 | 
 779 | Search documentation of ash\_sqlite
 780 | 
 781 | Settings
 782 | 
 783 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/manual_relationship.ex#L1 "View Source") AshSqlite.ManualRelationship behaviour (ash\_sqlite v0.2.3)
 784 | 
 785 | A behavior for sqlite-specific manual relationship functionality
 786 | 
 787 | # [](AshSqlite.ManualRelationship.html#summary)Summary
 788 | 
 789 | ## [Callbacks](AshSqlite.ManualRelationship.html#callbacks)
 790 | 
 791 | [ash\_sqlite\_join(source\_query, opts, current\_binding, destination\_binding, type, destination\_query)](AshSqlite.ManualRelationship.html#c:ash_sqlite_join/6)
 792 | 
 793 | [ash\_sqlite\_subquery(opts, current\_binding, destination\_binding, destination\_query)](AshSqlite.ManualRelationship.html#c:ash_sqlite_subquery/4)
 794 | 
 795 | # [](AshSqlite.ManualRelationship.html#callbacks)Callbacks
 796 | 
 797 | [](AshSqlite.ManualRelationship.html#c:ash_sqlite_join/6)
 798 | 
 799 | # ash\_sqlite\_join(source\_query, opts, current\_binding, destination\_binding, type, destination\_query)
 800 | 
 801 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/manual_relationship.ex#L4)
 802 | 
 803 | ```
 804 | @callback ash_sqlite_join(
 805 |   source_query :: Ecto.Query.t(),
 806 |   opts :: Keyword.t(),
 807 |   current_binding :: term(),
 808 |   destination_binding :: term(),
 809 |   type :: :inner | :left,
 810 |   destination_query :: Ecto.Query.t()
 811 | ) :: {:ok, Ecto.Query.t()} | {:error, term()}
 812 | ```
 813 | 
 814 | [](AshSqlite.ManualRelationship.html#c:ash_sqlite_subquery/4)
 815 | 
 816 | # ash\_sqlite\_subquery(opts, current\_binding, destination\_binding, destination\_query)
 817 | 
 818 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/manual_relationship.ex#L13)
 819 | 
 820 | ```
 821 | @callback ash_sqlite_subquery(
 822 |   opts :: Keyword.t(),
 823 |   current_binding :: term(),
 824 |   destination_binding :: term(),
 825 |   destination_query :: Ecto.Query.t()
 826 | ) :: {:ok, Ecto.Query.t()} | {:error, term()}
 827 | ```
 828 | 
 829 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
 830 | 
 831 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
 832 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
 833 | 
 834 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
 835 | 
 836 | v0.2.3
 837 | 
 838 | - Pages
 839 | - Modules
 840 | - Mix Tasks
 841 | 
 842 | <!--THE END-->
 843 | 
 844 | <!--THE END-->
 845 | 
 846 | <!--THE END-->
 847 | 
 848 | Search documentation of ash\_sqlite
 849 | 
 850 | Settings
 851 | 
 852 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/reference.ex#L1 "View Source") AshSqlite.Reference (ash\_sqlite v0.2.3)
 853 | 
 854 | Represents the configuration of a reference (i.e foreign key).
 855 | 
 856 | # [](AshSqlite.Reference.html#summary)Summary
 857 | 
 858 | ## [Functions](AshSqlite.Reference.html#functions)
 859 | 
 860 | [schema()](AshSqlite.Reference.html#schema/0)
 861 | 
 862 | # [](AshSqlite.Reference.html#functions)Functions
 863 | 
 864 | [](AshSqlite.Reference.html#schema/0)
 865 | 
 866 | # schema()
 867 | 
 868 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/reference.ex#L5)
 869 | 
 870 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
 871 | 
 872 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
 873 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
 874 | 
 875 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
 876 | 
 877 | v0.2.3
 878 | 
 879 | - Pages
 880 | - Modules
 881 | - Mix Tasks
 882 | 
 883 | <!--THE END-->
 884 | 
 885 | <!--THE END-->
 886 | 
 887 | <!--THE END-->
 888 | 
 889 | Search documentation of ash\_sqlite
 890 | 
 891 | Settings
 892 | 
 893 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/repo.ex#L1 "View Source") AshSqlite.Repo behaviour (ash\_sqlite v0.2.3)
 894 | 
 895 | Resources that use [`AshSqlite.DataLayer`](AshSqlite.DataLayer.html) use a `Repo` to access the database.
 896 | 
 897 | This repo is a thin wrapper around an [`Ecto.Repo`](../ecto/3.12.5/Ecto.Repo.html).
 898 | 
 899 | You can use [`Ecto.Repo`](../ecto/3.12.5/Ecto.Repo.html)'s `init/2` to configure your repo like normal, but instead of returning `{:ok, config}`, use `super(config)` to pass the configuration to the [`AshSqlite.Repo`](AshSqlite.Repo.html) implementation.
 900 | 
 901 | ## [](AshSqlite.Repo.html#module-additional-repo-configuration)Additional Repo Configuration
 902 | 
 903 | Because an `AshPostgres.Repo` is also an [`Ecto.Repo`](../ecto/3.12.5/Ecto.Repo.html), it has all of the same callbacks.
 904 | 
 905 | In the [`Ecto.Repo.init/2`](../ecto/3.12.5/Ecto.Repo.html#c:init/2) callback, you can configure the following additional items:
 906 | 
 907 | - `:tenant_migrations_path` - The path where your tenant migrations are stored (only relevant for a multitenant implementation)
 908 | - `:snapshots_path` - The path where the resource snapshots for the migration generator are stored.
 909 | 
 910 | # [](AshSqlite.Repo.html#summary)Summary
 911 | 
 912 | ## [Callbacks](AshSqlite.Repo.html#callbacks)
 913 | 
 914 | [installed\_extensions()](AshSqlite.Repo.html#c:installed_extensions/0)
 915 | 
 916 | Use this to inform the data layer about what extensions are installed
 917 | 
 918 | [migrations\_path()](AshSqlite.Repo.html#c:migrations_path/0)
 919 | 
 920 | The path where your migrations are stored
 921 | 
 922 | [min\_pg\_version()](AshSqlite.Repo.html#c:min_pg_version/0)
 923 | 
 924 | Use this to inform the data layer about the oldest potential sqlite version it will be run on.
 925 | 
 926 | [override\_migration\_type(atom)](AshSqlite.Repo.html#c:override_migration_type/1)
 927 | 
 928 | Allows overriding a given migration type for *all* fields, for example if you wanted to always use :timestamptz for :utc\_datetime fields
 929 | 
 930 | # [](AshSqlite.Repo.html#callbacks)Callbacks
 931 | 
 932 | [](AshSqlite.Repo.html#c:installed_extensions/0)
 933 | 
 934 | # installed\_extensions()
 935 | 
 936 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/repo.ex#L22)
 937 | 
 938 | ```
 939 | @callback installed_extensions() :: [String.t()]
 940 | ```
 941 | 
 942 | Use this to inform the data layer about what extensions are installed
 943 | 
 944 | [](AshSqlite.Repo.html#c:migrations_path/0)
 945 | 
 946 | # migrations\_path()
 947 | 
 948 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/repo.ex#L32)
 949 | 
 950 | ```
 951 | @callback migrations_path() :: String.t() | nil
 952 | ```
 953 | 
 954 | The path where your migrations are stored
 955 | 
 956 | [](AshSqlite.Repo.html#c:min_pg_version/0)
 957 | 
 958 | # min\_pg\_version()
 959 | 
 960 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/repo.ex#L29)
 961 | 
 962 | ```
 963 | @callback min_pg_version() :: integer()
 964 | ```
 965 | 
 966 | Use this to inform the data layer about the oldest potential sqlite version it will be run on.
 967 | 
 968 | Must be an integer greater than or equal to 13.
 969 | 
 970 | [](AshSqlite.Repo.html#c:override_migration_type/1)
 971 | 
 972 | # override\_migration\_type(atom)
 973 | 
 974 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/repo.ex#L34)
 975 | 
 976 | ```
 977 | @callback override_migration_type(atom()) :: atom()
 978 | ```
 979 | 
 980 | Allows overriding a given migration type for *all* fields, for example if you wanted to always use :timestamptz for :utc\_datetime fields
 981 | 
 982 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
 983 | 
 984 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
 985 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
 986 | 
 987 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
 988 | 
 989 | v0.2.3
 990 | 
 991 | - Pages
 992 | - Modules
 993 | - Mix Tasks
 994 | 
 995 | <!--THE END-->
 996 | 
 997 | <!--THE END-->
 998 | 
 999 | <!--THE END-->
1000 | 
1001 | Search documentation of ash\_sqlite
1002 | 
1003 | Settings
1004 | 
1005 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/statement.ex#L1 "View Source") AshSqlite.Statement (ash\_sqlite v0.2.3)
1006 | 
1007 | Represents a custom statement to be run in generated migrations
1008 | 
1009 | # [](AshSqlite.Statement.html#summary)Summary
1010 | 
1011 | ## [Functions](AshSqlite.Statement.html#functions)
1012 | 
1013 | [fields()](AshSqlite.Statement.html#fields/0)
1014 | 
1015 | [schema()](AshSqlite.Statement.html#schema/0)
1016 | 
1017 | # [](AshSqlite.Statement.html#functions)Functions
1018 | 
1019 | [](AshSqlite.Statement.html#fields/0)
1020 | 
1021 | # fields()
1022 | 
1023 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/statement.ex#L13)
1024 | 
1025 | [](AshSqlite.Statement.html#schema/0)
1026 | 
1027 | # schema()
1028 | 
1029 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/statement.ex#L44)
1030 | 
1031 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
1032 | 
1033 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1034 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
1035 | 
1036 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
1037 | 
1038 | v0.2.3
1039 | 
1040 | - Pages
1041 | - Modules
1042 | - Mix Tasks
1043 | 
1044 | <!--THE END-->
1045 | 
1046 | <!--THE END-->
1047 | 
1048 | <!--THE END-->
1049 | 
1050 | Search documentation of ash\_sqlite
1051 | 
1052 | Settings
1053 | 
1054 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/type.ex#L1 "View Source") AshSqlite.Type behaviour (ash\_sqlite v0.2.3)
1055 | 
1056 | Sqlite specific callbacks for [`Ash.Type`](../ash/3.4.58/Ash.Type.html).
1057 | 
1058 | Use this in addition to [`Ash.Type`](../ash/3.4.58/Ash.Type.html).
1059 | 
1060 | # [](AshSqlite.Type.html#summary)Summary
1061 | 
1062 | ## [Callbacks](AshSqlite.Type.html#callbacks)
1063 | 
1064 | [value\_to\_sqlite\_default(t, constraints, term)](AshSqlite.Type.html#c:value_to_sqlite_default/3)
1065 | 
1066 | # [](AshSqlite.Type.html#callbacks)Callbacks
1067 | 
1068 | [](AshSqlite.Type.html#c:value_to_sqlite_default/3)
1069 | 
1070 | # value\_to\_sqlite\_default(t, constraints, term)
1071 | 
1072 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/type.ex#L8)
1073 | 
1074 | ```
1075 | @callback value_to_sqlite_default(Ash.Type.t(), Ash.Type.constraints(), term()) ::
1076 |   {:ok, String.t()} | :error
1077 | ```
1078 | 
1079 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
1080 | 
1081 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1082 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
1083 | 
1084 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
1085 | 
1086 | v0.2.3
1087 | 
1088 | - Pages
1089 | - Modules
1090 | - Mix Tasks
1091 | 
1092 | <!--THE END-->
1093 | 
1094 | <!--THE END-->
1095 | 
1096 | <!--THE END-->
1097 | 
1098 | Search documentation of ash\_sqlite
1099 | 
1100 | Settings
1101 | 
1102 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/documentation/dsls/DSL-AshSqlite.DataLayer.md#L1 "View Source") AshSqlite.DataLayer
1103 | 
1104 | A sqlite data layer that leverages Ecto's sqlite capabilities.
1105 | 
1106 | ## [](dsl-ashsqlite-datalayer.html#sqlite)sqlite
1107 | 
1108 | Sqlite data layer configuration
1109 | 
1110 | ### [](dsl-ashsqlite-datalayer.html#nested-dsls)Nested DSLs
1111 | 
1112 | - [custom\_indexes](dsl-ashsqlite-datalayer.html#sqlite-custom_indexes)
1113 |   
1114 |   - index
1115 | - [custom\_statements](dsl-ashsqlite-datalayer.html#sqlite-custom_statements)
1116 |   
1117 |   - statement
1118 | - [references](dsl-ashsqlite-datalayer.html#sqlite-references)
1119 |   
1120 |   - reference
1121 | 
1122 | ### [](dsl-ashsqlite-datalayer.html#examples)Examples
1123 | 
1124 | ```
1125 | sqlite do
1126 |   repo MyApp.Repo
1127 |   table "organizations"
1128 | end
1129 | ```
1130 | 
1131 | ### [](dsl-ashsqlite-datalayer.html#options)Options
1132 | 
1133 | NameTypeDefaultDocs[`repo`](dsl-ashsqlite-datalayer.html#sqlite-repo)`atom`The repo that will be used to fetch your data. See the [`AshSqlite.Repo`](AshSqlite.Repo.html) documentation for more[`migrate?`](dsl-ashsqlite-datalayer.html#sqlite-migrate?)`boolean``true`Whether or not to include this resource in the generated migrations with `mix ash.generate_migrations`[`migration_types`](dsl-ashsqlite-datalayer.html#sqlite-migration_types)`keyword``[]`A keyword list of attribute names to the ecto migration type that should be used for that attribute. Only necessary if you need to override the defaults.[`migration_defaults`](dsl-ashsqlite-datalayer.html#sqlite-migration_defaults)`keyword``[]`A keyword list of attribute names to the ecto migration default that should be used for that attribute. The string you use will be placed verbatim in the migration. Use fragments like `fragment(\\"now()\\")`, or for `nil`, use `\\"nil\\"`.[`base_filter_sql`](dsl-ashsqlite-datalayer.html#sqlite-base_filter_sql)`String.t`A raw sql version of the base\_filter, e.g `representative = true`. Required if trying to create a unique constraint on a resource with a base\_filter[`skip_unique_indexes`](dsl-ashsqlite-datalayer.html#sqlite-skip_unique_indexes)`atom | list(atom)``false`Skip generating unique indexes when generating migrations[`unique_index_names`](dsl-ashsqlite-datalayer.html#sqlite-unique_index_names)`list({list(atom), String.t} | {list(atom), String.t, String.t})``[]`A list of unique index names that could raise errors that are not configured in identities, or an mfa to a function that takes a changeset and returns the list. In the format `{[:affected, :keys], "name_of_constraint"}` or `{[:affected, :keys], "name_of_constraint", "custom error message"}`[`exclusion_constraint_names`](dsl-ashsqlite-datalayer.html#sqlite-exclusion_constraint_names)`any``[]`A list of exclusion constraint names that could raise errors. Must be in the format `{:affected_key, "name_of_constraint"}` or `{:affected_key, "name_of_constraint", "custom error message"}`[`identity_index_names`](dsl-ashsqlite-datalayer.html#sqlite-identity_index_names)`any``[]`A keyword list of identity names to the unique index name that they should use when being managed by the migration generator.[`foreign_key_names`](dsl-ashsqlite-datalayer.html#sqlite-foreign_key_names)`list({atom, String.t} | {String.t, String.t})``[]`A list of foreign keys that could raise errors, or an mfa to a function that takes a changeset and returns a list. In the format: `{:key, "name_of_constraint"}` or `{:key, "name_of_constraint", "custom error message"}`[`migration_ignore_attributes`](dsl-ashsqlite-datalayer.html#sqlite-migration_ignore_attributes)`list(atom)``[]`A list of attributes that will be ignored when generating migrations.[`table`](dsl-ashsqlite-datalayer.html#sqlite-table)`String.t`The table to store and read the resource from. If this is changed, the migration generator will not remove the old table.[`polymorphic?`](dsl-ashsqlite-datalayer.html#sqlite-polymorphic?)`boolean``false`Declares this resource as polymorphic. See the [polymorphic resources guide](polymorphic-resources.html) for more.
1134 | 
1135 | ### [](dsl-ashsqlite-datalayer.html#sqlite-custom_indexes)sqlite.custom\_indexes
1136 | 
1137 | A section for configuring indexes to be created by the migration generator.
1138 | 
1139 | In general, prefer to use `identities` for simple unique constraints. This is a tool to allow for declaring more complex indexes.
1140 | 
1141 | ### [](dsl-ashsqlite-datalayer.html#nested-dsls-1)Nested DSLs
1142 | 
1143 | - [index](dsl-ashsqlite-datalayer.html#sqlite-custom_indexes-index)
1144 | 
1145 | ### [](dsl-ashsqlite-datalayer.html#examples-1)Examples
1146 | 
1147 | ```
1148 | custom_indexes do
1149 |   index [:column1, :column2], unique: true, where: "thing = TRUE"
1150 | end
1151 | ```
1152 | 
1153 | ### [](dsl-ashsqlite-datalayer.html#sqlite-custom_indexes-index)sqlite.custom\_indexes.index
1154 | 
1155 | ```
1156 | index fields
1157 | ```
1158 | 
1159 | Add an index to be managed by the migration generator.
1160 | 
1161 | ### [](dsl-ashsqlite-datalayer.html#examples-2)Examples
1162 | 
1163 | ```
1164 | index ["column", "column2"], unique: true, where: "thing = TRUE"
1165 | ```
1166 | 
1167 | ### [](dsl-ashsqlite-datalayer.html#arguments)Arguments
1168 | 
1169 | NameTypeDefaultDocs[`fields`](dsl-ashsqlite-datalayer.html#sqlite-custom_indexes-index-fields)`atom | String.t | list(atom | String.t)`The fields to include in the index.
1170 | 
1171 | ### [](dsl-ashsqlite-datalayer.html#options-1)Options
1172 | 
1173 | NameTypeDefaultDocs[`name`](dsl-ashsqlite-datalayer.html#sqlite-custom_indexes-index-name)`String.t`the name of the index. Defaults to "#{table}\_#{column}\_index".[`unique`](dsl-ashsqlite-datalayer.html#sqlite-custom_indexes-index-unique)`boolean``false`indicates whether the index should be unique.[`using`](dsl-ashsqlite-datalayer.html#sqlite-custom_indexes-index-using)`String.t`configures the index type.[`where`](dsl-ashsqlite-datalayer.html#sqlite-custom_indexes-index-where)`String.t`specify conditions for a partial index.[`message`](dsl-ashsqlite-datalayer.html#sqlite-custom_indexes-index-message)`String.t`A custom message to use for unique indexes that have been violated[`include`](dsl-ashsqlite-datalayer.html#sqlite-custom_indexes-index-include)`list(String.t)`specify fields for a covering index. This is not supported by all databases. For more information on SQLite support, please read the official docs.
1174 | 
1175 | ### [](dsl-ashsqlite-datalayer.html#introspection)Introspection
1176 | 
1177 | Target: [`AshSqlite.CustomIndex`](AshSqlite.CustomIndex.html)
1178 | 
1179 | ### [](dsl-ashsqlite-datalayer.html#sqlite-custom_statements)sqlite.custom\_statements
1180 | 
1181 | A section for configuring custom statements to be added to migrations.
1182 | 
1183 | Changing custom statements may require manual intervention, because Ash can't determine what order they should run in (i.e if they depend on table structure that you've added, or vice versa). As such, any `down` statements we run for custom statements happen first, and any `up` statements happen last.
1184 | 
1185 | Additionally, when changing a custom statement, we must make some assumptions, i.e that we should migrate the old structure down using the previously configured `down` and recreate it.
1186 | 
1187 | This may not be desired, and so what you may end up doing is simply modifying the old migration and deleting whatever was generated by the migration generator. As always: read your migrations after generating them!
1188 | 
1189 | ### [](dsl-ashsqlite-datalayer.html#nested-dsls-2)Nested DSLs
1190 | 
1191 | - [statement](dsl-ashsqlite-datalayer.html#sqlite-custom_statements-statement)
1192 | 
1193 | ### [](dsl-ashsqlite-datalayer.html#examples-3)Examples
1194 | 
1195 | ```
1196 | custom_statements do
1197 |   # the name is used to detect if you remove or modify the statement
1198 |   statement :pgweb_idx do
1199 |     up "CREATE INDEX pgweb_idx ON pgweb USING GIN (to_tsvector('english', title || ' ' || body));"
1200 |     down "DROP INDEX pgweb_idx;"
1201 |   end
1202 | end
1203 | ```
1204 | 
1205 | ### [](dsl-ashsqlite-datalayer.html#sqlite-custom_statements-statement)sqlite.custom\_statements.statement
1206 | 
1207 | ```
1208 | statement name
1209 | ```
1210 | 
1211 | Add a custom statement for migrations.
1212 | 
1213 | ### [](dsl-ashsqlite-datalayer.html#examples-4)Examples
1214 | 
1215 | ```
1216 | statement :pgweb_idx do
1217 |   up "CREATE INDEX pgweb_idx ON pgweb USING GIN (to_tsvector('english', title || ' ' || body));"
1218 |   down "DROP INDEX pgweb_idx;"
1219 | end
1220 | ```
1221 | 
1222 | ### [](dsl-ashsqlite-datalayer.html#arguments-1)Arguments
1223 | 
1224 | NameTypeDefaultDocs[`name`](dsl-ashsqlite-datalayer.html#sqlite-custom_statements-statement-name)`atom`The name of the statement, must be unique within the resource
1225 | 
1226 | ### [](dsl-ashsqlite-datalayer.html#options-2)Options
1227 | 
1228 | NameTypeDefaultDocs[`up`](dsl-ashsqlite-datalayer.html#sqlite-custom_statements-statement-up)`String.t`How to create the structure of the statement[`down`](dsl-ashsqlite-datalayer.html#sqlite-custom_statements-statement-down)`String.t`How to tear down the structure of the statement[`code?`](dsl-ashsqlite-datalayer.html#sqlite-custom_statements-statement-code?)`boolean``false`By default, we place the strings inside of ecto migration's `execute/1` function and assume they are sql. Use this option if you want to provide custom elixir code to be placed directly in the migrations
1229 | 
1230 | ### [](dsl-ashsqlite-datalayer.html#introspection-1)Introspection
1231 | 
1232 | Target: [`AshSqlite.Statement`](AshSqlite.Statement.html)
1233 | 
1234 | ### [](dsl-ashsqlite-datalayer.html#sqlite-references)sqlite.references
1235 | 
1236 | A section for configuring the references (foreign keys) in resource migrations.
1237 | 
1238 | This section is only relevant if you are using the migration generator with this resource. Otherwise, it has no effect.
1239 | 
1240 | ### [](dsl-ashsqlite-datalayer.html#nested-dsls-3)Nested DSLs
1241 | 
1242 | - [reference](dsl-ashsqlite-datalayer.html#sqlite-references-reference)
1243 | 
1244 | ### [](dsl-ashsqlite-datalayer.html#examples-5)Examples
1245 | 
1246 | ```
1247 | references do
1248 |   reference :post, on_delete: :delete, on_update: :update, name: "comments_to_posts_fkey"
1249 | end
1250 | ```
1251 | 
1252 | ### [](dsl-ashsqlite-datalayer.html#options-3)Options
1253 | 
1254 | NameTypeDefaultDocs[`polymorphic_on_delete`](dsl-ashsqlite-datalayer.html#sqlite-references-polymorphic_on_delete)`:delete | :nilify | :nothing | :restrict`For polymorphic resources, configures the on\_delete behavior of the automatically generated foreign keys to source tables.[`polymorphic_on_update`](dsl-ashsqlite-datalayer.html#sqlite-references-polymorphic_on_update)`:update | :nilify | :nothing | :restrict`For polymorphic resources, configures the on\_update behavior of the automatically generated foreign keys to source tables.[`polymorphic_name`](dsl-ashsqlite-datalayer.html#sqlite-references-polymorphic_name)`:update | :nilify | :nothing | :restrict`For polymorphic resources, configures the on\_update behavior of the automatically generated foreign keys to source tables.
1255 | 
1256 | ### [](dsl-ashsqlite-datalayer.html#sqlite-references-reference)sqlite.references.reference
1257 | 
1258 | ```
1259 | reference relationship
1260 | ```
1261 | 
1262 | Configures the reference for a relationship in resource migrations.
1263 | 
1264 | Keep in mind that multiple relationships can theoretically involve the same destination and foreign keys. In those cases, you only need to configure the `reference` behavior for one of them. Any conflicts will result in an error, across this resource and any other resources that share a table with this one. For this reason, instead of adding a reference configuration for `:nothing`, its best to just leave the configuration out, as that is the default behavior if *no* relationship anywhere has configured the behavior of that reference.
1265 | 
1266 | ### [](dsl-ashsqlite-datalayer.html#examples-6)Examples
1267 | 
1268 | ```
1269 | reference :post, on_delete: :delete, on_update: :update, name: "comments_to_posts_fkey"
1270 | ```
1271 | 
1272 | ### [](dsl-ashsqlite-datalayer.html#arguments-2)Arguments
1273 | 
1274 | NameTypeDefaultDocs[`relationship`](dsl-ashsqlite-datalayer.html#sqlite-references-reference-relationship)`atom`The relationship to be configured
1275 | 
1276 | ### [](dsl-ashsqlite-datalayer.html#options-4)Options
1277 | 
1278 | NameTypeDefaultDocs[`ignore?`](dsl-ashsqlite-datalayer.html#sqlite-references-reference-ignore?)`boolean`If set to true, no reference is created for the given relationship. This is useful if you need to define it in some custom way[`on_delete`](dsl-ashsqlite-datalayer.html#sqlite-references-reference-on_delete)`:delete | :nilify | :nothing | :restrict`What should happen to records of this resource when the referenced record of the *destination* resource is deleted.[`on_update`](dsl-ashsqlite-datalayer.html#sqlite-references-reference-on_update)`:update | :nilify | :nothing | :restrict`What should happen to records of this resource when the referenced destination\_attribute of the *destination* record is update.[`deferrable`](dsl-ashsqlite-datalayer.html#sqlite-references-reference-deferrable)`false | true | :initially``false`Wether or not the constraint is deferrable. This only affects the migration generator.[`name`](dsl-ashsqlite-datalayer.html#sqlite-references-reference-name)`String.t`The name of the foreign key to generate in the database. Defaults to &lt;table&gt;\_&lt;source\_attribute&gt;\_fkey
1279 | 
1280 | ### [](dsl-ashsqlite-datalayer.html#introspection-2)Introspection
1281 | 
1282 | Target: [`AshSqlite.Reference`](AshSqlite.Reference.html)
1283 | 
1284 | [← Previous Page Join Manual Relationships](manual-relationships.html)
1285 | 
1286 | [Next Page → Change Log](changelog.html)
1287 | 
1288 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) ([current file](https://preview.hex.pm/preview/ash_sqlite/0.2.3/show/documentation/dsls/DSL-AshSqlite.DataLayer.md)) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
1289 | 
1290 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1291 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
1292 | 
1293 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
1294 | 
1295 | v0.2.3
1296 | 
1297 | - Pages
1298 | - Modules
1299 | - Mix Tasks
1300 | 
1301 | <!--THE END-->
1302 | 
1303 | <!--THE END-->
1304 | 
1305 | <!--THE END-->
1306 | 
1307 | Search documentation of ash\_sqlite
1308 | 
1309 | Settings
1310 | 
1311 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/documentation/topics/advanced/expressions.md#L1 "View Source") Expressions
1312 | 
1313 | In addition to the expressions listed in the [Ash expressions guide](../ash/expressions.html), AshSqlite provides the following expressions
1314 | 
1315 | # Fragments
1316 | 
1317 | Fragments allow you to use arbitrary sqlite expressions in your queries. Fragments can often be an escape hatch to allow you to do things that don't have something officially supported with Ash.
1318 | 
1319 | ### [](expressions.html#examples)Examples
1320 | 
1321 | #### Simple expressions
1322 | 
1323 | ```
1324 | fragment("? / ?", points, count)
1325 | ```
1326 | 
1327 | #### Calling functions
1328 | 
1329 | ```
1330 | fragment("repeat('hello', 4)")
1331 | ```
1332 | 
1333 | #### Using entire queries
1334 | 
1335 | ```
1336 | fragment("points > (SELECT SUM(points) FROM games WHERE user_id = ? AND id != ?)", user_id, id)
1337 | ```
1338 | 
1339 | ### [](expressions.html#a-last-resport)a last resport
1340 | 
1341 | Using entire queries as shown above is a last resort, but can sometimes be the best way to accomplish a given task.
1342 | 
1343 | #### In calculations
1344 | 
1345 | ```
1346 | calculations do
1347 |   calculate :lower_name, :string, expr(
1348 |     fragment("LOWER(?)", name)
1349 |   )
1350 | end
1351 | ```
1352 | 
1353 | #### In migrations
1354 | 
1355 | ```
1356 | create table(:managers, primary_key: false) do
1357 |   add :id, :uuid, null: false, default: fragment("UUID_GENERATE_V4()"), primary_key: true
1358 | end
1359 | ```
1360 | 
1361 | ## [](expressions.html#like)Like
1362 | 
1363 | These wrap the sqlite builtin like operator
1364 | 
1365 | Please be aware, these match *patterns* not raw text. Use `contains/1` if you want to match text without supporting patterns, i.e `%` and `_` have semantic meaning!
1366 | 
1367 | For example:
1368 | 
1369 | ```
1370 | Ash.Query.filter(User, like(name, "%obo%")) # name contains obo anywhere in the string, case sensitively
1371 | ```
1372 | 
1373 | [← Previous Page Testing With Sqlite](testing.html)
1374 | 
1375 | [Next Page → Join Manual Relationships](manual-relationships.html)
1376 | 
1377 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) ([current file](https://preview.hex.pm/preview/ash_sqlite/0.2.3/show/documentation/topics/advanced/expressions.md)) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
1378 | 
1379 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1380 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
1381 | 
1382 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
1383 | 
1384 | v0.2.3
1385 | 
1386 | - Pages
1387 | - Modules
1388 | - Mix Tasks
1389 | 
1390 | <!--THE END-->
1391 | 
1392 | <!--THE END-->
1393 | 
1394 | <!--THE END-->
1395 | 
1396 | Search documentation of ash\_sqlite
1397 | 
1398 | Settings
1399 | 
1400 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/documentation/tutorials/getting-started-with-ash-sqlite.md#L1 "View Source") Getting Started With AshSqlite
1401 | 
1402 | ## [](getting-started-with-ash-sqlite.html#goals)Goals
1403 | 
1404 | In this guide we will:
1405 | 
1406 | 1. Setup AshSqlite, which includes setting up [Ecto](https://hexdocs.pm/ecto/Ecto.html)
1407 | 2. Add AshSqlite to the resources created in [the Ash getting started guide](../ash/get-started.html)
1408 | 3. Show how the various features of AshSqlite can help you work quickly and cleanly against a sqlite database
1409 | 4. Highlight some of the more advanced features you can use when using AshSqlite.
1410 | 5. Point you to additional resources you may need on your journey
1411 | 
1412 | ## [](getting-started-with-ash-sqlite.html#requirements)Requirements
1413 | 
1414 | - A working SQLite installation, with a sufficiently permissive user
1415 | - If you would like to follow along, you will need to add begin with [the Ash getting started guide](../ash/get-started.html)
1416 | 
1417 | ## [](getting-started-with-ash-sqlite.html#steps)Steps
1418 | 
1419 | ### [](getting-started-with-ash-sqlite.html#add-ashsqlite)Add AshSqlite
1420 | 
1421 | Add the `:ash_sqlite` dependency to your application
1422 | 
1423 | `{:ash_sqlite, "~> 0.2.3"}`
1424 | 
1425 | Add `:ash_sqlite` to your `.formatter.exs` file
1426 | 
1427 | ```
1428 | [
1429 |   # import the formatter rules from `:ash_sqlite`
1430 |   import_deps: [..., :ash_sqlite],
1431 |   inputs: [...]
1432 | ]
1433 | ```
1434 | 
1435 | ### [](getting-started-with-ash-sqlite.html#create-and-configure-your-repo)Create and configure your Repo
1436 | 
1437 | Create `lib/helpdesk/repo.ex` with the following contents. [`AshSqlite.Repo`](AshSqlite.Repo.html) is a thin wrapper around [`Ecto.Repo`](../ecto/3.12.5/Ecto.Repo.html), so see their documentation for how to use it if you need to use it directly. For standard Ash usage, all you will need to do is configure your resources to use your repo.
1438 | 
1439 | ```
1440 | # in lib/helpdesk/repo.ex
1441 | 
1442 | defmodule Helpdesk.Repo do
1443 |   use AshSqlite.Repo, otp_app: :helpdesk
1444 | end
1445 | ```
1446 | 
1447 | Next we will need to create configuration files for various environments. Run the following to create the configuration files we need.
1448 | 
1449 | ```
1450 | mkdir -p config
1451 | touch config/config.exs
1452 | touch config/dev.exs
1453 | touch config/runtime.exs
1454 | touch config/test.exs
1455 | ```
1456 | 
1457 | Place the following contents in those files, ensuring that the credentials match the user you created for your database. For most conventional installations this will work out of the box. If you've followed other guides before this one, they may have had you create these files already, so just make sure these contents are there.
1458 | 
1459 | ```
1460 | # in config/config.exs
1461 | import Config
1462 | 
1463 | # This should already have been added from the getting started guide
1464 | config :helpdesk,
1465 |   ash_domains: [Helpdesk.Support]
1466 | 
1467 | config :helpdesk,
1468 |   ash_apis: [Helpdesk.Support]
1469 | 
1470 | config :helpdesk,
1471 |   ecto_repos: [Helpdesk.Repo]
1472 | 
1473 | # Import environment specific config. This must remain at the bottom
1474 | # of this file so it overrides the configuration defined above.
1475 | import_config "#{config_env()}.exs"
1476 | ```
1477 | 
1478 | ```
1479 | # in config/dev.exs
1480 | 
1481 | import Config
1482 | 
1483 | # Configure your database
1484 | config :helpdesk, Helpdesk.Repo,
1485 |   database: Path.join(__DIR__, "../path/to/your.db"),
1486 |   show_sensitive_data_on_connection_error: true,
1487 |   pool_size: 10
1488 | ```
1489 | 
1490 | ```
1491 | # in config/runtime.exs
1492 | 
1493 | import Config
1494 | 
1495 | if config_env() == :prod do
1496 |   config :helpdesk, Helpdesk.Repo,
1497 |     pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")
1498 | end
1499 | ```
1500 | 
1501 | ```
1502 | # in config/test.exs
1503 | 
1504 | import Config
1505 | 
1506 | # Configure your database
1507 | #
1508 | # The MIX_TEST_PARTITION environment variable can be used
1509 | # to provide built-in test partitioning in CI environment.
1510 | # Run `mix help test` for more information.
1511 | config :helpdesk, Helpdesk.Repo,
1512 |   database: Path.join(__DIR__, "../path/to/your#{System.get_env("MIX_TEST_PARTITION")}.db"),
1513 |   pool: Ecto.Adapters.SQL.Sandbox,
1514 |   pool_size: 10
1515 | ```
1516 | 
1517 | And finally, add the repo to your application
1518 | 
1519 | ```
1520 | # in lib/helpdesk/application.ex
1521 | 
1522 |   def start(_type, _args) do
1523 |     children = [
1524 |       # Starts a worker by calling: Helpdesk.Worker.start_link(arg)
1525 |       # {Helpdesk.Worker, arg}
1526 |       Helpdesk.Repo
1527 |     ]
1528 | 
1529 |     ...
1530 | ```
1531 | 
1532 | ### [](getting-started-with-ash-sqlite.html#add-ashsqlite-to-our-resources)Add AshSqlite to our resources
1533 | 
1534 | Now we can add the data layer to our resources. The basic configuration for a resource requires the `AshSqlite.sqlite.table` and the `AshSqlite.sqlite.repo`.
1535 | 
1536 | ```
1537 | # in lib/helpdesk/support/resources/ticket.ex
1538 | 
1539 |   use Ash.Resource,
1540 |     domain: Helpdesk.Support,
1541 |     data_layer: AshSqlite.DataLayer
1542 | 
1543 |   sqlite do
1544 |     table "tickets"
1545 |     repo Helpdesk.Repo
1546 |   end
1547 | ```
1548 | 
1549 | ```
1550 | # in lib/helpdesk/support/resources/representative.ex
1551 | 
1552 |   use Ash.Resource,
1553 |     domain: Helpdesk.Support,
1554 |     data_layer: AshSqlite.DataLayer
1555 | 
1556 |   sqlite do
1557 |     table "representatives"
1558 |     repo Helpdesk.Repo
1559 |   end
1560 | ```
1561 | 
1562 | ### [](getting-started-with-ash-sqlite.html#create-the-database-and-tables)Create the database and tables
1563 | 
1564 | First, we'll create the database with [`mix ash_sqlite.create`](Mix.Tasks.AshSqlite.Create.html).
1565 | 
1566 | Then we will generate database migrations. This is one of the many ways that AshSqlite can save time and reduce complexity.
1567 | 
1568 | ```
1569 | mix ash_sqlite.generate_migrations --name add_tickets_and_representatives
1570 | ```
1571 | 
1572 | If you are unfamiliar with database migrations, it is a good idea to get a rough idea of what they are and how they work. See the links at the bottom of this guide for more. A rough overview of how migrations work is that each time you need to make changes to your database, they are saved as small, reproducible scripts that can be applied in order. This is necessary both for clean deploys as well as working with multiple developers making changes to the structure of a single database.
1573 | 
1574 | Typically, you need to write these by hand. AshSqlite, however, will store snapshots each time you run the command to generate migrations and will figure out what migrations need to be created.
1575 | 
1576 | You should always look at the generated migrations to ensure that they look correct. Do so now by looking at the generated file in `priv/repo/migrations`.
1577 | 
1578 | Finally, we will create the local database and apply the generated migrations:
1579 | 
1580 | ```
1581 | mix ash_sqlite.create
1582 | mix ash_sqlite.migrate
1583 | ```
1584 | 
1585 | ### [](getting-started-with-ash-sqlite.html#try-it-out)Try it out
1586 | 
1587 | And now we're ready to try it out! Run the following in iex:
1588 | 
1589 | Lets create some data. We'll make a representative and give them some open and some closed tickets.
1590 | 
1591 | ```
1592 | require Ash.Query
1593 | 
1594 | representative = (
1595 |   Helpdesk.Support.Representative
1596 |   |> Ash.Changeset.for_create(:create, %{name: "Joe Armstrong"})
1597 |   |> Helpdesk.Support.create!()
1598 | )
1599 | 
1600 | for i <- 0..5 do
1601 |   ticket =
1602 |     Helpdesk.Support.Ticket
1603 |     |> Ash.Changeset.for_create(:open, %{subject: "Issue #{i}"})
1604 |     |> Helpdesk.Support.create!()
1605 |     |> Ash.Changeset.for_update(:assign, %{representative_id: representative.id})
1606 |     |> Helpdesk.Support.update!()
1607 | 
1608 |   if rem(i, 2) == 0 do
1609 |     ticket
1610 |     |> Ash.Changeset.for_update(:close)
1611 |     |> Helpdesk.Support.update!()
1612 |   end
1613 | end
1614 | ```
1615 | 
1616 | And now we can read that data. You should see some debug logs that show the sql queries AshSqlite is generating.
1617 | 
1618 | ```
1619 | require Ash.Query
1620 | 
1621 | # Show the tickets where the subject equals "foobar"
1622 | Helpdesk.Support.Ticket
1623 | |> Ash.Query.filter(subject == "foobar")
1624 | |> Helpdesk.Support.read!()
1625 | ```
1626 | 
1627 | ```
1628 | require Ash.Query
1629 | 
1630 | # Show the tickets that are closed and their subject does not equal "barbaz"
1631 | Helpdesk.Support.Ticket
1632 | |> Ash.Query.filter(status == :closed and not(subject == "barbaz"))
1633 | |> Helpdesk.Support.read!()
1634 | ```
1635 | 
1636 | And, naturally, now that we are storing this in sqlite, this database is persisted even if we stop/start our application. The nice thing, however, is that this was the *exact* same code that we ran against our resources when they were backed by ETS.
1637 | 
1638 | ### [](getting-started-with-ash-sqlite.html#calculations)Calculations
1639 | 
1640 | Simple calculation for Ticket which adds a concatenation of state and subject:
1641 | 
1642 | ```
1643 | calculations do
1644 |   calculate :status_subject, :string,
1645 |   expr("#{status}: #{subject}")
1646 | end
1647 | ```
1648 | 
1649 | Testing of this feature can be done via iex:
1650 | 
1651 | ```
1652 | Ash.Query
1653 | Helpdesk.Support.Ticket
1654 |   |> Ash.Query.filter(status == :open)
1655 |   |> Ash.Query.load(:status_subject)
1656 |   |> Ash.read!()
1657 | ```
1658 | 
1659 | ### [](getting-started-with-ash-sqlite.html#aggregates)Aggregates
1660 | 
1661 | As stated in [what-is-ash-sqlite](getting-started-with-ash-sqlite.html#steps), **The main feature missing is Aggregate support.**.
1662 | 
1663 | In order to use these consider using [ash\_postgres](https://github.com/ash-project/ash_postgres) or provide a patch.
1664 | 
1665 | ### [](getting-started-with-ash-sqlite.html#rich-configuration-options)Rich Configuration Options
1666 | 
1667 | Take a look at the DSL documentation for more information on what you can configure. You can add check constraints, configure the behavior of foreign keys and more!
1668 | 
1669 | ### [](getting-started-with-ash-sqlite.html#deployment)Deployment
1670 | 
1671 | When deploying, you will need to ensure that the file you are using in production is persisted in some way (probably, unless you want it to disappear whenever your deployed system restarts). For example with fly.io this might mean adding a volume to your deployment.
1672 | 
1673 | ### [](getting-started-with-ash-sqlite.html#what-next)What next?
1674 | 
1675 | - Check out the data layer docs: [`AshSqlite.DataLayer`](AshSqlite.DataLayer.html)
1676 | - [Ecto's documentation](https://hexdocs.pm/ecto/Ecto.html). AshSqlite (and much of Ash itself) is made possible by the amazing Ecto. If you find yourself looking for escape hatches when using Ash or ways to work directly with your database, you will want to know how Ecto works. Ash and AshSqlite intentionally do not hide Ecto, and in fact encourages its use whenever you need an escape hatch.
1677 | - [Ecto's Migration documentation](https://hexdocs.pm/ecto_sql/Ecto.Migration.html) read more about migrations. Even with the ash\_sqlite migration generator, you will very likely need to modify your own migrations some day.
1678 | 
1679 | [← Previous Page Home](readme.html)
1680 | 
1681 | [Next Page → What is AshSqlite?](what-is-ash-sqlite.html)
1682 | 
1683 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) ([current file](https://preview.hex.pm/preview/ash_sqlite/0.2.3/show/documentation/tutorials/getting-started-with-ash-sqlite.md)) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
1684 | 
1685 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1686 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
1687 | 
1688 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
1689 | 
1690 | v0.2.3
1691 | 
1692 | - Pages
1693 | - Modules
1694 | - Mix Tasks
1695 | 
1696 | <!--THE END-->
1697 | 
1698 | <!--THE END-->
1699 | 
1700 | <!--THE END-->
1701 | 
1702 | Search documentation of ash\_sqlite
1703 | 
1704 | Settings
1705 | 
1706 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/documentation/topics/advanced/manual-relationships.md#L1 "View Source") Join Manual Relationships
1707 | 
1708 | See [Defining Manual Relationships](https://hexdocs.pm/ash/defining-manual-relationships.html) for an idea of manual relationships in general. Manual relationships allow for expressing complex/non-typical relationships between resources in a standard way. Individual data layers may interact with manual relationships in their own way, so see their corresponding guides.
1709 | 
1710 | ## [](manual-relationships.html#example)Example
1711 | 
1712 | ```
1713 | # in the resource
1714 | 
1715 | relationships do
1716 |   has_many :tickets_above_threshold, Helpdesk.Support.Ticket do
1717 |     manual Helpdesk.Support.Ticket.Relationships.TicketsAboveThreshold
1718 |   end
1719 | end
1720 | 
1721 | # implementation
1722 | defmodule Helpdesk.Support.Ticket.Relationships.TicketsAboveThreshold do
1723 |   use Ash.Resource.ManualRelationship
1724 |   use AshSqlite.ManualRelationship
1725 | 
1726 |   require Ash.Query
1727 |   require Ecto.Query
1728 | 
1729 |   def load(records, _opts, %{query: query, actor: actor, authorize?: authorize?}) do
1730 |     # Use existing records to limit resultds
1731 |     rep_ids = Enum.map(records, & &1.id)
1732 |      # Using Ash to get the destination records is ideal, so you can authorize access like normal
1733 |      # but if you need to use a raw ecto query here, you can. As long as you return the right structure.
1734 | 
1735 |     {:ok,
1736 |      query
1737 |      |> Ash.Query.filter(representative_id in ^rep_ids)
1738 |      |> Ash.Query.filter(priority > representative.priority_threshold)
1739 |      |> Helpdesk.Support.read!(actor: actor, authorize?: authorize?)
1740 |      # Return the items grouped by the primary key of the source, i.e representative.id => [...tickets above threshold]
1741 |      |> Enum.group_by(& &1.representative_id)}
1742 |   end
1743 | 
1744 |   # query is the "source" query that is being built. 
1745 | 
1746 |   # _opts are options provided to the manual relationship, i.e `{Manual, opt: :val}`
1747 | 
1748 |   # current_binding is what the source of the relationship is bound to. Access fields with `as(^current_binding).field`
1749 | 
1750 |   # as_binding is the binding that your join should create. When you join, make sure you say `as: ^as_binding` on the
1751 |   # part of the query that represents the destination of the relationship
1752 | 
1753 |   # type is `:inner` or `:left`.
1754 |   # destination_query is what you should join to to add the destination to the query, i.e `join: dest in ^destination-query`
1755 |   def ash_sqlite_join(query, _opts, current_binding, as_binding, :inner, destination_query) do
1756 |     {:ok,
1757 |      Ecto.Query.from(_ in query,
1758 |        join: dest in ^destination_query,
1759 |        as: ^as_binding,
1760 |        on: dest.representative_id == as(^current_binding).id,
1761 |        on: dest.priority > as(^current_binding).priority_threshold
1762 |      )}
1763 |   end
1764 | 
1765 |   def ash_sqlite_join(query, _opts, current_binding, as_binding, :left, destination_query) do
1766 |     {:ok,
1767 |      Ecto.Query.from(_ in query,
1768 |        left_join: dest in ^destination_query,
1769 |        as: ^as_binding,
1770 |        on: dest.representative_id == as(^current_binding).id,
1771 |        on: dest.priority > as(^current_binding).priority_threshold
1772 |      )}
1773 |   end
1774 | 
1775 |   # _opts are options provided to the manual relationship, i.e `{Manual, opt: :val}`
1776 | 
1777 |   # current_binding is what the source of the relationship is bound to. Access fields with `parent_as(^current_binding).field`
1778 | 
1779 |   # as_binding is the binding that has already been created for your join. Access fields on it via `as(^as_binding)`
1780 | 
1781 |   # destination_query is what you should use as the basis of your query
1782 |   def ash_sqlite_subquery(_opts, current_binding, as_binding, destination_query) do
1783 |     {:ok,
1784 |      Ecto.Query.from(_ in destination_query,
1785 |        where: parent_as(^current_binding).id == as(^as_binding).representative_id,
1786 |        where: as(^as_binding).priority > parent_as(^current_binding).priority_threshold
1787 |      )}
1788 |   end
1789 | end
1790 | ```
1791 | 
1792 | [← Previous Page Expressions](expressions.html)
1793 | 
1794 | [Next Page → AshSqlite.DataLayer](dsl-ashsqlite-datalayer.html)
1795 | 
1796 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) ([current file](https://preview.hex.pm/preview/ash_sqlite/0.2.3/show/documentation/topics/advanced/manual-relationships.md)) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
1797 | 
1798 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1799 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
1800 | 
1801 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
1802 | 
1803 | v0.2.3
1804 | 
1805 | - Pages
1806 | - Modules
1807 | - Mix Tasks
1808 | 
1809 | <!--THE END-->
1810 | 
1811 | <!--THE END-->
1812 | 
1813 | <!--THE END-->
1814 | 
1815 | Search documentation of ash\_sqlite
1816 | 
1817 | Settings
1818 | 
1819 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/documentation/topics/development/migrations-and-tasks.md#L1 "View Source") Migrations
1820 | 
1821 | ## [](migrations-and-tasks.html#tasks)Tasks
1822 | 
1823 | Ash comes with its own tasks, and AshSqlite exposes lower level tasks that you can use if necessary. This guide shows the process using `ash.*` tasks, and the `ash_sqlite.*` tasks are illustrated at the bottom.
1824 | 
1825 | ## [](migrations-and-tasks.html#basic-workflow)Basic Workflow
1826 | 
1827 | - Make resource changes
1828 | - Run `mix ash.codegen --name add_a_combobulator` to generate migrations and resource snapshots
1829 | - Run [`mix ash.migrate`](../ash/3.4.58/Mix.Tasks.Ash.Migrate.html) to run those migrations
1830 | 
1831 | For more information on generating migrations, run [`mix help ash_sqlite.generate_migrations`](Mix.Tasks.AshSqlite.GenerateMigrations.html) (the underlying task that is called by [`mix ash.migrate`](../ash/3.4.58/Mix.Tasks.Ash.Migrate.html))
1832 | 
1833 | ### [](migrations-and-tasks.html#regenerating-migrations)Regenerating Migrations
1834 | 
1835 | Often, you will run into a situation where you want to make a slight change to a resource after you've already generated and run migrations. If you are using git and would like to undo those changes, then regenerate the migrations, this script may prove useful:
1836 | 
1837 | ```
1838 | #!/bin/bash
1839 | 
1840 | # Get count of untracked migrations
1841 | N_MIGRATIONS=$(git ls-files --others priv/repo/migrations | wc -l)
1842 | 
1843 | # Rollback untracked migrations
1844 | mix ash_sqlite.rollback -n $N_MIGRATIONS
1845 | 
1846 | # Delete untracked migrations and snapshots
1847 | git ls-files --others priv/repo/migrations | xargs rm
1848 | git ls-files --others priv/resource_snapshots | xargs rm
1849 | 
1850 | # Regenerate migrations
1851 | mix ash.codegen --name $1
1852 | 
1853 | # Run migrations if flag
1854 | if echo $* | grep -e "-m" -q
1855 | then
1856 |   mix ash.migrate
1857 | fi
1858 | ```
1859 | 
1860 | After saving this file to something like `regen.sh`, make it executable with `chmod +x regen.sh`. Now you can run it with `./regen.sh name_of_operation`. If you would like the migrations to automatically run after regeneration, add the `-m` flag: `./regen.sh name_of_operation -m`.
1861 | 
1862 | ## [](migrations-and-tasks.html#multiple-repos)Multiple Repos
1863 | 
1864 | If you are using multiple repos, you will likely need to use [`mix ecto.migrate`](../ecto_sql/3.12.1/Mix.Tasks.Ecto.Migrate.html) and manage it separately for each repo, as the options would be applied to both repo, which wouldn't make sense.
1865 | 
1866 | ## [](migrations-and-tasks.html#running-migrations-in-production)Running Migrations in Production
1867 | 
1868 | Define a module similar to the following:
1869 | 
1870 | ```
1871 | defmodule MyApp.Release do
1872 |   @moduledoc """
1873 |   Houses tasks that need to be executed in the released application (because mix is not present in releases).
1874 |   """
1875 |   @app :my_ap
1876 |   def migrate do
1877 |     load_app()
1878 | 
1879 |     for repo <- repos() do
1880 |       {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
1881 |     end
1882 |   end
1883 | 
1884 |   def rollback(repo, version) do
1885 |     load_app()
1886 |     {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
1887 |   end
1888 | 
1889 |   defp repos do
1890 |     domains()
1891 |     |> Enum.flat_map(fn domain ->
1892 |       domain
1893 |       |> Ash.Domain.Info.resources()
1894 |       |> Enum.map(&AshSqlite.repo/1)
1895 |     end)
1896 |     |> Enum.uniq()
1897 |   end
1898 | 
1899 |   defp domains do
1900 |     Application.fetch_env!(:my_app, :ash_domains)
1901 |   end
1902 | 
1903 |   defp load_app do
1904 |     Application.load(@app)
1905 |   end
1906 | end
1907 | ```
1908 | 
1909 | # AshSqlite-specific tasks
1910 | 
1911 | - [`mix ash_sqlite.generate_migrations`](Mix.Tasks.AshSqlite.GenerateMigrations.html)
1912 | - [`mix ash_sqlite.create`](Mix.Tasks.AshSqlite.Create.html)
1913 | - [`mix ash_sqlite.migrate`](Mix.Tasks.AshSqlite.Migrate.html)
1914 | - [`mix ash_sqlite.rollback`](Mix.Tasks.AshSqlite.Rollback.html)
1915 | - [`mix ash_sqlite.drop`](Mix.Tasks.AshSqlite.Drop.html)
1916 | 
1917 | [← Previous Page Polymorphic Resources](polymorphic-resources.html)
1918 | 
1919 | [Next Page → Testing With Sqlite](testing.html)
1920 | 
1921 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) ([current file](https://preview.hex.pm/preview/ash_sqlite/0.2.3/show/documentation/topics/development/migrations-and-tasks.md)) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
1922 | 
1923 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1924 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
1925 | 
1926 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
1927 | 
1928 | v0.2.3
1929 | 
1930 | - Pages
1931 | - Modules
1932 | - Mix Tasks
1933 | 
1934 | <!--THE END-->
1935 | 
1936 | <!--THE END-->
1937 | 
1938 | <!--THE END-->
1939 | 
1940 | Search documentation of ash\_sqlite
1941 | 
1942 | Settings
1943 | 
1944 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/mix/tasks/ash_sqlite.create.ex#L1 "View Source") mix ash\_sqlite.create (ash\_sqlite v0.2.3)
1945 | 
1946 | Create the storage for repos in all resources for the given (or configured) domains.
1947 | 
1948 | ## [](Mix.Tasks.AshSqlite.Create.html#module-examples)Examples
1949 | 
1950 | ```
1951 | mix ash_sqlite.create
1952 | mix ash_sqlite.create --domains MyApp.Domain1,MyApp.Domain2
1953 | ```
1954 | 
1955 | ## [](Mix.Tasks.AshSqlite.Create.html#module-command-line-options)Command line options
1956 | 
1957 | - `--domains` - the domains who's repos you want to migrate.
1958 | - `--quiet` - do not log output
1959 | - `--no-compile` - do not compile before creating
1960 | - `--no-deps-check` - do not compile before creating
1961 | 
1962 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
1963 | 
1964 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1965 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
1966 | 
1967 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
1968 | 
1969 | v0.2.3
1970 | 
1971 | - Pages
1972 | - Modules
1973 | - Mix Tasks
1974 | 
1975 | <!--THE END-->
1976 | 
1977 | <!--THE END-->
1978 | 
1979 | <!--THE END-->
1980 | 
1981 | Search documentation of ash\_sqlite
1982 | 
1983 | Settings
1984 | 
1985 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/mix/tasks/ash_sqlite.drop.ex#L1 "View Source") mix ash\_sqlite.drop (ash\_sqlite v0.2.3)
1986 | 
1987 | Drop the storage for the given repository.
1988 | 
1989 | ## [](Mix.Tasks.AshSqlite.Drop.html#module-examples)Examples
1990 | 
1991 | ```
1992 | mix ash_sqlite.drop
1993 | mix ash_sqlite.drop -d MyApp.Domain1,MyApp.Domain2
1994 | ```
1995 | 
1996 | ## [](Mix.Tasks.AshSqlite.Drop.html#module-command-line-options)Command line options
1997 | 
1998 | - `--domains` - the domains who's repos should be dropped
1999 | - `-q`, `--quiet` - run the command quietly
2000 | - `-f`, `--force` - do not ask for confirmation when dropping the database. Configuration is asked only when `:start_permanent` is set to true (typically in production)
2001 | - `--no-compile` - do not compile before dropping
2002 | - `--no-deps-check` - do not compile before dropping
2003 | 
2004 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
2005 | 
2006 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
2007 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
2008 | 
2009 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
2010 | 
2011 | v0.2.3
2012 | 
2013 | - Pages
2014 | - Modules
2015 | - Mix Tasks
2016 | 
2017 | <!--THE END-->
2018 | 
2019 | <!--THE END-->
2020 | 
2021 | <!--THE END-->
2022 | 
2023 | Search documentation of ash\_sqlite
2024 | 
2025 | Settings
2026 | 
2027 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/mix/tasks/ash_sqlite.generate_migrations.ex#L1 "View Source") mix ash\_sqlite.generate\_migrations (ash\_sqlite v0.2.3)
2028 | 
2029 | Generates migrations, and stores a snapshot of your resources.
2030 | 
2031 | Options:
2032 | 
2033 | - `domains` - a comma separated list of domain modules, for which migrations will be generated
2034 | - `snapshot-path` - a custom path to store the snapshots, defaults to "priv/resource\_snapshots"
2035 | - `migration-path` - a custom path to store the migrations, defaults to "priv". Migrations are stored in a folder for each repo, so `priv/repo_name/migrations`
2036 | - `drop-columns` - whether or not to drop columns as attributes are removed. See below for more
2037 | - `name` - names the generated migrations, prepending with the timestamp. The default is `migrate_resources_<n>`, where `<n>` is the count of migrations matching `*migrate_resources*` plus one. For example, `--name add_special_column` would get a name like `20210708181402_add_special_column.exs`
2038 | 
2039 | Flags:
2040 | 
2041 | - `quiet` - messages for file creations will not be printed
2042 | - `no-format` - files that are created will not be formatted with the code formatter
2043 | - `dry-run` - no files are created, instead the new migration is printed
2044 | - `check` - no files are created, returns an exit(1) code if the current snapshots and resources don't fit
2045 | 
2046 | #### Snapshots
2047 | 
2048 | Snapshots are stored in a folder for each table that migrations are generated for. Each snapshot is stored in a file with a timestamp of when it was generated. This is important because it allows for simultaneous work to be done on separate branches, and for rolling back changes more easily, e.g removing a generated migration, and deleting the most recent snapshot, without having to redo all of it
2049 | 
2050 | #### Dropping columns
2051 | 
2052 | Generally speaking, it is bad practice to drop columns when you deploy a change that would remove an attribute. The main reasons for this are backwards compatibility and rolling restarts. If you deploy an attribute removal, and run migrations. Regardless of your deployment sstrategy, you won't be able to roll back, because the data has been deleted. In a rolling restart situation, some of the machines/pods/whatever may still be running after the column has been deleted, causing errors. With this in mind, its best not to delete those columns until later, after the data has been confirmed unnecessary. To that end, the migration generator leaves the column dropping code commented. You can pass `--drop_columns` to tell it to uncomment those statements. Additionally, you can just uncomment that code on a case by case basis.
2053 | 
2054 | #### Conflicts/Multiple Resources
2055 | 
2056 | It will raise on conflicts that it can't resolve, like the same field with different types. It will prompt to resolve conflicts that can be resolved with human input. For example, if you remove an attribute and add an attribute, it will ask you if you are renaming the column in question. If not, it will remove one column and add the other.
2057 | 
2058 | Additionally, it lowers things to the database where possible:
2059 | 
2060 | #### Defaults
2061 | 
2062 | There are three anonymous functions that will translate to database-specific defaults currently:
2063 | 
2064 | - `&DateTime.utc_now/0`
2065 | 
2066 | Non-function default values will be dumped to their native type and inspected. This may not work for some types, and may require manual intervention/patches to the migration generator code.
2067 | 
2068 | #### Identities
2069 | 
2070 | Identities will cause the migration generator to generate unique constraints. If multiple resources target the same table, you will be asked to select the primary key, and any others will be added as unique constraints.
2071 | 
2072 | # [](Mix.Tasks.AshSqlite.GenerateMigrations.html#summary)Summary
2073 | 
2074 | ## [Functions](Mix.Tasks.AshSqlite.GenerateMigrations.html#functions)
2075 | 
2076 | [run(args)](Mix.Tasks.AshSqlite.GenerateMigrations.html#run/1)
2077 | 
2078 | Callback implementation for [`Mix.Task.run/1`](../mix/Mix.Task.html#c:run/1).
2079 | 
2080 | # [](Mix.Tasks.AshSqlite.GenerateMigrations.html#functions)Functions
2081 | 
2082 | [](Mix.Tasks.AshSqlite.GenerateMigrations.html#run/1)
2083 | 
2084 | # run(args)
2085 | 
2086 | [](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/mix/tasks/ash_sqlite.generate_migrations.ex#L70)
2087 | 
2088 | Callback implementation for [`Mix.Task.run/1`](../mix/Mix.Task.html#c:run/1).
2089 | 
2090 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
2091 | 
2092 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
2093 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
2094 | 
2095 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
2096 | 
2097 | v0.2.3
2098 | 
2099 | - Pages
2100 | - Modules
2101 | - Mix Tasks
2102 | 
2103 | <!--THE END-->
2104 | 
2105 | <!--THE END-->
2106 | 
2107 | <!--THE END-->
2108 | 
2109 | Search documentation of ash\_sqlite
2110 | 
2111 | Settings
2112 | 
2113 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/mix/tasks/ash_sqlite.install.ex#L2 "View Source") mix ash\_sqlite.install (ash\_sqlite v0.2.3)
2114 | 
2115 | Installs AshSqlite. Should be run with `mix igniter.install ash_sqlite`
2116 | 
2117 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
2118 | 
2119 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
2120 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
2121 | 
2122 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
2123 | 
2124 | v0.2.3
2125 | 
2126 | - Pages
2127 | - Modules
2128 | - Mix Tasks
2129 | 
2130 | <!--THE END-->
2131 | 
2132 | <!--THE END-->
2133 | 
2134 | <!--THE END-->
2135 | 
2136 | Search documentation of ash\_sqlite
2137 | 
2138 | Settings
2139 | 
2140 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/mix/tasks/ash_sqlite.migrate.ex#L1 "View Source") mix ash\_sqlite.migrate (ash\_sqlite v0.2.3)
2141 | 
2142 | Runs the pending migrations for the given repository.
2143 | 
2144 | Migrations are expected at "priv/YOUR\_REPO/migrations" directory of the current application, where "YOUR\_REPO" is the last segment in your repository name. For example, the repository `MyApp.Repo` will use "priv/repo/migrations". The repository `Whatever.MyRepo` will use "priv/my\_repo/migrations".
2145 | 
2146 | This task runs all pending migrations by default. To migrate up to a specific version number, supply `--to version_number`. To migrate a specific number of times, use `--step n`.
2147 | 
2148 | This is only really useful if your domain or domains only use a single repo. If you have multiple repos and you want to run a single migration and/or migrate/roll them back to different points, you will need to use the ecto specific task, [`mix ecto.migrate`](../ecto_sql/3.12.1/Mix.Tasks.Ecto.Migrate.html) and provide your repo name.
2149 | 
2150 | If a repository has not yet been started, one will be started outside your application supervision tree and shutdown afterwards.
2151 | 
2152 | ## [](Mix.Tasks.AshSqlite.Migrate.html#module-examples)Examples
2153 | 
2154 | ```
2155 | mix ash_sqlite.migrate
2156 | mix ash_sqlite.migrate --domains MyApp.Domain1,MyApp.Domain2
2157 | 
2158 | mix ash_sqlite.migrate -n 3
2159 | mix ash_sqlite.migrate --step 3
2160 | 
2161 | mix ash_sqlite.migrate --to 20080906120000
2162 | ```
2163 | 
2164 | ## [](Mix.Tasks.AshSqlite.Migrate.html#module-command-line-options)Command line options
2165 | 
2166 | - `--domains` - the domains who's repos should be migrated
2167 | - `--all` - run all pending migrations
2168 | - `--step`, `-n` - run n number of pending migrations
2169 | - `--to` - run all migrations up to and including version
2170 | - `--quiet` - do not log migration commands
2171 | - `--pool-size` - the pool size if the repository is started only for the task (defaults to 2)
2172 | - `--log-sql` - log the raw sql migrations are running
2173 | - `--strict-version-order` - abort when applying a migration with old timestamp
2174 | - `--no-compile` - does not compile applications before migrating
2175 | - `--no-deps-check` - does not check depedendencies before migrating
2176 | - `--migrations-path` - the path to load the migrations from, defaults to `"priv/repo/migrations"`. This option may be given multiple times in which case the migrations are loaded from all the given directories and sorted as if they were in the same one.
2177 |   
2178 |   Note, if you have migrations paths e.g. `a/` and `b/`, and run `mix ecto.migrate --migrations-path a/`, the latest migrations from `a/` will be run (even if `b/` contains the overall latest migrations.)
2179 | 
2180 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
2181 | 
2182 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
2183 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
2184 | 
2185 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
2186 | 
2187 | v0.2.3
2188 | 
2189 | - Pages
2190 | - Modules
2191 | - Mix Tasks
2192 | 
2193 | <!--THE END-->
2194 | 
2195 | <!--THE END-->
2196 | 
2197 | <!--THE END-->
2198 | 
2199 | Search documentation of ash\_sqlite
2200 | 
2201 | Settings
2202 | 
2203 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/lib/mix/tasks/ash_sqlite.rollback.ex#L1 "View Source") mix ash\_sqlite.rollback (ash\_sqlite v0.2.3)
2204 | 
2205 | Reverts applied migrations in the given repository. Migrations are expected at "priv/YOUR\_REPO/migrations" directory of the current application but it can be configured by specifying the `:priv` key under the repository configuration. Runs the latest applied migration by default. To roll back to a version number, supply `--to version_number`. To roll back a specific number of times, use `--step n`. To undo all applied migrations, provide `--all`.
2206 | 
2207 | This is only really useful if your domain or domains only use a single repo. If you have multiple repos and you want to run a single migration and/or migrate/roll them back to different points, you will need to use the ecto specific task, [`mix ecto.migrate`](../ecto_sql/3.12.1/Mix.Tasks.Ecto.Migrate.html) and provide your repo name.
2208 | 
2209 | ## [](Mix.Tasks.AshSqlite.Rollback.html#module-examples)Examples
2210 | 
2211 | ```
2212 | mix ash_sqlite.rollback
2213 | mix ash_sqlite.rollback -r Custom.Repo
2214 | mix ash_sqlite.rollback -n 3
2215 | mix ash_sqlite.rollback --step 3
2216 | mix ash_sqlite.rollback -v 20080906120000
2217 | mix ash_sqlite.rollback --to 20080906120000
2218 | ```
2219 | 
2220 | ## [](Mix.Tasks.AshSqlite.Rollback.html#module-command-line-options)Command line options
2221 | 
2222 | - `--domains` - the domains who's repos should be rolledback
2223 | - `--all` - revert all applied migrations
2224 | - `--step` / `-n` - revert n number of applied migrations
2225 | - `--to` / `-v` - revert all migrations down to and including version
2226 | - `--quiet` - do not log migration commands
2227 | - `--pool-size` - the pool size if the repository is started only for the task (defaults to 1)
2228 | - `--log-sql` - log the raw sql migrations are running
2229 | 
2230 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
2231 | 
2232 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
2233 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
2234 | 
2235 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
2236 | 
2237 | v0.2.3
2238 | 
2239 | - Pages
2240 | - Modules
2241 | - Mix Tasks
2242 | 
2243 | <!--THE END-->
2244 | 
2245 | <!--THE END-->
2246 | 
2247 | <!--THE END-->
2248 | 
2249 | Search documentation of ash\_sqlite
2250 | 
2251 | Settings
2252 | 
2253 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/documentation/topics/resources/polymorphic-resources.md#L1 "View Source") Polymorphic Resources
2254 | 
2255 | To support leveraging the same resource backed by multiple tables (useful for things like polymorphic associations), AshSqlite supports setting the `data_layer.table` context for a given resource. For this example, lets assume that you have a `MyApp.Post` resource and a `MyApp.Comment` resource. For each of those resources, users can submit `reactions`. However, you want a separate table for `post_reactions` and `comment_reactions`. You could accomplish that like so:
2256 | 
2257 | ```
2258 | defmodule MyApp.Reaction do
2259 |   use Ash.Resource,
2260 |     domain: MyApp.Domain,
2261 |     data_layer: AshSqlite.DataLayer
2262 | 
2263 |    sqlite do
2264 |     polymorphic? true # Without this, `table` is a required configuration
2265 |   end
2266 | 
2267 |   attributes do
2268 |     attribute(:resource_id, :uuid)
2269 |   end
2270 | 
2271 |   ...
2272 | end
2273 | ```
2274 | 
2275 | Then, in your related resources, you set the table context like so:
2276 | 
2277 | ```
2278 | defmodule MyApp.Post do
2279 |   use Ash.Resource,
2280 |     domain: MyApp.Domain,
2281 |     data_layer: AshSqlite.DataLayer
2282 | 
2283 |   ...
2284 | 
2285 |   relationships do
2286 |     has_many :reactions, MyApp.Reaction,
2287 |       relationship_context: %{data_layer: %{table: "post_reactions"}},
2288 |       destination_attribute: :resource_id
2289 |   end
2290 | end
2291 | 
2292 | defmodule MyApp.Comment do
2293 |   use Ash.Resource,
2294 |     domain: MyApp.Domain,
2295 |     data_layer: AshSqlite.DataLayer
2296 | 
2297 |   ...
2298 | 
2299 |   relationships do
2300 |     has_many :reactions, MyApp.Reaction,
2301 |       relationship_context: %{data_layer: %{table: "comment_reactions"}},
2302 |       destination_attribute: :resource_id
2303 |   end
2304 | end
2305 | ```
2306 | 
2307 | With this, when loading or editing related data, ash will automatically set that context. For managing related data, see [`Ash.Changeset.manage_relationship/4`](../ash/3.4.58/Ash.Changeset.html#manage_relationship/4) and other relationship functions in [`Ash.Changeset`](../ash/3.4.58/Ash.Changeset.html)
2308 | 
2309 | ## [](polymorphic-resources.html#table-specific-actions)Table specific actions
2310 | 
2311 | To make actions use a specific table, you can use the `set_context` query preparation/change.
2312 | 
2313 | For example:
2314 | 
2315 | ```
2316 | defmodule MyApp.Reaction do
2317 |   actions do
2318 |     read :for_comments do
2319 |       prepare set_context(%{data_layer: %{table: "comment_reactions"}})
2320 |     end
2321 | 
2322 |     read :for_posts do
2323 |       prepare set_context(%{data_layer: %{table: "post_reactions"}})
2324 |     end
2325 |   end
2326 | end
2327 | ```
2328 | 
2329 | ## [](polymorphic-resources.html#migrations)Migrations
2330 | 
2331 | When a migration is marked as `polymorphic? true`, the migration generator will look at all resources that are related to it, that set the `%{data_layer: %{table: "table"}}` context. For each of those, a migration is generated/managed automatically. This means that adding reactions to a new resource is as easy as adding the relationship and table context, and then running [`mix ash_sqlite.generate_migrations`](Mix.Tasks.AshSqlite.GenerateMigrations.html).
2332 | 
2333 | [← Previous Page References](references.html)
2334 | 
2335 | [Next Page → Migrations](migrations-and-tasks.html)
2336 | 
2337 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) ([current file](https://preview.hex.pm/preview/ash_sqlite/0.2.3/show/documentation/topics/resources/polymorphic-resources.md)) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
2338 | 
2339 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
2340 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
2341 | 
2342 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
2343 | 
2344 | v0.2.3
2345 | 
2346 | - Pages
2347 | - Modules
2348 | - Mix Tasks
2349 | 
2350 | <!--THE END-->
2351 | 
2352 | <!--THE END-->
2353 | 
2354 | <!--THE END-->
2355 | 
2356 | Search documentation of ash\_sqlite
2357 | 
2358 | Settings
2359 | 
2360 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/README.md#L1 "View Source") Home
2361 | 
2362 | ![Logo](https://github.com/ash-project/ash/blob/main/logos/cropped-for-header-black-text.png?raw=true#gh-light-mode-only) ![Logo](https://github.com/ash-project/ash/blob/main/logos/cropped-for-header-white-text.png?raw=true#gh-dark-mojde-only)
2363 | 
2364 | [![CI](https://github.com/ash-project/ash_sqlite/actions/workflows/elixir.yml/badge.svg)](https://github.com/ash-project/ash_sqlite/actions/workflows/elixir.yml) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Hex version badge](https://img.shields.io/hexpm/v/ash_sqlite.svg)](https://hex.pm/packages/ash_sqlite) [![Hexdocs badge](https://img.shields.io/badge/docs-hexdocs-purple)](../ash_sqlite.html)
2365 | 
2366 | # AshSqlite
2367 | 
2368 | Welcome! [`AshSqlite`](AshSqlite.html) is the SQLite data layer for [Ash Framework](../ash.html).
2369 | 
2370 | ## [](readme.html#tutorials)Tutorials
2371 | 
2372 | - [Get Started](getting-started-with-ash-sqlite.html)
2373 | 
2374 | ## [](readme.html#topics)Topics
2375 | 
2376 | - [What is AshSqlite?](what-is-ash-sqlite.html)
2377 | 
2378 | ### [](readme.html#resources)Resources
2379 | 
2380 | - [References](references.html)
2381 | - [Polymorphic Resources](polymorphic-resources.html)
2382 | 
2383 | ### [](readme.html#development)Development
2384 | 
2385 | - [Migrations and tasks](migrations-and-tasks.html)
2386 | - [Testing](testing.html)
2387 | 
2388 | ### [](readme.html#advanced)Advanced
2389 | 
2390 | - [Expressions](expressions.html)
2391 | - [Manual Relationships](manual-relationships.html)
2392 | 
2393 | ## [](readme.html#reference)Reference
2394 | 
2395 | - [AshSqlite.DataLayer DSL](dsl-ashsqlite-datalayer.html)
2396 | 
2397 | [← Previous Page API Reference](api-reference.html)
2398 | 
2399 | [Next Page → Getting Started With AshSqlite](getting-started-with-ash-sqlite.html)
2400 | 
2401 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) ([current file](https://preview.hex.pm/preview/ash_sqlite/0.2.3/show/README.md)) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
2402 | 
2403 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
2404 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
2405 | 
2406 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
2407 | 
2408 | v0.2.3
2409 | 
2410 | - Pages
2411 | - Modules
2412 | - Mix Tasks
2413 | 
2414 | <!--THE END-->
2415 | 
2416 | <!--THE END-->
2417 | 
2418 | <!--THE END-->
2419 | 
2420 | Search documentation of ash\_sqlite
2421 | 
2422 | Settings
2423 | 
2424 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/documentation/topics/resources/references.md#L1 "View Source") References
2425 | 
2426 | To configure the foreign keys on a resource, we use the `references` block.
2427 | 
2428 | For example:
2429 | 
2430 | ```
2431 | references do
2432 |   reference :post, on_delete: :delete, on_update: :update, name: "comments_to_posts_fkey"
2433 | end
2434 | ```
2435 | 
2436 | ## [](references.html#important)Important
2437 | 
2438 | No resource logic is applied with these operations! No authorization rules or validations take place, and no notifications are issued. This operation happens *directly* in the database. That
2439 | 
2440 | ## [](references.html#nothing-vs-restrict)Nothing vs Restrict
2441 | 
2442 | The difference between `:nothing` and `:restrict` is subtle and, if you are unsure, choose `:nothing` (the default behavior). `:restrict` will prevent the deletion from happening *before* the end of the database transaction, whereas `:nothing` allows the transaction to complete before doing so. This allows for things like updating or deleting the destination row and *then* updating updating or deleting the reference(as long as you are in a transaction).
2443 | 
2444 | ## [](references.html#on-delete)On Delete
2445 | 
2446 | This option is called `on_delete`, instead of `on_destroy`, because it is hooking into the database level deletion, *not* a `destroy` action in your resource.
2447 | 
2448 | [← Previous Page What is AshSqlite?](what-is-ash-sqlite.html)
2449 | 
2450 | [Next Page → Polymorphic Resources](polymorphic-resources.html)
2451 | 
2452 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) ([current file](https://preview.hex.pm/preview/ash_sqlite/0.2.3/show/documentation/topics/resources/references.md)) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
2453 | 
2454 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
2455 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
2456 | 
2457 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
2458 | 
2459 | v0.2.3
2460 | 
2461 | - Pages
2462 | - Modules
2463 | - Mix Tasks
2464 | 
2465 | <!--THE END-->
2466 | 
2467 | <!--THE END-->
2468 | 
2469 | <!--THE END-->
2470 | 
2471 | Search documentation of ash\_sqlite
2472 | 
2473 | Settings
2474 | 
2475 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/documentation/topics/development/testing.md#L1 "View Source") Testing With Sqlite
2476 | 
2477 | Testing resources with SQLite generally requires passing `async?: false` to your tests, due to `SQLite`'s limitation of having a single write transaction open at any one time.
2478 | 
2479 | This should be coupled with to make sure that Ash does not spawn any tasks.
2480 | 
2481 | ```
2482 | config :ash, :disable_async?, true
2483 | ```
2484 | 
2485 | [← Previous Page Migrations](migrations-and-tasks.html)
2486 | 
2487 | [Next Page → Expressions](expressions.html)
2488 | 
2489 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) ([current file](https://preview.hex.pm/preview/ash_sqlite/0.2.3/show/documentation/topics/development/testing.md)) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
2490 | 
2491 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
2492 | [![ash_sqlite](assets/logo.png)](https://github.com/ash-project/ash_sqlite)
2493 | 
2494 | [ash\_sqlite](https://github.com/ash-project/ash_sqlite)
2495 | 
2496 | v0.2.3
2497 | 
2498 | - Pages
2499 | - Modules
2500 | - Mix Tasks
2501 | 
2502 | <!--THE END-->
2503 | 
2504 | <!--THE END-->
2505 | 
2506 | <!--THE END-->
2507 | 
2508 | Search documentation of ash\_sqlite
2509 | 
2510 | Settings
2511 | 
2512 | # [View Source](https://github.com/ash-project/ash_sqlite/blob/v0.2.3/documentation/topics/about-ash-sqlite/what-is-ash-sqlite.md#L1 "View Source") What is AshSqlite?
2513 | 
2514 | AshSqlite is the SQLite [`Ash.DataLayer`](../ash/3.4.58/Ash.DataLayer.html) for [Ash Framework](../ash.html). This doesn't have all of the features of [AshPostgres](../ash_postgres.html), but it does support most of the features of Ash data layers. The main feature missing is Aggregate support.
2515 | 
2516 | Use this to persist records in a SQLite table. For example, the resource below would be persisted in a table called `tweets`:
2517 | 
2518 | ```
2519 | defmodule MyApp.Tweet do
2520 |   use Ash.Resource,
2521 |     data_layer: AshSQLite.DataLayer
2522 | 
2523 |   attributes do
2524 |     integer_primary_key :id
2525 |     attribute :text, :string
2526 |   end
2527 | 
2528 |   relationships do
2529 |     belongs_to :author, MyApp.User
2530 |   end
2531 | 
2532 |   sqlite do
2533 |     table "tweets"
2534 |     repo MyApp.Repo
2535 |   end
2536 | end
2537 | ```
2538 | 
2539 | The table might look like this:
2540 | 
2541 | idtextauthor\_id1"Hello, world!"1
2542 | 
2543 | Creating records would add to the table, destroying records would remove from the table, and updating records would update the table.
2544 | 
2545 | [← Previous Page Getting Started With AshSqlite](getting-started-with-ash-sqlite.html)
2546 | 
2547 | [Next Page → References](references.html)
2548 | 
2549 | [Hex Package](https://hex.pm/packages/ash_sqlite/0.2.3) [Hex Preview](https://preview.hex.pm/preview/ash_sqlite/0.2.3) ([current file](https://preview.hex.pm/preview/ash_sqlite/0.2.3/show/documentation/topics/about-ash-sqlite/what-is-ash-sqlite.md)) Search HexDocs [Download ePub version](ash_sqlite.epub "ePub version")
2550 | 
2551 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
2552 | 
```
Page 4/10FirstPrevNextLast