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

@mmstudio/an000014

v1.1.0

Published

sql查询

Downloads

16

Readme

sql查询

数据库查询

数据库类型

支持mysql,postgres,mariadb

ts返回类型最大20个,如果超过20个,可直接as

注意事项

需要先确定数据库类型

在进行业务开发时,需要首先确定数据库类型,否则sql有非常大的可能性是无法兼容的。

long类型

postgres数据库中的长整型转换到js中,类型为BigInt,比较小的数值最好设置其类型为smallint即可。

BigIntnumber类型计算时,需要将number转换为BigInt后进行。几种转换方法:

  1. BigInttonumber.一般无须进行这种转换,因为有可能会因长度不够而失败

    function b2n(v: BigInt){
    	return parseInt(v.toString(), 10);
    }
  2. numbertoBigInt

    function n2b(v: number){
    	return BigInt(v);
    }
  3. stringtoBigInt

    function n2b(v: string){
    	return BigInt(v);
    }
  4. BigInttostring

    function n2b(v: BigInt){
    	return v.toString();
    }

配置

mm.json

{
	"dbs": {
		"db001": {
			"type": "postgres",
			"source": "postgres://mmstudio:[email protected]:5432/mmstudio"
		},
		"db002": {
			"type": "mariadb",
			"source": "mysql://mmstudio:[email protected]:3306/mmstudio?connectionLimit=5"
		},
		"db003": {
			"type": "mariadb",
			"source": [
				"mysql://mmstudio:[email protected]:3306/mmstudio?connectionLimit=5",
				"mysql://mmstudio:[email protected]:3307/mmstudio?connectionLimit=5",
				"mysql://mmstudio:[email protected]:3308/mmstudio?connectionLimit=5"
			]
		}
	}
}

说明

  1. 项目下的配置会在部署时被覆盖
  2. 配置文件名固定mm.json,且须放置在项目根目录
  3. dbs下的名称db001,db002,db003视具体情况配置,个数不定,简单项目使用一个数据库亦可。
  4. type目前只支持postgresmariadb两种,mariadb与mysql通用
  5. mariadb支持主从节点配置如db003,配置项的第一个将作为主节点

docker-compose

docker-compose安装

[sudo] docker-compose -f db.yaml up

db.yaml

version: '3.7'

services:
  postgres:
    image: postgres
    container_name: postgres
    volumes:
      - /home/taoqf/data/postgre:/var/lib/postgresql/data
    restart: always
    environment:
      POSTGRES_DB: mmstudio
      POSTGRES_USER: mmstudio
      POSTGRES_PASSWORD: Mmstudio123
    ports:
      - 5432:5432

  mariadb:
    image: mariadb
    container_name: mariadb
    restart: always
    volumes:
      - /home/taoqf/data/mysql:/var/lib/mysql
    environment:
      MYSQL_DATABASE: mmstudio
      MYSQL_USER: mmstudio
      MYSQL_PASSWORD: Mmstudio123
      MYSQL_ROOT_PASSWORD: Mmstudio123
    ports:
      - 3306:3306

  adminer:
    container_name: adminer
    image: adminer
    restart: always
    ports:
      - 8080:8080
# networks:
#   default: