nia/sql-operation

包含使用 `nia/sql-adapter` 组件进行简单 CRUD 操作的组件。

此软件包的官方仓库似乎已丢失,因此该软件包已被冻结。

1.0.2 2018-12-10 17:55 UTC

This package is not auto-updated.

Last update: 2022-03-16 11:58:50 UTC


README

包含使用 nia/sql-adapter 组件进行简单 CRUD 操作的组件。

安装

使用 Composer 需要此软件包。

composer require nia/sql-operation

测试

运行单元测试使用以下命令

$ cd /path/to/nia/component/
$ phpunit --bootstrap=vendor/autoload.php tests/

如何使用

以下示例展示了如何使用类进行简单的 CRUD 操作。

// create usert
$operation = new InsertOperation($writingAdapter);
$id = $operation->insert('user', [
    'email' => 'foo@bar.baz',
    'password' => password_hash($password, PASSWORD_DEFAULT)
]);

// update user (change email address)
$operation = new UpdateOperation($writingAdapter);
$operation->update('user', $id, [
    'email' => 'faz@baz.boo'
]);

// fetch user
$operation = new FetchOperation($readingAdapter);
$user = $operation->fetch('user', $id);

// delete user
$operation = new UpdateOperation($writingAdapter);
$operation->delete('user', $id);