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

@icreate/imedx-js-sdk

v0.0.32-beta.2

Published

npm i @icreate/imedx-js-sdk

Downloads

42

Readme

安装

npm i @icreate/imedx-js-sdk

引用

import { createClient, DbDataType, sql } from '@icreate/imedx-js-sdk'

创建 imedxService

/**
* @description: 创建 imedxService
* @param {String} URL 请求地址
* @param {String} headers 请求头
* @param {String} appId 应用ID
* @param {String} secretKey 密钥
* @param {String} autoEncrypt 自动加密
* @return {*}
*/
const imedxService = createClient('http://192.168.2.24:9090', {
  headers: { data_source: 'default' },
  appId: '',
  secretKey: '',
  autoEncrypt: true
})

请求拦截器

imedxService.interceptors.request.use(
  config => {
    // if (store.getters.token) {
    config.headers['Authorization'] = `Bearer zzzzzzzzzzz`
    // }
    return config
  },
  error => {
    console.log('------request error------', error)
    return Promise.reject(error)
  }
)

响应拦截器

imedxService.interceptors.response.use(
  async res => {
    try {
      res.data = JSON.parse(res.data)
    } catch (error) {
      return Promise.reject(error)
    }
    if (res.code !== 200) {
      return Promise.reject(new Error(res.message || 'Error'))
    } else {
      return res
    }
  },
  error => {
    console.log('------response error------', error)
    return Promise.reject(error)
  }
)

查询

  • from: 表名称。
  • select: 查询列字符串,无入参时默认 * 。
  • where: 条件字符串,默认 AND 拼接。
  • in: 列名 + 数据集。
  • notIn: 列名 + 数据集。
  • and 条件字符串,是会追加 AND 条件。
  • or 拼接 OR 条件
  • order 排序 倒叙直接列名.desc
  • limit pageSize 分页查询条数 currentPage 当前页,从 1 开始
const startDate = '2022-01-01'
const endDate = '2022-02-01'
const StudentIds = ['1111111', '22222222', '333333333']
const StudentName = ['aaaaaa', 'bbbbbbb', 'cccccccc']
let keys = '关键字'
keys = keys.replace(/'/g, `''`)
var LikeKey = [
  `STUDENT_ID LIKE '%${keys}%'`,
  `STUDENT_NAME LIKE '%${keys}%'`,
  `HEIGHT LIKE '%${keys}%'`,
  `WEIGHT LIKE '%${keys}%'`
]

const data = await imedxService
  .from('SIMS_STUDENT')
  .select('STUDENT_ID, STUDENT_NAME, HEIGHT, WEIGHT')
  .where(`CREATED_TIME >= '${startDate}'`, `CREATED_TIME < '${endDate}'`, `STATUS = 1`)
  .in('STUDENT_ID', StudentIds)
  .notIn('STUDENT_NAME', StudentName)
  .and(`GENDER = '男'`, `NATION = '汉'`)
  .or(LikeKey)
  .order('STUDENT_ID', 'HEIGHT.DESC')
  .limit(20, 1)

查询 - 根据主键 ID

  • from: 表名称。
  • select: 查询列字符串,无入参时默认 * 。
  • id: 主键 ID 的值。
const data = await imedxService
  .from('SIMS_STUDENT')
  .select('STUDENT_ID, STUDENT_NAME, HEIGHT, WEIGHT')
  .id('123456')

查询 - 支持参数化设置

  • params 参数对象,支持多入参,合并参数属性。
const params = {
  startDate: '2022-01-01',
  endDate: '2022-02-01',
  status: 1
}
const data = await imedxService
  .from('SIMS_STUDENT')
  .select('STUDENT_ID, STUDENT_NAME, HEIGHT, WEIGHT')
  .where(`CREATED_TIME >= #{startDate}`, `CREATED_TIME < #{endDate}`, `STATUS = #{status}`)
  .order('STUDENT_ID', 'HEIGHT.DESC')
  .limit(20, 1)
  .params(params)

查询 - CLOB 类型列

  • selectClob: 列名称,仅单行单列查询。
const data = await imedxService
  .from('DB_SOURCE')
  .selectClob('AVATAR')
  .where('id="cccc"')

查询 - BLOB 类型列

  • selectBlob 列名称,仅单独列查询。
const data = await imedxService
  .from('DB_SOURCE')
  .selectBlob('AVATAR')
  .where('id="cccc"')

复杂查询

| 操作对象 | 方法 | 入参 | 说明 | | :------: | :--------: | :-------------------------------------- | :----------------------------------------------------------- | | sql | define | 表名+列数组:{ name: '', columns: [] } | 定义表结构 | | 表 | select | 列对象,无参时默认*,支持多入参 | 指定查询列 | | 表 | from | 表对象 | 指定查询表 | | 表 | where | 列条件 | 指定 where 条件 | | 表 | orderBy | 列对象,倒序直接: 列.desc(),支持多入参 | 指定排序规则 | | 表 | pagination | pageSize: 行数, currentPage:当前页 | 指定分页查询;必须有 order by 条件 | | 表 | toQuery | | 返回查询对象 | | 表 | join | 表对象 | join 表 | | 表 | leftJoin | 表对象 | left join 表 | | 表 | rightJoin | 表对象 | right join 表 | | 表 | innerJoin | 表对象 | inner join 表 | | 表 | on | 列条件 | 在 join、leftJoin、rightJoin、innerJoin 后使用,指定关联条件 | | 列 | isNull | | IS NULL | | 列 | isNotNull | | IS NOT NULL | | 列 | equals | 值或列 | 等于: = | | 列 | notEquals | 值或列 | 不等于:<> | | 列 | gt | 值或列 | 大于:> | | 列 | gte | 值或列 | 大于等于:>= | | 列 | lt | 值或列 | 小于:< | | 列 | lte | 值或列 | 小于等于:<= | | 列 | like | 值 | LIKE | | 列 | notLike | 值 | NOT LIKE | | 列 | in | 值集合 | IN | | 列 | notIn | 值集合 | NOT IN | | 列 | between | 开始值 + 结束值 | BETWEEN | | 列 | notBetween | 开始值 + 结束值 | NOT BETWEEN | | 列 | desc | | 倒序 DESC | | 列 | and | 列条件 | 拼接 AND 条件 | | 列 | or | 列条件 | 拼接 OR 条件 |

// 定义学生表
var SimsStudent = sql.define({
  name: 'SIMS_STUDENT',
  columns: ['COLLEGE_ID', 'CLASS_ID', 'STUDENT_ID', 'STUDENT_NAME', 'ENG_NAME', 'ID_CARD_NO', 'CONTENT']
})

// 定义班级表
var SimsClass = sql.define({
  name: 'SIMS_CLASS',
  columns: ['COLLEGE_ID', 'MAJOR_ID', 'CLASS_ID', 'CLASS_NAME', 'STUDENT_NUMBER']
})

// 单行单列查询 CLOB类型
var query = SimsStudent.selectClob(SimsStudent.CONTENT)
  .from(SimsStudent)
  .where(SimsStudent.STUDENT_ID.equals('boom'))
  .toQuery()

// 单表查询
var query1 = SimsStudent
  .select(SimsStudent.STUDENT_ID, SimsStudent.STUDENT_NAME, SimsStudent.ID_CARD_NO)
  .from(SimsStudent)
  .where(
    SimsStudent.STUDENT_NAME
      .equals('boom')
      .and(SimsStudent.ENG_NAME.equals('sssss'))
      .or(SimsStudent.COLLEGE_ID.equals('55555555').and(SimsStudent.CLASS_ID.isNull()))
  )
  .toQuery()

// 关联表查询
var query2 = SimsStudent
  .select()
  .from(
    SimsStudent
      .join(SimsClass)
      .on(SimsStudent.COLLEGE_ID.equals(SimsClass.COLLEGE_ID))
  )
  .where(SimsStudent.STUDENT_NAME.equals('boom').and(SimsClass.CLASS_NAME.equals('aaaaaa')))
  .orderBy(SimsClass.CLASS_ID.desc(), SimsStudent.STUDENT_ID)
  .pagination(20, 1)
  .toQuery()

const data = await imedxService.commit(query, query1, query2)

SQL执行

  • SQLQuery:SQL语句,参数对象
  • SQL语句中参数用 #{} 占位。
var querySQL = `SELECT * FROM SIMS_STUDENT WHERE ID = #{ID} AND NAME = #{NAME)`
var params = {ID: '159159159', NAME: '储某某'}
var query = sql.SQLQuery(querySQL, params)

const data = await imedxService.commit(query)

插入数据

  • from: 表名称。
  • insert: 插入数据集。
  • field: 在 URL 中指定列对应数据类型。
const data = await imedxService
  .from('SIMS_STUDENT')
  .insert([
    { ID: '6', STUDENT_ID: '6', STUDENT_NAME: '6', HEIGHT: '6', version: '1' },
    { ID: '8', STUDENT_ID: '8', STUDENT_NAME: '8', HEIGHT: '8', version: '1' }
  ])
  .field('ID', DbDataType.Varchar2)
  .field('STUDENT_ID', DbDataType.Varchar2)
  .field('STUDENT_NAME', DbDataType.Varchar2)

更新数据

  • from: 表名称。
  • update: 更新数据集。
const data = await imedxService
  .from('SIMS_STUDENT')
  .update(
    [
      { ID: '4', STUDENT_ID: '4', STUDENT_NAME: '4', HEIGHT: '4', version: '2' },
      { ID: '5', STUDENT_ID: '5', STUDENT_NAME: '5', HEIGHT: '5', version: '2' }
    ]
  )

更新数据 - 根据主键 ID

  • from: 表名称。
  • update: 更新数据集 + 主键 ID 值。
const data = await imedxService
  .from('SIMS_STUDENT')
  .update({ STUDENT_ID: '11', STUDENT_NAME: '2' }, 'aaaaaa')

删除数据

  • from: 表名称。
  • delete: 删除数据集。
const data = await imedxService
  .from('SIMS_STUDENT')
  .delete([{ ID: '4' }, { ID: '5' }])

删除数据 - 根据主键 ID

  • from: 表名称。
  • delete: 无需入参
  • id: 主键值
const data = await imedxService
  .from('SIMS_STUDENT')
  .delete()
  .id('5')

存储过程调用(无返回值)

  • proc1: 存储过程过程名 + 存储过程过程入参 JSON 字符串
const data = await imedxService.proc1('procedure_name', '{"p_user_id":"sa"}')

存储过程调用(有返回值)

  • proc2: 存储过程过程名 + 存储过程过程入参 JSON 字符串
const data = await imedxService.proc2('procedure_name', '{"p_user_id":"sa"}')

存储过程调用 - 方式二

  • proc1:无返回值;入参:存储过程名,参数对象
  • proc2:有返回值;入参:存储过程名,参数对象
var procName = `P_TEST`
var params = {ID: '159159159', NAME: '储某某'}
var proc1 = sql.proc1(procName, params)
var proc2 = sql.proc1(procName, params)

const data = await imedxService.commit(proc1, proc2)

函数调用

  • func: 函数名 + 函数入参对象
const data = await imedxService.func('function_name', { param1: 'value1' })

多表操作

  • 多张表的 增 删 改 操作 - 写法一
  • result_id: 请求 ID,用于区分结果集属于哪个表操作。
  • table_name: 表名称。
  • type: 操作类型 insert|update|delete
  • data: 操作数据集
  • fields: 列类型对象
const data = await imedxService
  .commit(
    {
      result_id: '111111',
      table_name: 'ICS_TEST_TABLE',
      type: 'insert',
      data: [
        { ID: '10', name: '10', age: '10', address: '10', version: '1' },
        { ID: '11', name: '11', age: '11', address: '11', version: '1' }
      ],
      fields: { desc: DbDataType.Clob, remark: DbDataType.Varchar2 }
    },
    {
      result_id: '222222',
      table_name: 'ICS_TEST_TABLE',
      type: 'update',
      data: [
        { ID: '12', name: '12', age: '12', address: '12', version: '1' },
        { ID: '13', name: '13', age: '13', address: '13', version: '1' }
      ],
      fields: { desc: DbDataType.Clob, remark: DbDataType.Varchar2 }
    },
    {
      result_id: '333333',
      table_name: 'ICS_TEST_TABLE',
      type: 'delete',
      data: [
        { ID: '12', name: '12', age: '12', address: '12', version: '1' },
        { ID: '13', name: '13', age: '13', address: '13', version: '1' }
      ],
      fields: { desc: DbDataType.Clob, remark: DbDataType.Varchar2 }
    }
  )
  • 多张表的 增 删 改 操作 - 写法二
  • sql.define

| 操作对象 | 方法名 | 入参 | 说明 | | :------: | :-----: | :---------------------------------------------- | :------------------------- | | sql | define | 表名+列数组:{ name: '', columns: [] } | 定义表结构 | | 表 | insert | 数据集,即需要插入的数据集 | 生成多表操作的 insert 对象 | | 表 | update | 数据集,即需要更新的数据集 | 生成多表操作的 update 对象 | | 表 | delete | 数据集,即需要删除的数据集 | 生成多表操作的 delete 对象 | | 表 | fields | 特殊列类型指定:{ columnName: DbDataType.Clob } | 参数说明特殊列类型 | | 表 | toQuery | | 返回指定类型对象 |

// 定义学生表
var SimsStudent = sql.define({
  name: 'SIMS_STUDENT',
  columns: ['COLLEGE_ID', 'CLASS_ID', 'STUDENT_ID', 'STUDENT_NAME', 'ENG_NAME', 'ID_CARD_NO']
})
// 定义班级表
var SimsClass = sql.define({
  name: 'SIMS_CLASS',
  columns: ['COLLEGE_ID', 'MAJOR_ID', 'CLASS_ID', 'CLASS_NAME', 'STUDENT_NUMBER']
})

// 通过表生成 Insert 对象
var Insert = SimsStudent
  .insert({ COLLEGE_ID: '5', CLASS_ID: '5', STUDENT_ID: '5', STUDENT_NAME: '5', ENG_NAME: '1', ID_CARD_NO: '1' })
  .fields({ ID_CARD_NO: DbDataType.Clob })
  .toQuery()

// 通过表生成 Update 对象
var Update = SimsStudent
  .update([{ COLLEGE_ID: '5', CLASS_ID: '6', STUDENT_ID: '6', STUDENT_NAME: '6', ENG_NAME: '6', ID_CARD_NO: '6' }])
  .fields({ ID_CARD_NO: DbDataType.Clob })
  .toQuery()

// 通过表生成 Delete 对象
var Delete = SimsStudent
  .delete([{ COLLEGE_ID: '5', CLASS_ID: '5', STUDENT_ID: '5', STUDENT_NAME: '5', ENG_NAME: '1', ID_CARD_NO: '1' }])
  .fields({ ID_CARD_NO: DbDataType.Clob })
  .toQuery()

const data = await imedxService.commit(Insert, Update, Delete)