Fusio Api 之链接MySQL数据库

fusio5个月前更新 admin
143 1

版本:Fusio (5.1.0)

路径:网址/apps/fusio/

进入API菜单下的connection页面,点击‘+’,下面的配置按实际填写

Fusio Api 之链接MySQL数据库

添加其他数据库雷同,应为用不上没测试其他。

以下为翻译官方文档

Connection使 Fusio 能够连接到其他远程服务。这可以是数据库或消息队列服务。 请查看适配器,查看所有可用连接的列表。 开发您自己的自定义连接也很容易。

Name:连接的名称。

Class:connection 类。除了选择连接外,您还可以使用 edit (编辑) 按钮输入自定义连接类。

Config:所有其他输入字段都是基于Class的选择而需要输入。

目前还用不上这东西。

Development:要开发自定义连接,您需要创建一个实现 interface 的类

Fusio\Engine\ConnectionInterface

通常,连接应返回一个完全配置的对象,该对象可在操作中使用。 即,数据库连接返回一个配置的 doctrine DBAL 实例,因此用户不需要 在操作中提供任何凭证。

在以下示例连接中:

<?php

namespace App\Connection;

use Fusio\Engine\ConnectionInterface;
use Fusio\Engine\Form\BuilderInterface;
use Fusio\Engine\Form\ElementFactoryInterface;
use Fusio\Engine\ParametersInterface;

class AcmeConnection implements ConnectionInterface
{
    public function getName(): string
    {
        return 'Acme-Client';
    }

    public function getConnection(ParametersInterface $config): MyClient
    {
        return new MyClient(
            $config->get('username'),
            $config->get('password'),
        );
    }

    public function configure(BuilderInterface $builder, ElementFactoryInterface $elementFactory): void
    {
        $builder->add($elementFactory->newInput('username', 'Username', 'text', 'The name of the service user'));
        $builder->add($elementFactory->newInput('password', 'Password', 'password', 'The password of the service user'));
    }
}

© 版权声明

相关文章