定制 nicodinus/amphp2-sqlite 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

nicodinus/amphp2-sqlite

Composer 安装命令:

composer require nicodinus/amphp2-sqlite

包简介

Async SQLite client based on legacy version of amphp/amp framework (^2.6)

README 文档

README

License

nicodinus/amphp2-sqlite is a non-blocking sqlite client for amphp:^2.6 using parallel

Installation

composer require nicodinus/amphp2-sqlite

Usage

<?php

declare(strict_types=1);

use Amp\Loop;
use Vajexal\AmpSQLite\SQLiteCommandResult;
use Vajexal\AmpSQLite\SQLiteConnection;
use Vajexal\AmpSQLite\SQLiteResultSet;
use Vajexal\AmpSQLite\SQLiteStatement;
use function Vajexal\AmpSQLite\connect;

require_once 'vendor/autoload.php';

Loop::run(function () {
    /** @var SQLiteConnection $connection */
    $connection = yield connect('database.sqlite');

    yield $connection->execute('drop table if exists users');
    yield $connection->execute('create table users (id integer primary key, name text not null)');
    yield $connection->execute('insert into users (name) values (:name)', [
        ':name' => 'Bob',
    ]);

    /** @var SQLiteResultSet $results */
    $results = yield $connection->query('select * from users');
    while (yield $results->advance()) {
        $row = $results->getCurrent();
        echo "Hello {$row['name']}\n";
    }

    /** @var SQLiteStatement $statement */
    $statement = yield $connection->prepare('update users set name = :name where id = 1');
    /** @var SQLiteCommandResult $result */
    $result = yield $statement->execute([
        ':name' => 'John',
    ]);
    echo "Updated {$result->getAffectedRowCount()} rows\n";
});

Transactions

<?php

declare(strict_types=1);

use Amp\Loop;
use Vajexal\AmpSQLite\SQLiteConnection;
use Vajexal\AmpSQLite\SQLiteTransaction;
use function Vajexal\AmpSQLite\connect;

require_once 'vendor/autoload.php';

Loop::run(function () {
    /** @var SQLiteConnection $connection */
    $connection = yield connect('database.sqlite');

    yield $connection->execute('drop table if exists users');
    yield $connection->execute('create table users (id integer primary key, name text not null)');

    /** @var SQLiteTransaction $transaction */
    $transaction = yield $connection->beginTransaction();
    yield $transaction->execute('insert into users (name) values (:name)', [
        ':name' => 'Bob',
    ]);

    yield $transaction->createSavepoint('change_name');
    yield $transaction->execute('update users set name = :name where id = 1', [
        ':name' => 'John',
    ]);
    yield $transaction->releaseSavepoint('change_name');

    yield $transaction->commit();
});

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固