mwd/marquee
MySQL的Entity Framework
v1.0
2021-01-21 04:19 UTC
Requires
- ext-json: *
- ext-pdo: *
- ext-redis: *
- symfony/inflector: ^5.2
This package is auto-updated.
Last update: 2024-09-16 23:46:07 UTC
README
概览
Marquee是一个免费的多数据库抽象层和ORM。它的目的是在利用智能数据源的同时,允许使用通用的代码模式。无论你选择将数据存储在Redis、MySQL,甚至CSV中,99%的PHP代码都保持不变。
数据库支持
- Redis: 测试中
- MySQL: Alpha / 测试中
- SQLite: 计划中
- MSSQL: 计划中
- CSV: 计划中
- JSON: 计划中
- PostgreSQL: 计划中
- Azure Cosmos DB: 计划中
关于作者
我叫查尔斯·佩伦斯。我是一位来自密歇根州的自学成才的软件工程师。我热衷于通过自动化和创新简化Web开发过程。我擅长创建简洁、语义化的API。我相信代码的冗长不应仅依赖于注释。此项目通过使用简单、易懂、可预测的方法和类名,同时保持灵活的功能,允许编写表达式的代码。我希望你会发现我的工作能够帮助你快速开始你的下一个项目。
https://charlespellens.me/ | contact@charlespellens.com
免责声明:非生产就绪
虽然我对这个项目的进展感到非常自豪,但请在此阶段不要将其用于任何关键任务工作。这是一个正在进行中的项目,我邀请你尝试使用它或将其变成你自己的。
快速入门/示例
<?php include 'vendor/autoload.php'; /** * Library Use Statements */ use Marquee\Core\Connection\MySQLConnection; use Marquee\Data\Entity; use Marquee\Exception\Exception; use Marquee\Schema\Property; /** * PHP Core Use Statements */ use \Generator; /** * Define a sample entity with two string properties: * - username * - password */ class User extends Entity { public function getUsername(): string { return $this->username; } public static function Properties(): Generator { yield Property::string('username')->unique(); yield Property::string('password'); } } $db = new MySQLConnection(MySQLConnection::CreateDsn(DB_HOST, DB_PORT, DB_PASSWORD, DB_USERNAME)); $db->selectDb(DB_NAME); if ($db->tryConnect($e)) { try { /** * Build the user table if it doesn't already exist in the schema */ $table = User::BuildTable($db); if (!$table->exists()) { $table->create(); echo 'Created user table', '<br>'; } /** * Query all users */ $userCount = 0; $users = $db->query(User::class)->limit(10)->get(); echo '<ul>'; while ($user = $users->next()) { echo '<li>', $user, '</li>'; $userCount++; } echo '</ul>'; /** * If we have less than 10 users, insert a new one. */ if ($userCount < 10) { $insert = $db->query(User::class)->create([ 'username' => 'Test ' . uniqid(), 'password' => password_hash('test password', PASSWORD_ARGON2I) ]); if ($user = $insert->next()) { echo 'Created test user'; } } else { /** * Start over if we have 10 users */ $db->query(User::class)->truncate()->next(); echo 'Deleted all users'; } } catch (Exception $e) { echo 'Error: ', $e->getMessage(); } finally { $db->disconnect(); } } else { exit($e->getMessage()); }