softwarepunt/instarecord 问题修复 & 功能扩展

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

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

softwarepunt/instarecord

最新稳定版本:v0.7.0

Composer 安装命令:

composer require softwarepunt/instarecord

包简介

ActiveRecord Database ORM layer for MySQL

README 文档

README

✨ A hyper productive ORM for PHP.

Packagist Version PHPUnit

Instarecord makes it super easy and fun to work with MySQL databases in PHP. It's fast and intuitive, and loaded with optional features to make your life easier.

The pitch

🧙‍♂️ Define your models with typed variables, and Instarecord figures out the rest!

<?php

class User extends Model
{
    public int $id;
    public string $email;
    public ?string $name;
}

$user = new User();
$user->email = "bob@web.net";
$user->save(); 

echo "Created user #{$user->id}!";

Features

🗺️ Object Mapping

Define your models as pure PHP classes with typed properties. Use them like regular objects.

📦 Easy CRUD

Use intuitive object-oriented CRUD (create, read, update, and delete) operations on your models.

🔎 Query Builder

Use the query builder to quickly build and run more complex queries with prepared statements.

🤝 Relationships

Set up relationships between your models and easily load them in an optimized way.

Validation

Add constraints to your model properties and validate them with user-friendly error messages.

🕑 Caching

Use model caching features to prevent unnecessary or duplicate queries.

Quickstart

Installation

Add Instarecord to your project with Composer:

composer require softwarepunt/instarecord

Configuration

Pass your own DatabaseConfig or modify the default one:

<?php

use SoftwarePunt\Instarecord\Instarecord;

$config = Instarecord::config();
$config->charset = "utf8mb4";
$config->unix_socket = "/var/run/mysqld/mysqld.sock";
$config->username = "my_user";
$config->password = "my_password";
$config->database = "my_database";
$config->timezone = "UTC";

Use models

Defines your models by creating normal classes with public properties, and extending Model:

<?php

use SoftwarePunt\Instarecord\Model;

class Car extends Model
{
    public int $id;
    public string $make;
    public string $model;
    public int $year;
}

Now you can create, read, update, and delete records with ease:

$car = new Car();
$car->make = "Toyota";
$car->model = "Corolla";
$car->year = 2005;
$car->save(); // INSERT INTO cars [..]

// Post insert, the primary key (id) is automatically populated

$car->year = 2006;
$car->save(); // UPDATE cars SET year = 2006 WHERE id = 123

$car->delete(); // DELETE FROM cars WHERE id = 123

Run queries

You can easily build and run custom queries, and get results in various ways - from raw data to fully populated models.

From models

$matchingCars = Car::query()
    ->where('make = ?', 'Toyota')
    ->andWhere('year > ?', 2000)
    ->orderBy('year DESC')
    ->limit(10)
    ->queryAllModels(); // Car[]

Standalone

$carsPerYear = Instarecord::query()
    ->select('year, COUNT(*) as count')
    ->from('cars')
    ->groupBy('year')
    ->queryKeyValueArray(); // [2005 => 10, 2006 => 5, ..]

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-04-12