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

lazy-kit-fastsql

v0.0.2

Published

> SQL quick toolkit based on Nodejs

Downloads

5

Readme

lazy-kit-fastsql

SQL quick toolkit based on Nodejs

Functions

type Row = {[field:string]:any};
type RowSet = Row[];
interface SelectOptions {
  groupBy?: string|string[];
  orderBy?:string|{[field:string]:("ASC"|"DESC")};
  limit?:number|number[];
}
type Table2Union = { table: string; fields: Row; where?:Row|RowSet; };

/**
 * 插入语句
 * @param T 插入表
 * @param set 插入字段 { 字段 : 值 }
 * @param isReplace 主键重复时是否替换, 默认false
 * @returns 
 */
function C(T:string, set:Row, isReplace?:boolean): string;
/**
 * 查询语句
 * @param T 查询表
 * @param fields 查询字段 { 原字段: 别名 }, 默认 * 
 * @param where 查询条件, 可以是JSON对象、也可以是数组
 * - JSON时, { 字段 : 值, ... } 所有字段通过AND连接
 * - 数组时, [{ 字段 : 值, ... },...] JSON对象内字段通过AND连接, 每个JSON对象产生的条件通过OR连接
 * - 特殊用法:
 * - 当字段设置为$CUSTOM时, 自定义条件语句
 * - 值为空、NULL或者undefined的时候, 转换为SQL中的NULL值判断
 * - 同样可以通过设置值为字符串形式的特殊表达式 “#{NULL}”、“#{ISNULL}”来判断值为空; 或者通过 “#{ISNOTNULL}”、“#{NOTNULL}”、“#{!NULL}”来判断非空;
 * - 值如果是一个字符串或者数字, 默认做相等判断
 * - 值是一个JSON对象, 值的KEY是一个操作符号, 支持IN、BETWEEN、LIKE、区间(>=_<、>_<=、>=_<=), 操作符都不是以上的情况下, 直接 “字段名 操作符 值”进行判断
 * @param options { GROUP BY, ORDER BY, LIMIT }
 * @returns 
 */
function R(T:string, fields?:Row|"*", where?:Row|RowSet, options?:SelectOptions): string;
/**
 * 更新语句
 * @param T 更新表
 * @param set 更新字段 { 字段名: 值 }
 * @param where 
 * @returns 
 */
function U(T:string, set:Row, where?:Row|RowSet): string;
/**
 * 删除语句
 * @param T 删除表
 * @param where 条件
 * @returns 
 */
function D(T:string, where?:Row|RowSet): string;

namespace T {
  /**
   * 联表查询 - UNION(ALL)
   * @param tables 要联合的表 [{ 
      table: 表名
      fields: {原字段名:别名, ...},  // 提取字段, 注意字段数量、别名要和其他查询保持一致
      where: [ // 查询条件, 多个条件OR连接时数组, 全部AND连接时JSON
        { ... }, // 条件1: AND连接
        // 此处将条件1 和 条件2 通过 OR 进行连接
        { ... } // 条件2
      ] 
    },...]
  */
  function Union(...tables: Table2Union[]): string;
  /**
   * 联表查询 - UNION(ALL)
   * @param TT 指定临时表名
   * @param tables 要联合的表
   */
  function Union(TT:string, ...tables: Table2Union[]): string;
  /**
   * 联表查询 - UNION(ALL)
   * @param isDuplicate 是否允许重复, 默认true, 即UNION ALL
   * @param tables 要联合的表
   */
  function Union(isDuplicate: boolean, ...tables: Table2Union[]): string;
  /**
   * 
   * @param TT 指定临时表名
   * @param isDuplicate 是否允许重复, 默认true, 即UNION ALL
   * @param tables 
   */
  function Union(TT:string, isDuplicate: boolean, ...tables: Table2Union[]): string;

  /**
   * 联表查询 - (INNER|LEFT|RIGHT|FULL)JOIN
   * @param M 主表
   * @param J 联表
   * @param ON 条件
   * @param fields 提取字段, 一维数组或者二维数组只有一个值, 取主表; 二维数组存在两个值, 第一个数组取主表, 第二个取联表
   * @param OP 操作符, 默认LEFT
   * @returns SQL
   */
  function Join(M:string, J:string, ON:Row, fields:string[]|string[][], OP?:string): string;
}