andrewlamers / eloquent-rest-bridge
eloquent 的连接驱动,通过 HTTP 转发 SQL 语句,并将数据返回到 eloquent 模型中。
v0.1.5
2018-05-30 20:06 UTC
Requires
- guzzlehttp/guzzle: ~6
- illuminate/console: ^5.1
- illuminate/container: ^5.1
- illuminate/database: ^5.1
- illuminate/encryption: ^5.1
- illuminate/events: ^5.1
- illuminate/http: ^5.1
- illuminate/routing: ^5.1
- illuminate/support: ^5.1
README
illuminate 数据库管理器的连接驱动,通过 HTTP 将 SQL 语句转发到目标主机上运行的服务。
这显著减少了通过 TCP 连接建立的传统的连接传输大小。
主机将执行 SQL 语句,并以 JSON 格式返回结果,这些结果被解析回数据库管理器,就像它是直接的数据库连接一样。
支持 SSL,但不是必需的,因为所有请求和响应体都通过 AES 和预共享密钥加密。
这对于通过有限带宽连接或通过防火墙检索结果非常有用。减少的传输大小使得响应时间比通过 SSH 端口隧道传输原始数据库命令要快得多。
安装
composer require andrewlamers/eloquent-rest-bridge
Laravel 服务提供者
在您的 config/app.php 的服务提供者列表中包含此服务。
Andrewlamers\EloquentRestBridge\ServiceProvider::class
Laravel 配置文件
包含一个用于 laravel 的配置文件,允许您修改 rest bridge 的配置。
要使用以下命令将配置文件移动到您的项目 config/ 文件夹。
php artisan vendor:publish --provider="Andrewlamers\EloquentRestBridge\ServiceProvider"
配置选项
return array(
'encryption' => [
/*
* Available ciphers are AES-256-CBC and AES-128-CBC
*/
'cipher' => env('REST_BRIDGE_CIPHER', 'AES-256-CBC'),
/*
* The key must match the cipher. AES-256 must be a 32 bit key, and AES-128 must be a 16 byte key
* You can use the php artisan key:generate --show command to generate a key. Do not use the same key as your application.
* The encrypter will look for the key in the environment value with the key name specified here.
*/
'key' => 'REST_BRIDGE_KEY'
],
/*
* The url that is listening for sql commands to return results from.
*/
'url' => env('REST_BRIDGE_URL'),
'log' => [
/*
* Enable logging of requests, responses, and sql commands.
*/
'enabled' => false,
/*
* Base path for the log files. It will create 3 log files for requests, responses, and sql queries.
*/
'base_path' => storage_path('logs/')
],
'daemon' => [
'enabled' => false,
'route' => '_rest_bridge/handler'
]
);
示例数据库配置
在您的数据库配置中,'rest' 驱动程序将可用。它需要知道您想要使用的连接。
'my-db-connection' => [
'driver' => 'sqlsrv',
'host' => env('SQLSRV_HOST', ''),
'database' => env('SQLSRV_DATABASE', ''),
'username' => env('SQLSRV_USERNAME', ''),
'password' => env('SQLSRV_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
],
'my-rest-connection' => [
'driver' => 'rest',
'connection' => 'my-db-connection'
]
rest 驱动程序将配置选项转发到侦听命令的守护程序。