@atscript/db-postgres

中文文档
0.1.174发布于 2026/11/07MITTypeScriptESM + CJS近 30 天下载 3087

PostgreSQL adapter for @atscript/db with pg (node-postgres) driver support.

原始使用文档
文档目录5 节
  1. Installation
  2. Quick Start
  3. Features
  4. Documentation
  5. License

Atscript

@atscript/db-postgres

Define your models once — get TypeScript types, runtime validation, and DB metadata from a single .as model.

Documentation · PostgreSQL Adapter


PostgreSQL adapter for @atscript/db using the pg (node-postgres) driver. Full-featured with pgvector, CITEXT, GIN fulltext, HNSW indexes, transactional DDL, and batched inserts with RETURNING.

Includes PostgresPlugin for @db.pg.* annotations (type overrides, schema selection, native collation).

Installation

pnpm add @atscript/db-postgres pg

Quick Start

import { DbSpace } from "@atscript/db";
import { createAdapter } from "@atscript/db-postgres";

const db = createAdapter("postgresql://user@localhost:5432/mydb");
const users = db.getTable(UsersType);

await users.insertOne({ name: "Alice", email: "[email protected]" });

Features

  • Full CRUD with batched multi-row INSERT + RETURNING (auto-chunking at ~65K params)
  • pgvector: HNSW indexes with cosine, euclidean, and dot product similarity
  • CITEXT for case-insensitive text via @db.collate "nocase"
  • GIN fulltext search via tsvector / tsquery with ranking
  • GENERATED BY DEFAULT AS IDENTITY for auto-increment
  • Native UUID generation via gen_random_uuid()
  • Schema selection via @db.pg.schema
  • Transactional DDL — schema sync is fully atomic
  • Foreign key constraints with referential actions
  • Full schema sync: CREATE, ALTER, DROP, indexes, views

Documentation

License

MIT

版本与发布记录

@atscript/db-postgres 共发布 137 个版本,首次发布于 2026/03/16;过去 12 个月发布了 137 个版本。

版本发布日期距今
0.1.174latest2026/11/07今天
0.1.1732026/11/071 天前
0.1.1722026/11/061 天前
0.1.1712026/11/061 天前
0.1.1702026/11/061 天前
0.1.1692026/11/043 天前

关于 @atscript/db-postgres 的常见问题

@atscript/db-postgres 是什么?

PostgreSQL adapter for @atscript/db with pg (node-postgres) driver support.

如何安装 @atscript/db-postgres?

在项目目录运行 npm install @atscript/db-postgres,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@uniqu/core(^0.2.1)、@atscript/db(^0.1.174)、@atscript/core(^0.2.9)、@atscript/typescript(^0.2.9)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@atscript/db-postgres 支持 TypeScript 吗?

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

@atscript/db-postgres 支持 ESM 还是 CommonJS?

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

@atscript/db-postgres 可以商用吗?

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

@atscript/db-postgres 的下载量有多少?

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

@atscript/db-postgres 还在维护吗?

最新版本 0.1.174 发布于 2026/11/07(今天);至今共发布 137 个版本,其中过去 12 个月发布了 137 个;首次发布于 2026/03/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。