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

apijson-builder-client

v0.2.9

Published

A javascript package for apijson javascript operations

Downloads

2

Readme

apijson-builder-client

apijson 不必过多解释,可查看连接。 apijson的请求构建是唯一的学习成本(不考虑撸源码的话),因此为了方便js构建rest请求, 所以有了apijson-builder-client, 是个小东西,代码量也很小。方便你快速构建apijson的rest请求。

安装

import ApiJsonBuilder from 'apijson-builder-client'
Vue.use(ApiJsonBuilder, {
    baseURL: '/api/apijson',
    tokenKey: 'X-Token',
    token: '304958029525nsd23423'
})

使用

import {QueryBuilder} from 'apijson-builder-client';
QueryBuilder.by('User')
        .condition(Condition.by('name', 'like', 'zhang'))
        .order('name')
        .multi(true)
        .setResFields('name,age,phone')
        .page(0, 10)
        .send()
.then(resp => {
    const {total, User: users} = resp // users 即为数据, total为总数
})

新增or查询功能,支持多个字段组合or查询,如:(A and B) or (C and D) 或者 (A or B) and (C or D)

import {QueryBuilder} from 'apijson-builder-client';
QueryBuilder.by('User_info13')
        .condition(Condition.by('age','and',">0,<100"))
        .condition(Condition.by('user_name', 'like', 'test1'))
        .condition(Condition.by('gender', 'eq', 0))
        .condition(Condition.by('crd','and',">1,<20001"))
        //.condition(Condition.by('date', 'like', '2017-02-01'))
        //.condition(Condition.by('id', 'in', [82006,82002]))    //逻辑运算-筛选
        //.condition(Condition.by('id', 'and', ">=82000,<=82005"))   //逻辑运算-范围筛选
        //.condition(Condition.by('id', 'notin', [82006,82002]))    //逻辑运算--not  in
        //.order('name')
        .multi(true)
        .setExplain(true)
        .setOrFields('age&&gender,user_name&&crd')   //or  查询    (A and B) or (C and D)
        //.setOrFields('age,gender')                //or  查询  (A or B) and (C or D)
        //.setOrFields('user_name,crd')
        .setDatasource('apijsonUser1')
        .setResFields('age,crd,user_name')
        .page(0, 10)
        .send()
.then(resp => {
        for(var key in resp) {
          console.log(key, resp[key])    //打印请求结果
        }
      })
})

新增表关联查询功能,支持 INNER JOIN 、LEFT JOIN 和 RIGHT JOIN

import {QueryBuilder} from 'apijson-builder-client';
QueryBuilder.by('Moment')
        .setJoinType('>/User/id@,</Comment/momentId@')  //设置  RIGHT JOIN User表  、  LEFT JOIN  Comment表
        .setResFields('id,userId,content')   
        .setAssociativeCondition('User', 'id', '/Moment/userId',"id,date,name")    
        .setAssociativeCondition('Comment', 'momentId', '/Moment/id',"id,momentId")
        .page(0, 10)
        .setExplain(true)
        .multi(true)
        .send()
.then(resp => {
        for(var key in resp) {
          console.log(key, resp[key])  //打印请求结果
        }
      })

新增分组查询功能,支持 max、avg、sum等

import {QueryBuilder} from 'apijson-builder-client';
QueryBuilder.by('Moment')
        //.setResFields('max(userId):maxUserId')   //取最大值
        //.setResFields('avg(userId)')     //取平均值
        .setResFields('userId;sum(id):idSum')
        .setExplain(true)
        .setGroups('userId')     //userId分组
        .send()
.then(resp => {
        for(var key in resp) {
          console.log(key, resp[key])  //打印请求结果
        }
      })

增改删除功能演示

import {CUDBuilder} from 'apijson-builder-client';
 ##新增
CUDBuilder.by('User','post')
	.set('user_name',"test1")
	.set('gender',1)
	.setExplain(true)
	.setDatasource('apijsonUser1')
	.send()
.then(resp => {
	for(var key in resp) {
	  console.log(key, resp[key])
	}

})

##修改
CUDBuilder.by('Moment','put')
	.whereId('eq',1655267505965)
	.set('content',"今天一直下雨")
	.setTag('Moment')
	.send()
.then(resp => {
	for(var key in resp) {
	  console.log(key, resp[key])
	}
  })
  
##删除
CUDBuilder.by('Moment','delete')
        .whereId('eq',1655267505965)
        .setTag('Moment')
        .send()
.then(resp => {
        for(var key in resp) {
          console.log(key, resp[key])
        }
      })
      

关于token

你可以这样设置token

import {setToken, LoginBuilder} from "apijson-builder-client";

LoginBuilder.login('username', 'password').then(resp => {
    const {token} = resp
    setToken(token)
})

其他

更多使用方式自己看下就知道了, 欢迎来完善。 来改源码前请务必熟知apijson的语法!