schema-keeper/executor 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

schema-keeper/executor

Composer 安装命令:

composer require schema-keeper/executor

包简介

Simple interaction with PostgreSQL stored procedures

README 文档

README

Minimum PHP Version Minimum PostgreSQL Version Build Status Codecov

The Executor helps to execute PL/pgSQL stored procedures.

Examples

Exception handling

Suppose stored procedure throws an exception:

CREATE OR REPLACE FUNCTION public.test_function() 
  RETURNS VOID
  LANGUAGE plpgsql
AS $function$
BEGIN
   RAISE EXCEPTION 'MyException' USING HINT = 'TestHint';
END;
$function$;

The way to call it via Executor:

<?php

use SchemaKeeper\Tools\Executor\Fetcher\SingleColumn;
use SchemaKeeper\Tools\Executor\Exception\RaisedException;

try {
    $executor->execFunc('public.test_function', [], new SingleColumn()); 
} catch (RaisedException $e) {
    echo $e->getExceptionName().' '.$e->getExceptionHint();
}

Echo in the catch block will output: "MyException TestHint"

Fetching

Suppose stored procedure returns a table:

CREATE OR REPLACE FUNCTION public.test_function(_dummy TEXT)
    RETURNS TABLE(param1 INTEGER, param2 TEXT)
    LANGUAGE plpgsql
AS $function$
BEGIN
    param1 = 1;
    param2 = 'One';
    RETURN NEXT;

    param1 = 2;
    param2 = 'Two';
    RETURN NEXT;

    RETURN;
END;
$function$;

Executor provides three different fetchers:

<?php

use SchemaKeeper\Tools\Executor\Fetcher\SingleColumn;
use SchemaKeeper\Tools\Executor\Fetcher\SingleRow;
use SchemaKeeper\Tools\Executor\Fetcher\MultipleRow;

$params = [':dummy' => 'test'];

$result1 = $executor->execFunc('public.test_function', $params, new SingleColumn());
$result2 = $executor->execFunc('public.test_function', $params, new SingleRow());
$result3 = $executor->execFunc('public.test_function', $params, new MultipleRow());

var_dump($result1, $result2, $result3);

var_dump will output:

int(1)

array(2) {
  'param1' =>
  int(1)
  'param2' =>
  string(3) "One"
}

array(2) {
  [0] =>
  array(2) {
    'param1' =>
    int(1)
    'param2' =>
    string(3) "One"
  }
  [1] =>
  array(2) {
    'param1' =>
    int(2)
    'param2' =>
    string(3) "Two"
  }
}

Initialization

<?php

use SchemaKeeper\Tools\Executor\Connection\PDOProxy;
use SchemaKeeper\Tools\Executor\ErrorHandler;
use SchemaKeeper\Tools\Executor\Executor;

$dsn = 'pgsql:dbname=schema_keeper;host=localhost';

$pdo = new PDO($dsn, 'postgres', 'postgres', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);

$conn = new PDOProxy($pdo);

$errorHandler = new ErrorHandler();

$executor = new Executor($conn, $errorHandler);

Contributing

Please refer to CONTRIBUTING.md for information on how to contribute to SchemaKeeper.

统计信息

  • 总下载量: 18
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-04-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固