java-nile/ 可塑
未知PHP数据库抽象层
0.0.47
2017-10-18 00:47 UTC
Requires
- php: >=5.6
- danielstjules/stringy: ^3.1
- monolog/monolog: ^1.23
Requires (Dev)
- illuminate/database: ^5.4
- javanile/producer: ^0.0.18
- phpunit/phpunit: ^5.7.19
This package is auto-updated.
Last update: 2024-09-21 23:10:50 UTC
README
可塑是一个用于管理MySQL数据库的抽象层,它具有改进的状态更改和数据库模式操作功能。可塑集成ORM类以管理持久对象和适配数据库模式。
寻找贡献者 😎
我们正在寻找对ORM和数据库世界充满热情的贡献者(PHP爱好者),以
- 在代码库中应用PSR代码标准并美化源文件
- 测试库以不同框架,如:Slim、Laravel、ZendFramenwork等...
- 编写并维护更新wiki部分 https://github.com/java-nile/可塑/wiki
- 通过不同类型的推广提高 https://packagist.org.cn/packages/java-nile/可塑 的知名度
我们保证所有贡献者的可见性和感谢,在我们的所有博客文章和讨论java-nile/可塑的文章中都会有大量的星标和公开引用
通过composer安装
我们建议通过composer安装,否则您将需要创建一个问题。
composer require javanile/moldable
开始使用
如何:连接到数据库
<?php // library namespace use Javanile\Moldable\Database; // initialize a database connection object $db = new Database([ 'host' => 'localhost', 'dbname' => 'db_marketing', 'username' => 'root', 'password' => 'p4ssw0rd', 'prefix' => 'prefix_', ]); // '$db' is ready to use for your manipulation
如何:创建ORM类模型
<?php // library namespace use Javanile\Moldable\Storable; // define ORM class-model class Customer extends Storable { public $id = self::PRIMARY_KEY; public $name = ''; } // instance empty object // database tables and fields are automatic generated // or updated if change Customer class $customer = new Customer(); // assign values $customer->name = 'Franky Franco'; // now object persist on DB $customer->store();
如何:创建模式(如果存在则更新)
<?php // '$db' is pre-connected database object (follow: 'How to: Connect to database') // apply method send queries to create // or align database to defined schema $db->apply([ // customer table name 'Customer' => [ // customer fields 'id' => $db::PRIMARY_KEY, // define field as a primary key 'name' => '', // empty string define field as VARCHAR 'points' => 0, // 0 (zero) define field as INT(11) 'born' => $db::DATE, // use to define as date field 'bio' => $db::TEXT, // text for large string and contents ], // products table name 'Products' => [ // products fields 'id' => $db::PRIMARY_KEY, // define field as a primary key 'name' => '', // empty string define field as VARCHAR 'price' => .0, // for float number init field with point-zero ".0" ], ]);
测试设置
要测试库,请按照以下步骤操作
- 运行本地MySQL数据库
- 将文件
phpunit.xml.dist
复制到phpunit.xml
- 使用数据库连接参数更新
phpunit.xml
- 从项目目录运行
./vendor/bin/phpunit
讨论
- https://medium.com/@billmike1994/getting-started-with-moldable-an-orm-for-continuous-migration-d4be845b7c65
- https://github.com/nazneen1/follow/wiki/Utilize-Javanile--php-tool-to-connect-any-database
- https://www.reddit.com/r/PHP/comments/6jsm2d/the_only_php_mysql_orm_for_continuous_delivery/
- https://www.reddit.com/r/PHP/comments/3okj7x/schemadb_a_modern_and_coincise_database/?ref=readnext_4
- https://www.reddit.com/r/PHP/comments/427zvg/schemadb_adapt_schema_of_mysql_db_based_on_class/
- http://fudforum.org/forum/index.php?S=Google%20%5BBot%5D&t=msg&th=123561
- http://www.codingforums.com/php/374551-manipulate-database-schema.html#post1497472
- http://forums.phpfreaks.com/topic/300920-manipulate-database-schema-with-orm/
- http://www.giorgiotave.it/forum/php-mysql/241550-manipolare-lo-schema-del-database.html#post1205019
- http://www.iprogrammatori.it/forum-programmazione/php/manipolare-schema-del-database-t27275.html
- http://ctolib.com/java-nile-moldable.html
路线图
- 支持MongoDB,以便透明地切换MySQL/MongoDB
- 管理存储键值对(如设置、配置或元字段)的表
- 管理UUID字段(大整数或哈希字符串),作为PRIMARY_KEY索引的替代
- 灵活的连接系统,以在运行时扩展表模型字段
- 为子集字段定义编码/解码静态方法
- 实现工作单元模式
- 监听查询事件(为模型和数据库查询管理钩子/事件)