PHPackages                             veasin/nx-sql - 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. veasin/nx-sql

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

veasin/nx-sql
=============

sql builder for nx

0.0.3(4mo ago)011↓90%2PHPPHP &gt;=8.4

Since Mar 23Pushed 1mo agoCompare

[ Source](https://github.com/veasin/nx-sql)[ Packagist](https://packagist.org/packages/veasin/nx-sql)[ Docs](https://github.com/veasin/nx)[ RSS](/packages/veasin-nx-sql/feed)WikiDiscussions main Synced 2mo ago

READMEChangelogDependencies (2)Versions (4)Used By (2)

ff-sql
======

[](#ff-sql)

SQL query builder, DDL generator, and database migration tool for ff framework (PHP 8.4+).

```
composer require veasin/ff-sql

```

Query Builder
-------------

[](#query-builder)

Chainable SQL query builder with automatic parameter binding.

```
use ff\helpers\sql;

// SELECT
echo sql::table('user')->select();                   // SELECT * FROM `user`
echo sql::table('user')->select(['id', 'name']);     // SELECT `id`, `name` FROM `user`

// WHERE
sql::table('user')->where(['id' => 1, 'status' => 1])->select();
// SELECT * FROM `user` WHERE `id` = ? AND `status` = ?

// JOIN
$info = sql::table('info i');
sql::table('user')
    ->join($info, ['id' => 'id'])
    ->where($info['status']->equal(1))
    ->select();
// SELECT `user`.* FROM `user` LEFT JOIN `info` `i` ON (`i`.`id` = `user`.`id`) WHERE `i`.`status` = ?

// INSERT / UPDATE / DELETE
sql::table('user')->insert(['name' => 'vea', 'age' => 30]);
sql::table('user')->where(['id' => 1])->update(['name' => 'new name']);
sql::table('user')->where(['id' => 1])->delete();

// Expressions
sql::table('user')->select([sql::COUNT('*')->as('total')]);
// SELECT COUNT(*) `total` FROM `user`

// OR / AND grouping
$t = sql::table('article');
$t->where($t['status']->eq(1), $t['id']->eq(4)->or($t['id']->eq(5)))->select();
// SELECT * FROM `article` WHERE `status` = ? AND (`id` = ? OR `id` = ?)
```

Parameters are collected in `$sql->params`:

```
$sql = sql::table('user')->where(['id' => 1])->select();
$sql->params; // [1]
```

DDL Generator
-------------

[](#ddl-generator)

Generate MySQL DDL statements programmatically.

```
use ff\helpers\ddl\table;

// CREATE TABLE
echo new table('user')->create([
    'id'   => ['type' => 'INT', 'auto' => true],
    'name' => ['type' => 'VARCHAR(100)', 'null' => false, 'comment' => '姓名'],
    'email'=> ['type' => 'VARCHAR(200)', 'unique' => true],
]);
/*
CREATE TABLE `user` (
  `id` INT AUTO_INCREMENT,
  `name` VARCHAR(100) NOT NULL COMMENT '姓名',
  `email` VARCHAR(200),
  UNIQUE INDEX `uk_email` (`email`),
  PRIMARY KEY (`id`)
);
*/

// ALTER TABLE — add / modify / drop columns
echo new table('user')->fields(
    add: ['age' => ['type' => 'INT']],
    modify: ['name' => ['type' => 'VARCHAR(200)']],
    drop: ['phone'],
);
// ALTER TABLE `user` ADD COLUMN `age` INT, MODIFY COLUMN `name` VARCHAR(200), DROP COLUMN `phone`;

// Index management
echo new table('user')->index(
    add: ['idx_name' => ['columns' => ['name'], 'type' => 'INDEX']],
    modify: ['PRIMARY' => ['columns' => ['id', 'uuid'], 'type' => 'PRIMARY']],
    drop: ['uk_email'],
);

// Schema round-trip
$schema = new table('user')->create([...])->toSchema();           // table → array
$tables = table::fromSql("CREATE TABLE `user` (...)");           // SQL → table[]
```

Migration Tool
--------------

[](#migration-tool)

Track and apply database schema changes over time.

```
# 初始化
php tools/migrate.php init

# 修改数据库后保存版本
php tools/migrate.php save -m "add users table"

# 查看状态
php tools/migrate.php check
php tools/migrate.php list
php tools/migrate.php diff

# 部署到另一台机器
php tools/migrate.php apply

# 回滚未提交变更
php tools/migrate.php clean

# 从头重建
php tools/migrate.php reset
```

See [tools/migrate.md](tools/migrate.md) for full documentation.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance86

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

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 ~4 days

Total

3

Last Release

128d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/127591812?v=4)[vea](/maintainers/vea)[@Vea](https://github.com/Vea)

### Embed Badge

![Health badge](/badges/veasin-nx-sql/health.svg)

```
[![Health](https://phpackages.com/badges/veasin-nx-sql/health.svg)](https://phpackages.com/packages/veasin-nx-sql)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.8k117.8M121](/packages/jdorn-sql-formatter)[backup-manager/backup-manager

A framework agnostic database backup manager with user-definable procedures and support for S3, Dropbox, FTP, SFTP, and more with drivers for popular frameworks.

1.7k1.6M11](/packages/backup-manager-backup-manager)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[insolita/yii2-migration-generator

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

108508.0k5](/packages/insolita-yii2-migration-generator)[xpdo/xpdo

A PDO-based Object/Relational Bridge Library

7088.4k4](/packages/xpdo-xpdo)

PHPackages © 2026

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