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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@careteam/care-ui-querybuilder

v0.0.21

Published

The React <QueryBuilder /> component for constructing queries

Downloads

25

Readme

querybuilder

:::demo demo/sql.jsx sql :::

:::demo demo/sql-named.jsx sql-named :::

:::demo demo/custom.jsx 自定义 :::

:::demo demo/disabled.jsx 不可选 :::

如何使用

  import Querybuilder from '@tencent/care-ui-querybuilder';
  
  // 假设要样式的话
  import '@tencent/care-ui-querybuilder/lib/index.less';

demo

import React from 'react';
import { registerFormField, connect } from '@formily/react-schema-renderer';
import Querybuilder from '@tencent/care-ui-querybuilder';
import '@tencent/care-ui-querybuilder/dist/index.less';

export default function QueryFomily(props) {
  const { value, onChange, ...options } = props;

  return (
    <div className="querybuilder-formily">
      <Querybuilder value={value} onChange={onChange} {...options} />
    </div>
  );
}

registerFormField(
  'querybuilder',
  connect()(QueryFomily),
);

or

import React, { useState } from 'react';
import QueryBuilder from '../src';
const fields = [
  { name: 'name', type: 'VARCHAR' },
  { name: 'code', type: 'TINYINT' },
  { name: 'isOk', type: 'BOOLEAN' },
];

const defaultValue = {
  id: 'g-Z5hBie93WIlPmk1MWwOsJ',
  rules: [
    {
      id: 'r-4EmPOzphlXOFbN8xe7RHO',
      field: 'name',
      value: 1,
      operator: '=',
    },
    {
      id: 'r-o5qpJfAZgTn9u1U9lW8D8',
      field: 'name',
      value: '33',
      operator: '=',
    },
  ],
  combinator: 'and',
  not: false,
};

export default function SQL() {
  const [value, setValue] = useState(defaultValue);

  function onChange(newValue) {
    console.log('onchange', newValue);
    setValue(newValue);
  }

  return (
    <div>
      <div className="demo-title">json</div>
      <QueryBuilder fields={fields} format="json" onChange={onChange} value={value}/>
    </div>
  );
}

props

fields

[
  {
    name: '字段name',
    label: '展示文案(可选)',
    type: 'VARCHAR(sql type)'
  }
]

format

| 值 | 说明 | 示例 | | ---- | ---- | ----- | | sql | 数据库query | (a = 1 and b = 2) | | sql-named | | 见下面 | | json | | 见下面 |

sql-named 示例:

{
  sql: '(name = :name_1 and name like :name_2)',
  params: {
    name_1: '\'1\'',
    name_2: '\'%2%\''
  }
}

json 示例:

{
  id: 'g-Z5hBie93WIlPmk1MWwOsJ',
  rules: [
    {
      id: 'r-4EmPOzphlXOFbN8xe7RHO',
      field: 'name',
      value: 1,
      operator: '=',
    },
    {
      id: 'r-o5qpJfAZgTn9u1U9lW8D8',
      field: 'name',
      value: '33',
      operator: '=',
    },
  ],
  combinator: 'and',
  not: false,
}

controlElements 自定义ui (Object)

不修改则使用默认展示

| 值 | 说明 | | ---- | ---- | | addGroupAction | 添加组 | | removeGroupAction | 删除组 | | addRuleAction | 添加规则 | | removeRuleAction | 删除规则 | | combinatorSelector | 连接类型 | | fieldSelector | 字段选择 | | operatorSelector | 操作符 | | valueEditor | 值编辑 |

具体可看 src/control 中的实现

如:

<QueryBuilder controlElements={{operatorSelector: xxx}}/>

fieldType 字段类型

未完成,暂时只支持 sql类型

normal

sql

fieldTypeMap 自定义字段类型匹配

未完成