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

general_fetch

v1.0.5

Published

通用读写请求库

Downloads

15

Readme

通用读写请求库

封装通用读写方便使用,居于node-fetches6-promise封装同时支持浏览器和node.js环境。 浏览器支持需要支持fetch 和 Promise,对于不支持fetch 和 Promise的浏览器请自己注入fetch 和 Promise到全局。

安装

npm i general_fetch --save

全局配置

默认使用全局配置的里的配置作为参数,构造器里传入的参数优先级比全局配置高

    globalOptions = {
        /**
         * CGI URL
         */
        baseUrl: '',
        /**
         * select时分页查询时的起始页
         */
        page: 0,
        /**
         * select时分页查询时每页的数量
         */
        count: 20
    };
    // 先配置全局`baseUrl`
    const GF = require('../index');
    GF.globalOptions.baseUrl = 'http://ke.qq.com/cgi-bin/crm/general_access';

使用前必须先配置全局baseUrl

Select

查询数据构造器

    /**
     * 查询数据构造器
     * @param sourceId 业务id,对应一张表,找后端要
     */
    constructor(sourceId: number);

分页查询起始页

    /**
     * 分页查询起始页
     * @param pageIndex
     * @return {Select}
     */
    page(pageIndex: number): Select;    

分页查询每页数量

    /**
     * 分页查询每页数量
     * @param count
     * @return {Select}
     */
    count(count: number): Select;

设置选中的字段

    /**
     * 设置选中的字段
     * @param fields
     * @return {Select}
     */
    fields(fields: string[]): Select;

添加字段升序排序条件

    /**
     * 添加字段升序排序条件
     * @param field
     * @return {Select}
     */
    sortAsc(field: any): Select;

添加字段降序排序条件

    /**
     * 添加字段降序排序条件
     * @param field
     * @return {Select}
     */
    sortDesc(field: any): Select;

发生select请求,获得Promise

在发送请求前一定要设置过滤条件。

    /**
     * 发生select请求,获得Promise
     * @return {Promise<SelectResponse>|Promise}
     */
    send(): Promise<SelectResponse>;

Select 请求返回的结果

interface SelectResponse {
    /**
     * 分页查询每页数量
     */
    count: number;
    /**
     * 分页查询起始页
     */
    page: number;
    /**
     * 对应查询条件共有的记录数量
     */
    total: number;
    /**
     * 获取到的数据存放在这里
     */
    rows: {
        [key: string]: any;
    }[];
}

条件过滤

在Select和Update的时候,必须设置条件过滤选中对应的记录。有以下条件过滤接口

等于

    /**
     * 添加过滤条件 等于
     * @param field
     * @param value
     * @return {Select}
     */
    equalTo(field: string, value: any): Filter;

大于

    /**
     * 添加过滤条件 大于
     * @param field
     * @param value
     * @return {Select}
     */
    greaterThan(field: string, value: any): Filter;

大于等于

    /**
     * 添加过滤条件 大于等于
     * @param field
     * @param value
     * @return {Select}
     */
    greaterThanOrEqualTo(field: string, value: any): Filter;

小于

    /**
     * 添加过滤条件 小于
     * @param field
     * @param value
     * @return {Select}
     */
    lessThan(field: string, value: any): Filter;

小于等于

    /**
     * 添加过滤条件 小于等于
     * @param field
     * @param value
     * @return {Select}
     */
    lessThanOrEqualTo(field: string, value: any): Filter;

不等于

    /**
     * 添加过滤条件 不等于
     * @param field
     * @param value
     * @return {Select}
     */
    notEqual(field: string, value: any): Filter;

值在列表里

    /**
     * 添加过滤条件 值在列表里
     * @param field
     * @param list
     * @return {Select}
     */
    inList(field: string, list: any[]): Filter;

值不在列表里

    /**
     * 添加过滤条件 值不在列表里
     * @param field
     * @param list
     * @return {Select}
     */
    notInList(field: string, list: any[]): Filter;

Update

更新请求构造器

    /**
     * 更新请求构造器
     * @param sourceId 业务id,对应一张表,找后端要
     */
    constructor(sourceId: number);

设置要更新的字段名称和对应的值

    /**
     * 设置要更新的字段名称和对应的值
     * @param updateData
     * @return {Update}
     */
    data(updateData: {
        [key: string]: any;
    }): Update;

发送请求

    /**
     * 发生update请求,获得Promise
     * @return {Promise<T>|Promise}
     */
    send(): Promise<UpdateResponse>;

update请求成功插入后不会返回数据,如果插入出错就reject错误

Insert

Insert 插入数据构造器

    /**
     * Insert 插入数据构造器
     * @param sourceId
     */
    constructor(sourceId: number);

设置要更新的字段

    /**
     * 设置要更新的字段
     * @param fields
     * @return {Insert}
     */
    fields(fields: string[]): Insert;

添加一条需要插入的数据

    /**
     * 添加一条需要插入的数据
     * @param row
     */
    row(row: any[]): Insert;

发生请求Insert请求,获得Promise

    /**
     * 发生请求Insert请求,获得Promise
     * @return {Promise<{}>|Promise}
     */
    send(): Promise<{}>;

insert请求成功插入后不会返回数据,如果插入出错就reject错误

Contributing

dev

test

test with mocha,run npm run test to test it

require

安装全局依赖

  • typedoc to make API doc
  • mocha for test

License

MIT

Copyright (c) 2016 HalWu