# 安裝自定義的數據源

目前本插件有提供一定數量的數據源，包括但不限於 MySQL, SQLite 等等。這些數據源的設定都需要在 `db.yml` 中去設定。然而，有時候你仍然需要去創建一個本插件內沒有提供的數據源，又或者需要掛接到在團隊核心插件已經創建的數據源上。

在 `v0.0.6` 版本後，你將可以安裝自定義的數據源。首先需要到 `db.yml` 把數據源設置成 `custom`

```yaml
enable: true # 設置啟動 eld-sql
dataSource: "custom" # 設置為自定義

sqlite:
  file: "central.db"

mysql:
  host: 127.0.0.1
  port: 3306
  database: database
  username: username
  password: password
  useSSL: false
  pool:
    name: SQL-Pool
    minSize: 5
    maxSize: 10
    connectionTimeout: 30000
    idleTimeout: 60000
    maxLifeTime: 600000
```

然後，在 `SQLInstallation` 中注入你所自定義的數據源。

```java
    @Override
    public void bindServices(ServiceCollection collection) {
        SQLInstallation sqlInstallation = collection.getInstallation(SQLInstallation.class);
        DataSource dataSource = ... // 獲取你的數據源
        // 請設置與 DataSource 類型一致的 Dialect 類型，這邊以自定義的 MySQL 數據源為例
        sqlInstallation.injectDataSource(dataSource, MySQL8Dialect.class);
    }
```

{% hint style="info" %}
有關 `Dialect` 的類型詳細可到[這裏](https://javabydeveloper.com/what-is-dialect-in-hibernate-and-list-of-dialects/)查看。
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://eric2788.gitbook.io/eldependenci-sql/details/custom-install-datasource.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
