prappo / wp-eloquent
WordPress 的 Eloquent ORM。
v3.0.5
2024-08-25 08:30 UTC
Requires
- php: ^7.3|^8.0
- ext-json: *
- ext-pdo: *
Suggests
- doctrine/dbal: Required to rename columns and drop SQLite columns (^2.6).
- fzaninotto/faker: Required to use the eloquent factory builder (^1.9.1).
- symfony/finder: Required to use Eloquent model factories (^5.1).
This package is auto-updated.
Last update: 2024-09-25 08:37:02 UTC
README
此包从 Laravel 8.9 提取。
WpEloquent 组件是 PHP 的完整数据库工具包,提供可表达性的查询构建器、ActiveRecord 风格的 ORM 和模式构建器。它目前支持 MySQL、Postgres、SQL Server 和 SQLite。
安装
composer require prappo/wp-eloquent
使用说明
首先,使用连接启动应用程序。
使用 $wpdb 连接
use Prappo\WpEloquent\Application; Application::bootWp();
使用分离的连接
use Prappo\WpEloquent\Application; Application::boot([ 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'database', 'username' => 'root', 'password' => 'password', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ]);
启动应用程序后。您可以使用它如下
使用查询构建器
use Prappo\WpEloquent\Support\Facades\DB; $users = DB::table('users')->where('votes', '>', 100)->get();
其他核心方法可以通过 Capsule 直接访问,方式与 DB 门面相同
use Prappo\WpEloquent\Support\Facades\DB; $results = DB::select('select * from users where id = ?', [1]);
使用模式构建器
use Prappo\WpEloquent\Support\Facades\Schema; Schema::create('users', function ($table) { $table->increments('id'); $table->string('email')->unique(); $table->timestamps(); });
使用 Eloquent ORM
class User extends Prappo\WpEloquent\Database\Eloquent\Model {} $users = User::where('votes', '>', 1)->get();
有关使用此库提供的各种数据库设施的进一步文档,请参阅Laravel 框架文档。