承接 pulunomoe/datamapper 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

pulunomoe/datamapper

Composer 安装命令:

composer require pulunomoe/datamapper

包简介

Super simple data mapper ORM for PHP

README 文档

README

Super simple data mapper ORM for PHP.

Requirements

  • PHP 8+
  • PDO

Features

  • CRUD (wow!)
  • More incoming (soon-ish)

Usage

1. Install with composer

composer require pulunomoe/datamapper

2. Create your entity class

<?php

// src/Entity/Car.php

namespace YourApp\Entity;

use Pulunomoe\DataMapper\Entity;
use Pulunomoe\DataMapper\EntityClass;
use Pulunomoe\DataMapper\Property;

#[Entity('tests')] // Put your table name here
class Car extends EntityClass
{
	#[Property('id')] // Put your column name here
	public int $id;   // "$id" is a special column for primary key

	#[Property('brand')]
	public string $brand;

	#[Property('model')]
	public string $model;
}

3. Call the DataMapper

<?php

// Initialize the data mapper by passing a PDO instance and the entity class name
$dm = new DataMapper($pdo, Car::class);

// Retrieve all cars
$dm->findAll();

// Retrieve all cars by brand
$dm->findAllBy('brand', 'Danke Motoren Werke');

// Retrieve a single car with the id = 1
$dm->findOne(1);

// Save a car to the database
$car = new Car();
$car->brand = 'Honyabishi';
$car->model = 'Super 9001';
$car = $dm->create($car);

// Update a car
$car->model = 'Super 9001 Mark II Type R GT-MAXXX';
$car = $dm->update($car);

// Delete a car with the id = 1
$dm->delete(1);

API

  • Find All

findAll(string $orderBy = '', bool $desc = false, int $limit = 10, int $offset = 0): array

  • Find All By

findAllBy(string $column, string $value, string $orderBy = '', bool $desc = false, int $limit = 10, int $offset = 0): array

  • Find One

function findOne(int $id): ?EntityClass

  • Create

create(EntityClass $object): EntityClass

  • Update

update(EntityClass $object): EntityClass

  • Delete

function delete(int $id): void

Changelog

  • v0.1 : Initial version
  • v0.2 : Added ordering, limit, and find all by

Shameless plug

Like this library? Buy me some coffee or buy me some cendol

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固