| 1 | # SQL persistence |
| 2 | |
| 3 | Every store in the EDC, intended as persistence for state, comes out of the box with two implementations: |
| 4 | - in-memory |
| 5 | - sql (postgresql dialect) |
| 6 | |
| 7 | By default, the `in-memory` stores are provided by the dependency injection, the `sql` implementations can be used by |
| 8 | simply registering the relative extensions (e.g. `asset-index-sql`, `contract-negotiation-store-sql`, ...). |
| 9 | |
| 10 | ## Configuration |
| 11 | |
| 12 | ### DataSources |
| 13 | |
| 14 | For using `sql` extensions, a `DataSource` is needed, and it should be registered on the `DataSourceRegistry` service. |
| 15 | |
| 16 | The `sql-pool-apache-commons` extension takes care to create and register pooled data sources starting from configuration. |
| 17 | It expects at least one data source called `default` that can be configured with `Vault` keys: |
| 18 | ``` |
| 19 | edc.datasource.default.url=... |
| 20 | edc.datasource.default.name=... |
| 21 | edc.datasource.default.password=... |
| 22 | ``` |
| 23 | (note: if no vault entries are found for such keys, they will be obtained from the configuration). |
| 24 | |
| 25 | Other datasources can be defined using the same settings structure: |
| 26 | ``` |
| 27 | edc.datasource.<datasource-name>.url=... |
| 28 | edc.datasource.<datasource-name>.name=... |
| 29 | edc.datasource.<datasource-name>.password=... |
| 30 | ``` |
| 31 | |
| 32 | `<datasource-name>` can be a string that then can be used by the stores configuration to use specific data sources. |
| 33 | |
| 34 | ### Using custom datasource in stores |
| 35 | |
| 36 | Using a custom datasource in a store can be done by configuring the setting: |
| 37 | ``` |
| 38 | edc.sql.store.<store-context>.datasource=<datasource-name> |
| 39 | ``` |
| 40 | |
| 41 | This way the `<store-context>` (that could be `asset`, `contractnegotiation`...) will use the `<datasource-name>` datasource. |