承接 venndev/vosaka-libsql 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

venndev/vosaka-libsql

最新稳定版本:1.0.2

Composer 安装命令:

composer require venndev/vosaka-libsql

包简介

One library support async for all queries database

README 文档

README

Vosaka LibSQL is an asynchronous database library for PHP, built on top of the vosaka-foroutines ecosystem. It provides fully non-blocking, concurrent database operations with built-in connection pooling for both MySQL and PostgreSQL.

Features

  • Asynchronous & Non-blocking: Leverages PHP fibers (via vosaka-foroutines) to handle multiple queries concurrently without blocking the main execution thread.
  • Connection Pools: Built-in efficient connection pooling (AsyncMysqlPool and AsyncPgsqlPool).
  • Multiple Databases: First-class support for both MySQL and PostgreSQL.
  • High Performance: Designed for high-throughput applications requiring vast amounts of concurrent database operations.
  • Type-safe & Modern: Developed with modern PHP 8 features and strict typing.

Installation

You can install the library via Composer:

composer require venndev/vosaka-libsql

(Note: This library requires the venndev/vosaka-fourotines package)

Usage

1. MySQL Connection Pool

Here is a quick example of how to use the AsyncMysqlPool to run concurrent queries non-blocking:

<?php

require 'vendor/autoload.php';

use vosaka\libsql\AsyncMysqlPool;
use vosaka\foroutines\AsyncMain;
use vosaka\foroutines\Launch;
use vosaka\foroutines\Thread;
use vosaka\foroutines\RunBlocking;

#[AsyncMain]
function main(): void
{
    // Initialize the MySQL pool
    $pool = new AsyncMysqlPool(
        host: '127.0.0.1',
        port: 3306,
        user: 'root',
        password: 'password',
        database: 'test_db',
        maxConnections: 20
    );

    // Run concurrent queries
    RunBlocking::new(function () use ($pool) {
        for ($i = 0; $i < 50; $i++) {
            Launch::new(function () use ($pool, $i) {
                // Non-blocking query execution
                $result = $pool->query('SELECT * FROM users WHERE id = ?', [$i % 10 + 1])->await();
                
                // For INSERT/UPDATE/DELETE
                $pool->execute('INSERT INTO logs (message) VALUES (?)', ["Log entry $i"])->await();
            });
        }

        // Clean up
        $pool->closeAll()->await();
    });
}

2. PostgreSQL Connection Pool

Using PostgreSQL is just as easy with AsyncPgsqlPool:

<?php

require 'vendor/autoload.php';

use vosaka\libsql\AsyncPgsqlPool;
use vosaka\foroutines\AsyncMain;
use vosaka\foroutines\Launch;
use vosaka\foroutines\Thread;
use vosaka\foroutines\RunBlocking;

#[AsyncMain]
function main(): void
{
    // Initialize the PostgreSQL pool
    $pool = new AsyncPgsqlPool(
        host: '127.0.0.1',
        port: 5432,
        user: 'postgres',
        password: 'password',
        database: 'test_db',
        maxConnections: 20
    );

    RunBlocking::new(function () use ($pool) {
        Launch::new(function () use ($pool) {
            $result = $pool->query('SELECT * FROM users LIMIT 10')->await();
        });
        $pool->closeAll()->await();
    });
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is open-sourced software licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固