# @acpr/rate-limit-postgresql 中文文档

规范地址：https://npmcn.com/package/%40acpr/rate-limit-postgresql/

版本：1\.4\.1
npm 元数据更新时间：2024-03-18T11:44:23.667Z
中文译文更新时间：2026-11-05T22:15:46.295Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40acpr/rate-limit-postgresql
原文对照：https://npmcn.com/package/%40acpr/rate-limit-postgresql/?lang=original
项目主页：https://github.com/express-rate-limit/rate-limit-postgresql
源码仓库：https://github.com/express-rate-limit/rate-limit-postgresql

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：42.8 kB，14 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：4 个
- peer 依赖：express-rate-limit \>=6\.0\.0
- 首次发布：2023-09-13T09:39:56.814Z
- 最新版本发布：2024-03-18T11:44:22.950Z
- 近 30 天下载量：13422（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：10（近 12 个月 0 个）

## 中文简介

用于此软件的 PostgreSQL 商店 `express-rate-limit` 中间软件

## 安装

```sh
npm install @acpr/rate-limit-postgresql
```

也可以使用：`pnpm add @acpr/rate-limit-postgresql`、`yarn add @acpr/rate-limit-postgresql`、`bun add @acpr/rate-limit-postgresql`

## README

# 费率限制-贴出

[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](https://npmcn.com/package/%40acpr/rate-limit-postgresql/code_of_conduct.md)

A 类 [`PostgreSQL`](https://www.postgresql.org/) 存储 [`express-rate-limit`](https://github.com/nfriedly/express-rate-limit) 中间软件.

## 安装

从 npm 注册 :

```sh
# Using npm
> npm install --save @acpr/rate-limit-postgresql
# Using yarn or pnpm
> yarn/pnpm add @acpr/rate-limit-postgresql
```

## 使用量

使用功能示例 `rate-limit-postgresql` 可见于 [跟踪寄存器](https://github.com/adrianprelipcean/express-rate-limit-postgresql-examples)

```js
let rateLimit = require('express-rate-limit')
let postgresStores = require('@acpr/rate-limit-postgresql')

let limiter = new RateLimit({
    store: new postgresStores.PostgresStore(
        {
            user: 'postgres',
            password: 'postgres',
            host: 'localhost',
            database: 'rate-limit',
            port: 5432,
        },
        'aggregated_store',
    ),
    windowMs: 15 * 60 * 1000, // 15 minutes
    max: 3, // Limit each IP to 3 requests per `window` (here, per 15 minutes)
    message:
        'Too many accounts created from this IP, please try again after 15 minutes',
    standardHeaders: 'draft-7', // Set `RateLimit` and `RateLimit-Policy`` headers
    legacyHeaders: false,
})

//  apply to all requests
app.use(limiter)
```

### 导入

该图书馆以无害环境管理和CJS表格提供,并与二者合作 Javascript和Typescript项目.

**这个软件包需要您使用节点16或以上.**

在 CommonJS 项目中导入它 (`type: commonjs` 或者没有 `type` 输入 `package.json`)如下:

```ts
let postgresStores = require('@acpr/rate-limit-postgresql')
```

在无害环境管理项目中导入(`type: module` 内 `package.json`)如下:

```ts
import postgresStores from '@acpr/rate-limit-postgresql'
```

## 配置

### 邮政仓库类型

Postgres商店有两种不同的类型:

1.  `PostgresStoreAggregatedIP` (默认) `PostgresStore` 建筑师)- 如下表所示,该列表汇总了表中的IP数

| 键 | 会话( d) | 计数 |
| --- | --- | --- |
| 192.168.1.1 (中文(简体) ) | 1个 | 3个 |
| 192.168.2.1 (中文(简体) ) | 1个 | 1个 |

2.  `PostgresStoreIndividualIP` - 将每个请求的IP存储在 单独行(如下表所示)并进行汇总 在单独的一步

| 编号 | 键 | 会话( d) | 事件( t) |
| --- | --- | --- | --- |
| 1个 | 192.168.1.1 (中文(简体) ) | 1个 | 2023-09-13 T07:40:09+00:00 (中文(简体) ) |
| 2个 | 192.168.1.1 (中文(简体) ) | 1个 | 2023-09-13 T07:40:10+00:00 (中文(简体) ) |
| 3个 | 192.168.1.1 (中文(简体) ) | 1个 | 2023-09-13 T07:40:11+00:00 (中文(简体) ) |
| 页:1 | 192.168.2.1 (中文(简体) ) | 1个 | 2023-09-13 T07:40:11+00:00 (中文(简体) ) |

> 说明: 数据库使用UUID作为ID的数据类型,表格中包含 整数作为ID来保持插图简单.

### 构造器

这两类商店在构造器中都采用了相同的输入

-   `config` - 数据库配置在 [节点后置](https://node-postgres.com/apis/client) 配置 .
-   `prefix` - 会话的独有名称(在数据库中长期存在)。 用于 双数检查,以避免在键被计算两次时出现假阳性, 但前缀不同.

## 安装

项目许可证在 [许可证文件](https://npmcn.com/package/%40acpr/rate-limit-postgresql/license.md)第三方 许可证存放于 [第三方 许可证文件夹](https://npmcn.com/package/%40acpr/rate-limit-postgresql/third_party_licenses)

## 常见问题

### @acpr/rate-limit-postgresql 是什么？

用于此软件的 PostgreSQL 商店 express-rate-limit 中间软件

### 如何安装 @acpr/rate-limit-postgresql？

在项目目录运行 npm install @acpr/rate-limit-postgresql，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：express-rate-limit（\>=6\.0\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @acpr/rate-limit-postgresql 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @acpr/rate-limit-postgresql 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @acpr/rate-limit-postgresql 可以商用吗？

@acpr/rate-limit-postgresql 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @acpr/rate-limit-postgresql 的下载量有多少？

根据 npm 官方下载统计，@acpr/rate-limit-postgresql 在 2026/10/05 – 2026/11/03 这 30 天内被下载 13,422 次，日均约 447 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @acpr/rate-limit-postgresql 还在维护吗？

最新版本 1\.4\.1 发布于 2024/03/18（2 年前）；至今共发布 10 个版本，其中过去 12 个月发布了 0 个；首次发布于 2023/09/13。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

