npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@sinoform/helper-condition-api

v1.18.11

Published

构建 API 查询条件的辅助模块。

Readme

@sinoform/helper-condition-api

构建 API 查询条件的辅助模块。

支持两种风格构建 API 查询条件,即:

  • 流式方法
  • sql 模板

根据个人喜好,两种风格二选一即可。

简单示例

查询姓名包含 的查询条件。

流式方法:

import { build$ } from '@sinoform/helper-condition-api';

const currentUser = getCurrentUser();
const context = { formDesignId: '表单id', currentUser };
const $ = build$(context);

// 创建查询条件
const condition = $('userName').contain('张');
// 或者
condition = $('userName').like('%张%');

sql 模板风格:

import { sql } from '@sinoform/helper-condition-api';
const condition = sql`userName like '%张%'`;

组合多个查询条件

可以使用 andornot 逻辑运算符组合多个查询条件。

示例 1

import { build$ } from '@sinoform/helper-condition-api';

const currentUser = getCurrentUser();
const context = { formDesignId: '表单id', currentUser };
const $ = build$(context);

const useNameCondition = $('userName').contain('张');
const ageCondition = $('age').gt(18);
const condition = $.and(userNameCondition, ageCondition);
import { sql } from '@sinoform/helper-condition-api';

const condition = sql`
  USER_NAME like '%张%'
  AND age > 18
`;

示例 2

import { $ } from '@sinoform/helper-condition-api';

const condition = $.or(
  $('userName').contain('张'),
  $('userName').contain('李'),
);
import { sql } from '@sinoform/helper-condition-api';

const condition = sql`
  USER_NAME like '%张%'
  OR USER_NAME like '%李%'
`;

示例 3

import { $ } from '@sinoform/helper-condition-api';

const condition = $.and(
  $.or($('userName').contain('张'), $('userName').contain('李')),
  $('age').gt(18),
);
import { sql } from '@sinoform/helper-condition-api';

const condition = sql`
  (
    USER_NAME like '%张%'
    OR USER_NAME like '%李%'
  ) AND (
    age > 18
  )
`;

支持的操作符

| 操作符 | 说明 | | ----------------------------- | --------------------------------------------------------------------- | | equal | 相等比较操作符 | | notEqual | 不相等比较操作符 | | contain | 文本包含操作符,相当于 like '%文本%' | | notContain | 文本不包含操作符 | | isNull | 空判定操作符 | | notNull | 非空判定操作符 | | lt | 小于操作符 | | gt | 大于操作符 | | lte | 小于等于操作符 | | gte | 大于等于操作符 | | in | 包含操作符 | | is | is null场景中使用的操作符 | | isNot | is not null 场景使用的操作符 | | like | 文本包含操作符 | | notLike | 文本不包含操作符 | | range | 区间操作符,相当于 between x and y | | and | 并且逻辑操作符,使用 and 组合的多个查询条件是必须都要满足的 | | or | 或者逻辑操作符,使用 or 组合的多个查询条件只需要满足一个即可 | | not | 非逻辑操作符,使用 not 包裹的查询条件表示查询不满足此查询条件的数据 | | querySelfAll | 仅查询出自己可见的所有数据 | | queryDeptAll | 查询出自己和部门可见的所有数据 |

equal

相等性比较

$('field_1').equal('10');
sql`field_1 = '10'`;

notEqual

不相等比较

$('field_1').notEqual('10');
sql`field_1 <> '10'`;

contain

文本包含关系

$('field_1').contain('张');
sql`field_1 like '%张%'`;

notContain

字符串不包含的关系

$('field_1').notContain('张');
sql`field_1 not like '%张%'`;

isNull

判断是否为空

$('field_1').isNull();
sql`field_1 is null`;

notNull

判断是否非空

$('field_1').notNull();
field_1 is not null

isEmpty

判断是否为空

$('field_1').isEmpty();
sql`field_1 is null or field_1 = ''`;

notEmpty/isNotEmpty

判断是否非空

$('field_1').isNotEmpty();
sql`field_1 is not null and field_1 <> ''`;

lt

小于

$('field_1').lt(10);
sql`field_1 < 10`;

gt

大于

$('field_1').gt(10);
sql`field_1 > 10`;

lte

小于等于

$('field_1').lte(10);
sql`field_1 <= 10`;

gte

大于等于

$('field_1').gte(10);
sql`field_1 >= 10`;

in

数组包含关系

$('field_1').in('类型1', '类型2', '类型3');
sql`field_1 in ('类型1', '类型2', '类型3')`;

is

$('field_1').is(null);
sql`field_1 is null`;

isNot

$('field_1').isNot(null);
sql`field_1 is not null`;

like

文本包含关系。

$('field_1').like('张%');
sql`field_1 like '张%'`;

notLike

文本不包含关系

$('field_1').notLike('张%');
sql`
  field_1 not like '张%'
`;

range

between ... and ...

$('field_1').range(1, 3);
sql`
  field_1 between 1 and 3
`;

and

逻辑与的关系

$.and($('field_1').gt(10), $('field_1').lt(100), $('user_name').equal('张三'));
sql`
  field_1 > 10 and field_1 < 100 and user_name = '张三'
`;

or

逻辑或的关系

$.or($('field_1').gt(10), $('field_1').lt(100), $('user_name').equal('张三'));
sql`
  field_1 > 10 or field_1 < 100 or user_name = '张三'
`;

not

逻辑非的关系

$.not($('field_1').equal(10));
// 或者

$('field_1').not.equal(10);
sql`
  !(field_1 = 10)
`;

likeLeft

文本左包含关系

$('field_1').likeLeft('张');
sql`field_1 like '张%'`;

querySelfAll

查询仅自己可见的数据

import { build$ } from '@sinoform/helper-condition-api';

const currentUser = getCurrentUser();
const context = { formDesignId: '表单id', currentUser };
const $ = build$(context);

const condition = $.querySelfAll();

相当于:

import { $ } from '@sinoform/helper-condition-api';

const condition = $.and(
  $('PERM.FORMDESIGN_ID').equal(formDesignId),
  $('PERM.SUBJECT_ID').equal(currentUserId),
);

queryDeptAll

查询出自己和部门可见的数据

import { build$ } from '@sinoform/helper-condition-api';

const currentUser = getCurrentUser();
const context = { formDesignId: '表单id', currentUser };
const $ = build$(context);

const condition = $.queryDeptAll();

相当于:

import { $ } from '@sinoform/helper-condition-api';

$.or(
  $.and(
    $('PERM.FORMDESIGN_ID').equal(formDesignId),
    $('PERM.SUBJECT_ID').equal(currentUserId),
  ),
  $.and(
    $('PERM.FORMDESIGN_ID').equal(formDesignId),
    $('PERM.SUBJECT_ID').equal(deptId),
    $('PERM.SUBJECT_TYPE').equal('superDept'),
  ),
);