adachsoft/dynamic-table-in-memory 问题修复 & 功能扩展

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

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

adachsoft/dynamic-table-in-memory

最新稳定版本:v0.1.0

Composer 安装命令:

composer require adachsoft/dynamic-table-in-memory

包简介

In-memory RAM implementation of adachsoft/dynamic-table-contract

README 文档

README

License

In-memory (RAM-based) implementation of the adachsoft/dynamic-table-contract package.

Provides complete CRUD for tables and rows, plus powerful querying capabilities (findBy()) with filtering, sorting, pagination, and column projection — all executed in memory without any external database.

Features

  • Fully implements TableRepositoryInterface and QueryableRowRepositoryInterface
  • Isolated in-memory store (no static state, multiple independent instances supported)
  • Efficient query engine with:
    • Complex filters (AND/OR/NOT, comparisons, LIKE, IN, null checks)
    • Multi-level sorting (ASC/DESC)
    • Pagination with accurate totalCount
    • Projection/aliasing with expressions (CONCAT, TEMPLATE, JSON_EXTRACT, literals)
  • Zero dependencies beyond the contract and PHP 8.2+
  • Testable and lightweight

Installation

Add to your composer.json (in monorepo setup):

{
    "repositories": [
        {
            "type": "path",
            "url": "packages/dynamic-table-in-memory"
        }
    ],
    "require": {
        "adachsoft/dynamic-table-in-memory": "*"
    }
}

Then run:

composer install

Usage

Basic Setup

use AdachSoft\DynamicTableInMemory\Store\InMemoryStore;
use AdachSoft\DynamicTableInMemory\Repository\InMemoryTableRepository;
use AdachSoft\DynamicTableInMemory\Repository\InMemoryRowRepository;
use AdachSoft\DynamicTableInMemory\Query\ExpressionEvaluator;
use AdachSoft\DynamicTableInMemory\Query\FilterEvaluator;
use AdachSoft\DynamicTableInMemory\Query\RowProjector;

// Create shared store
$store = new InMemoryStore();

// Repositories
$tableRepo = new InMemoryTableRepository($store);

$expressionEvaluator = new ExpressionEvaluator();
$filterEvaluator = new FilterEvaluator($expressionEvaluator);
$rowProjector = new RowProjector($expressionEvaluator);

$rowRepo = new InMemoryRowRepository(
    $store,
    $filterEvaluator,
    $expressionEvaluator,
    $rowProjector
);

Creating a Table

use AdachSoft\DynamicTableContract\Dto\NewTableDto;
use AdachSoft\DynamicTableContract\Dto\ColumnDto;
use AdachSoft\DynamicTableContract\Type\BuiltIn\StringType;
use AdachSoft\DynamicTableContract\Type\BuiltIn\IntType;

$columns = [
    new ColumnDto('id', new IntType()),
    new ColumnDto('name', new StringType()),
    new ColumnDto('email', new StringType()),
];

$table = $tableRepo->create(new NewTableDto('users', $columns));

Row Operations

use AdachSoft\DynamicTableContract\Dto\NewRowDto;

// Add row (auto ID)
$row = $rowRepo->add('users', null, new NewRowDto([
    'name' => 'John Doe',
    'email' => 'john@example.com',
]));

// Get by ID
$retrieved = $rowRepo->getById('users', $row->id);

// Update
$rowRepo->update('users', $row->id, new NewRowDto([
    'name' => 'Jane Doe',
    'email' => 'jane@example.com',
]));

// Delete
$rowRepo->delete('users', $row->id);

Advanced Querying with findBy()

use AdachSoft\DynamicTableContract\Query\Dto\QueryParametersDto;
use AdachSoft\DynamicTableContract\Query\Filter\EqualsCondition;
use AdachSoft\DynamicTableContract\Query\Filter\AndFilter;
use AdachSoft\DynamicTableContract\Query\Sort\SortVo;
use AdachSoft\DynamicTableContract\Query\Pagination\PaginationVo;
use AdachSoft\DynamicTableContract\Query\Expression\ConcatExpressionVo;

// Example filter: name LIKE '%doe%' AND email IS NOT NULL
$filter = new AndFilter([
    new LikeCondition::column('name', '%doe%'),
    new IsNotNullCondition::column('email'),
]);

// Sort by name ASC, then email DESC
$sorts = new SortCollection([
    SortVo::asc('name'),
    SortVo::desc('email'),
]);

// Pagination and projection
$params = new QueryParametersDto(
    filter: $filter,
    sorts: $sorts,
    pagination: new PaginationVo(page: 1, perPage: 10),
    selectedColumns: [
        'full_name' => new ConcatExpressionVo(['name', 'email'], ' - '),
        'email',
    ]
);

$result = $rowRepo->findBy('users', $params);

echo 'Total matching rows: ' . $result->totalCount . PHP_EOL;
foreach ($result->rows->all() as $row) {
    echo $row->values['full_name'] . PHP_EOL;
}

See the contract documentation for full details on DTOs, expressions, filters, and types.

Testing

Run tests with:

cd packages/dynamic-table-in-memory
composer install
vendor/bin/phpunit

Or from root:

vendor/bin/phpunit --testsuite=InMemory

(All functional tests for both repositories are included in tests/Functional/.)

License

MIT License - see LICENSE file.

Contributing

See the main monorepo CONTRIBUTING.md.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固