tivins/orm 问题修复 & 功能扩展

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

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

tivins/orm

Composer 安装命令:

composer require tivins/orm

包简介

basic php orm

README 文档

README

Install

composer install tivins/orm

Configuration

ORM use Tivins/Database.

use Tivins\ORM\DB;
use Tivins\Database\Database;
use Tivins\Database\Connectors\MySQLConnector;

# Define ORM/DB::$db with mysql connection. 
DB::$db = new Database(new MySQLConnector('my_database', 'root', 'secret'));

basic example

1 - Create a model

use Tivins\App\Models;
use \Tivins\ORM\Table;
use \Tivins\ORM\Column;

#[Table('books')]
class Book extends Model
{
    #[Column(primary: true)] 
    protected int $id = 0;
    
    #[Column] 
    protected string $title = '';
    
    #[Column] 
    protected string $author = '';
    
    #[Column] 
    protected int $year = 0;

    // add getters/setters,
    // and custom methods.
}

Usage:

# create
$book = (new Book())
    ->setTitle("Le Petit Prince")
    ->setAuthor("Antoine de Saint-Exupéry")
    ->setYear(1943)
    ->save();
$book->getId(); // ex: 123

# load and update
$book = Book::getInstance(123);
$book->setTitle("Changed title")->save();
$book->getId(); // 123 

# load by
$book = (new Book())->loadBy(['name' => 'Changed title']);
$book->getId(); // 123 

Collection

// Get an array of objects
$books = Book::getSelectQuery('b')->addFields('b')->execute()->fetchAll();
// convert to Book[] array.
$books = Book::mapCollection($books);

Please, refer to Database documentation to learn more about SelectQuery.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-12