berlindb/core
Composer 安装命令:
composer require berlindb/core
包简介
A collection of PHP classes and functions that aims to provide an ORM-like experience and interface to WordPress database tables.
README 文档
README
BerlinDB provides an ORM-like interface for custom database tables in WordPress.
Use it when custom post types, taxonomies, or post meta are no longer the right
storage model for your data, but you still want a WordPress-native developer
experience: wpdb compatibility, schema objects, query builders, row objects,
caching hooks, and table upgrade routines.
Requirements
- PHP 8.1 or newer
- WordPress
- Composer
Installation
composer require berlindb/core
Quick Start
A typical integration defines four small classes:
- a
Schemathat describes columns and indexes - a
Tablethat creates and upgrades the database table - a
Rowthat shapes returned records - a
Querythat reads and writes records
Define A Schema
<?php namespace Acme\Plugin\Database; use BerlinDB\Database\Kern\Schema; class WidgetSchema extends Schema { public $columns = array( array( 'name' => 'id', 'type' => 'bigint', 'length' => '20', 'unsigned' => true, 'extra' => 'auto_increment', 'default' => false, 'cache_key' => true, 'sortable' => true, ), array( 'name' => 'name', 'type' => 'varchar', 'length' => '200', 'default' => '', 'searchable' => true, 'sortable' => true, ), array( 'name' => 'status', 'type' => 'varchar', 'length' => '20', 'default' => 'active', 'cache_key' => true, 'in' => true, 'not_in' => true, ), array( 'name' => 'date_created', 'type' => 'datetime', 'default' => '', 'created' => true, 'sortable' => true, ), ); public $indexes = array( array( 'type' => 'primary', 'columns' => array( 'id' ), ), array( 'name' => 'status', 'type' => 'key', 'columns' => array( 'status' ), ), ); }
Define A Table
<?php namespace Acme\Plugin\Database; use BerlinDB\Database\Kern\Table; class WidgetTable extends Table { protected $schema = WidgetSchema::class; protected $name = 'acme_widgets'; protected $version = '202605280'; }
Create or upgrade the table during your plugin's install or upgrade routine:
( new WidgetTable() )->install();
Define A Row
<?php namespace Acme\Plugin\Database; use BerlinDB\Database\Kern\Row; class Widget extends Row { public $id = 0; public $name = ''; public $status = 'active'; public $date_created = ''; }
Define A Query
<?php namespace Acme\Plugin\Database; use BerlinDB\Database\Kern\Query; class WidgetQuery extends Query { protected $prefix = 'acme'; protected $table_name = 'widgets'; protected $table_alias = 'w'; protected $table_schema = WidgetSchema::class; protected $item_name = 'widget'; protected $item_name_plural = 'widgets'; protected $item_shape = Widget::class; protected $cache_group = 'acme-widgets'; }
Query Data
$query = new WidgetQuery(); $widget_id = $query->add_item( array( 'name' => 'Example', 'status' => 'active', ) ); $widget = $query->get_item( $widget_id ); $active_widgets = $query->query( array( 'status__in' => array( 'active', 'pending' ), 'orderby' => 'date_created', 'order' => 'DESC', 'number' => 20, ) ); $query->update_item( $widget_id, array( 'status' => 'archived', ) ); $query->delete_item( $widget_id );
Documentation
The project wiki contains deeper documentation for the current object model, including adapters, interfaces, traits, parsers, operators, schemas, tables, and queries.
Development
Install dependencies:
composer install
Run the default test suite:
bin/run-tests.sh -- --group default
Run the suite against a specific PHP and WordPress version:
bin/run-tests.sh -p 8.1 -w 6.7 -- --group default
Run static analysis and coding standards:
vendor/bin/phpstan analyse --memory-limit=1G vendor/bin/phpcs
See CONTRIBUTING.md for the full local workflow.
Name
BerlinDB is named for WordCamp Europe 2019 in Berlin, Germany, where it was originally exhibited and announced as an unnamed utility being used by the Sandhills Development engineering team.
Peter Wilson recommended naming it "Berlin" to commemorate everyone in attendance for its unveiling. Thanks, Peter.
License
BerlinDB is open-source software licensed under the MIT license.
berlindb/core 适用场景与选型建议
berlindb/core 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 434.24k 次下载、GitHub Stars 达 267, 最近一次更新时间为 2021 年 07 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「orm」 「wordpress」 「wpdb」 「custom-tables」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 berlindb/core 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 berlindb/core 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 berlindb/core 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Kinikit - PHP Application development framework MVC component
Store your language lines in the database, yaml or other sources
PHP Database ORM for Symfony1. Do NOT use for new projects: please move to a newest Symfony release and Doctrine2
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
统计信息
- 总下载量: 434.24k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 268
- 点击次数: 22
- 依赖项目数: 7
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-07-12