PHPackages                             bingcool/swoolefy-orm - 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. [Database &amp; ORM](/categories/database)
4. /
5. bingcool/swoolefy-orm

ActiveLibrary[Database &amp; ORM](/categories/database)

bingcool/swoolefy-orm
=====================

db orm for swoolefy base on topthink/think-orm

1.2.17(7y ago)14822Apache-2.0PHPPHP &gt;=5.6.0

Since Oct 27Pushed 6y ago1 watchersCompare

[ Source](https://github.com/bingcool/swoolefy-orm)[ Packagist](https://packagist.org/packages/bingcool/swoolefy-orm)[ RSS](/packages/bingcool-swoolefy-orm/feed)WikiDiscussions master Synced yesterday

READMEChangelog (7)DependenciesVersions (30)Used By (0)

think-orm
=========

[](#think-orm)

基于PHP5.6+ 的ORM实现，主要特性：

- 基于ThinkPHP5.1的ORM独立封装
- 支持Mysql、Pgsql、Sqlite、SqlServer、Oracle和Mongodb
- 支持Db类和查询构造器
- 支持事务
- 支持模型和关联

适用于不使用ThinkPHP框架的开发者。

安装

```
composer require topthink/think-orm

```

Db类用法：

```
use think\Db;
// 数据库配置信息设置（全局有效）
Db::setConfig(['数据库配置参数（数组）']);
// 进行CURD操作
Db::table('user')
	->data(['name'=>'thinkphp','email'=>'thinkphp@qq.com'])
	->insert();
Db::table('user')->find();
Db::table('user')
	->where('id','>',10)
	->order('id','desc')
	->limit(10)
	->select();
Db::table('user')
	->where('id',10)
	->update(['name'=>'test']);
Db::table('user')
	->where('id',10)
	->delete();
```

Db类增加的（静态）方法包括：

- `setConfig` 设置全局配置信息
- `getConfig` 获取数据库配置信息
- `setQuery` 设置数据库Query类名称
- `setCacheHandler` 设置缓存对象Handler（必须支持get、set及rm方法）
- `getSqlLog` 用于获取当前请求的SQL日志信息（包含连接信息）

其它操作参考TP5.1的完全开发手册[数据库](https://www.kancloud.cn/manual/thinkphp5_1/353998)章节

定义模型：

```
namespace app\index\model;
use think\Model;
class User extends Model
{
}
```

代码调用：

```
use app\index\model\User;

$user = User::get(1);
$user->name = 'thinkphp';
$user->save();
```

Db类和模型对比使用
----------

[](#db类和模型对比使用)

#### ✅ 创建Create

[](#white_check_mark---创建create)

- Db用法

    ```
    Db::table('user')
        ->insert([
            'name'  => 'thinkphp',
            'email' => 'thinkphp@qq.com',
        ]);
    ```
- 模型用法

    ```
    $user        = new User;
    $user->name  = 'thinkphp';
    $user->email = 'thinkphp@qq.com';
    $user->save();
    ```
- 或者批量设置

    ```
    $user = new User;
    $user->save([
        'name'  => 'thinkphp',
        'email' => 'thinkphp@qq.com',
    ]);
    ```

#### ✅ 读取Read

[](#white_check_mark--读取read)

- Db用法

    ```
    $user = Db::table('user')
        ->where('id', 1)
        ->find();
    //  或者
    $user = Db::table('user')
        ->find(1);
    echo $user['id'];
    echo $user['name'];
    ```
- 模型用法

    ```
    $user = User::get(1);
    echo $user->id;
    echo $user->name;
    ```
- 模型实现读取多个记录

    ```
    // 查询用户数据集
    $users = User::where('id', '>', 1)
        ->limit(5)
        ->select();

    // 遍历读取用户数据
    foreach ($users as $user) {
        echo $user->id;
        echo $user->name;
    }
    ```

#### ✅ 更新Update

[](#white_check_mark--更新update)

- Db用法

    ```
    Db::table('user')
        ->where('id', 1)
        ->update([
            'name'  => 'topthink',
            'email' => 'topthink@qq.com',
        ]);
    ```
- 模型用法

    ```
    $user        = User::get(1);
    $user->name  = 'topthink';
    $user->email = 'topthink@qq.com';
    $user->save();
    ```
- 或者使用

    ```
    $user = User::get(1);
    $user->save([
        'name'  => 'topthink',
        'email' => 'topthink@qq.com',
    ]);
    ```
- 静态调用

    ```
    User::update([
        'name'  => 'topthink',
        'email' => 'topthink@qq.com',
    ], ['id' => 1]);
    ```

#### ✅ 删除Delete

[](#white_check_mark--删除delete)

- Db用法

    ```
    Db::table('user')->delete(1);
    ```
- 模型用法

    ```
    $user = User::get(1);
    $user->delete();
    ```
- 或者静态实现

    ```
    User::destroy(1);
    ```
- 静态调用

    ```
    User::update([
        'name'  => 'topthink',
        'email' => 'topthink@qq.com',
    ], ['id' => 1]);
    ```
- destroy方法支持删除指定主键或者查询条件的数据

    ```
    // 根据主键删除多个数据
    User::destroy([1, 2, 3]);
    // 指定条件删除数据
    User::destroy([
        'status' => 0,
    ]);
    // 使用闭包条件
    User::destroy(function ($query) {
        $query->where('id', '>', 0)
            ->where('status', 0);
    });
    ```

更多模型用法可以参考5.1完全开发手册的[模型](https://www.kancloud.cn/manual/thinkphp5_1/354041)章节

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 83% 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 ~16 days

Total

29

Last Release

2672d ago

Major Versions

v0.9 → v1.02018-01-05

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/12829386?v=4)[黄增冰](/maintainers/bingcool)[@bingcool](https://github.com/bingcool)

---

Top Contributors

[![liu21st](https://avatars.githubusercontent.com/u/1111670?v=4)](https://github.com/liu21st "liu21st (122 commits)")[![bingcool](https://avatars.githubusercontent.com/u/12829386?v=4)](https://github.com/bingcool "bingcool (14 commits)")[![big-dream](https://avatars.githubusercontent.com/u/9215157?v=4)](https://github.com/big-dream "big-dream (2 commits)")[![evalor](https://avatars.githubusercontent.com/u/26944445?v=4)](https://github.com/evalor "evalor (2 commits)")[![Tinywan](https://avatars.githubusercontent.com/u/14959876?v=4)](https://github.com/Tinywan "Tinywan (2 commits)")[![iakihsoug](https://avatars.githubusercontent.com/u/5564630?v=4)](https://github.com/iakihsoug "iakihsoug (1 commits)")[![pppscn](https://avatars.githubusercontent.com/u/5105854?v=4)](https://github.com/pppscn "pppscn (1 commits)")[![shaukei](https://avatars.githubusercontent.com/u/1581783?v=4)](https://github.com/shaukei "shaukei (1 commits)")[![willove](https://avatars.githubusercontent.com/u/5616317?v=4)](https://github.com/willove "willove (1 commits)")[![Junjunya1995](https://avatars.githubusercontent.com/u/24283128?v=4)](https://github.com/Junjunya1995 "Junjunya1995 (1 commits)")

### Embed Badge

![Health badge](/badges/bingcool-swoolefy-orm/health.svg)

```
[![Health](https://phpackages.com/badges/bingcool-swoolefy-orm/health.svg)](https://phpackages.com/packages/bingcool-swoolefy-orm)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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