PHPackages                             php-comp/lite-activerecord - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. php-comp/lite-activerecord

ActiveLibrary

php-comp/lite-activerecord
==========================

a simple activeRecord library of the php

v1.1.0(7y ago)14MITPHPPHP &gt;=7.0.0

Since May 1Pushed 7y ago1 watchersCompare

[ Source](https://github.com/phppkg/lite-activeRecord)[ Packagist](https://packagist.org/packages/php-comp/lite-activerecord)[ Docs](https://github.com/php-comp/lite-activeRecord)[ RSS](/packages/php-comp-lite-activerecord/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (4)Versions (3)Used By (0)

simple activeRecord
===================

[](#simple-activerecord)

[![License](https://camo.githubusercontent.com/b6a4221c4c4819099af6ed5d86b07b6f246b6564c8a53ea6e3a5adba50108a8d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f696e686572652f636f6e736f6c652e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Php Version](https://camo.githubusercontent.com/5127919eba34cfd4efa2e1d76a62f25de4061ec0a31a434fd9b23f6b16fc2c0e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533453d372e302d627269676874677265656e2e7376673f6d61784167653d32353932303030)](https://packagist.org/packages/php-comp/lite-activerecord)[![Latest Stable Version](https://camo.githubusercontent.com/4c74d16bc16ff252e21c8fad663cceacc7e46591d0825f5a715942f173743612/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068702d636f6d702f6c6974652d6163746976657265636f72642e737667)](https://packagist.org/packages/php-comp/lite-activerecord)

一个简洁的php activeRecord库

功能：

- 简洁，使用简单
- 支持 `findByPk` `findOne` `findAll` `insert` `update` 等常用方法
- 内置数据验证检查，保存数据之前自动验证。（像 yii 的模型，验证基于 `inhere/php-validate`）

安装
--

[](#安装)

- By composer require

```
composer require php-comp/lite-activerecord
```

- By composer.json

```
{
    "require": {
        "php-comp/lite-activerecord": "~1.0"
    }
}
```

- Pull directly

```
git clone https://github.com/php-comp/lite-activeRecord.git
```

如何使用
----

[](#如何使用)

- 引入类并继承

```
use PhpComp\LiteActiveRecord\RecordModel

class User extends RecordModel
{
    // ...

    /**
     * 表名称(可选定义)
     * @return string
     */
    public static function tableName(): string
    {
        return 'user';
    }

    /**
     * 表的字段。
     *  - 必须定义，只有这里定义的字段才会被保存
     * @return array
     */
    public function columns(): array
    {
        return [
            // column => [type]

            'id' => ['int'],
            'name' => ['string'],
        ];
    }

    /**
     * define attribute field translate list(可选定义)
     * @return array
     */
    public function translates(): array
    {
        return [
            // 'field' => 'translate',
            // e.g. 'name'=>'名称',
    }

    /**
     * 数据验证规则(可选定义)
     * - 保存数据之前会自动验证
     * @return array
     */
    public function rules(): array
    {
        return [
            // ['body', 'string'],
            // ['id, createTime', 'int'],
        }
    }
}
```

- 插入

```
$user = User::load($data);
$user->insert();

if ($model->hasError()) {
    var_dump($model->firstError())
}

var_dump($user->id);
```

- 查找

```
$user = User::findById(12);
$user = User::findOne(['name' => 'inhere']);

// 查找多个
$users = User::findAll([
    ['id', '>', 23],
    'status' => [1, 2], // status IN (1,2)
    ['name', 'like', "%tom%"],
]);
```

- 更新

```
$user->name = 'new name';
$user->update();
```

- 删除

```
// 模型删除
$affected = $user->delete();

// 通过id删除
$affected = User::deleteByPk(23);
```

Projects
--------

[](#projects)

- **github**
- **gitee**

参考
--

[](#参考)

-
-

License
-------

[](#license)

MIT

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~203 days

Total

2

Last Release

2733d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d23e1decaf354e8f36a7ad61128865dc78dd63336c2d023d79aa3ff8ba2a05ff?d=identicon)[inhere](/maintainers/inhere)

---

Top Contributors

[![inhere](https://avatars.githubusercontent.com/u/5302062?v=4)](https://github.com/inhere "inhere (32 commits)")

---

Tags

activerecordphpphplibrarypdotoolactiverecord

### Embed Badge

![Health badge](/badges/php-comp-lite-activerecord/health.svg)

```
[![Health](https://phpackages.com/badges/php-comp-lite-activerecord/health.svg)](https://phpackages.com/packages/php-comp-lite-activerecord)
```

###  Alternatives

[litesaml/lightsaml

SAML 2.0 PHP library

1055.5M18](/packages/litesaml-lightsaml)[toolkit/cli-utils

useful cli tool library of the php

20222.1k16](/packages/toolkit-cli-utils)[tommyknocker/pdo-database-class

Framework-agnostic PHP database library with unified API for MySQL, MariaDB, PostgreSQL, SQLite, MSSQL, and Oracle. Query Builder, caching, sharding, window functions, CTEs, JSON, migrations, ActiveRecord, CLI tools, AI-powered analysis. Zero external dependencies.

845.7k](/packages/tommyknocker-pdo-database-class)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
