Scan your whole stack
From OX Research Newsroom
Are you using @lark-apaas/nestjs-datapaas?
Find out what’s in your code.
Scan your apps free in minutes (opens in a new tab)Latest version: v1.0.33-alpha.20261201023003
@lark-apaas/nestjs-datapaas was last scanned on 1 Dec 2026 at version 1.0.33-alpha.20261201023003. Risk score 0 of 100. No malicious behavior was detected.
| Version | Published | Status |
|---|---|---|
| 1.0.33-alpha.20261201023003 LATEST | 1 Dec 2026 | No rules fired |
| 1.0.32 | 30 Nov 2026 | No rules fired |
| 1.0.32-alpha.20261130125410 | 30 Nov 2026 | No rules fired |
| 1.0.32-beta.0 | 30 Nov 2026 | Not shown |
| 1.0.32-alpha.20261130122756 | 30 Nov 2026 | Not shown |
Findings for v1.0.33-alpha.20261201023003. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.
The score describes 1.0.33-alpha.20261201023003; other versions have their own rules, not their own score.
The publisher’s own README, as collected from the registry.
基于 Drizzle ORM 封装的 PostgreSQL 数据库连接模块,提供连接池、请求上下文注入与事务等能力。
npm install @lark-apaas/nestjs-datapaas
Base 数据源的带参数查询默认开启 postgres.js prepare,同一物理连接上的同一 SQL 可以复用 statement。事务、savepoint 和 reserve 客户端继承该设置;每次查询的身份设置仍照常执行。无参数查询(包括聚合的 SET LOCAL)保持原有协议,PG 数据源保持原有行为。
在 DataPaasModule.forRoot 或 forRootAsync 的配置中设置 basePrepare: false 可关闭这项默认行为。直接调用客户端 unsafe 时,显式传入的 { prepare: false } 也会保留。
适用于配置可以直接从环境变量或常量获取的场景:
import { Module } from '@nestjs/common';
import { DataPaasModule } from '@lark-apaas/nestjs-datapaas';
@Module({
imports: [
DataPaasModule.forRoot({
// PostgreSQL 连接串,如:postgres://user:pass@host:port/dbname
connectionString: process.env.DATABASE_URL!,
schema: yourSchema, // 可选,Drizzle schema
logger: true, // 可选,启用日志
timeout: 10000, // 可选,请求超时(ms)
idleTimeout: 20, // 可选,空闲连接超时(s)
connectionTimeout: 10, // 可选,连接超时(s)
ssl: false, // 可选,是否启用 SSL
autoContext: true, // 可选,为 SQL 执行自动设置 user_id 环境变量
}),
],
})
export class AppModule {}
推荐使用,适用于需要从 ConfigModule 等异步配置源获取配置的场景:
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { DataPaasModule } from '@lark-apaas/nestjs-datapaas';
import * as schema from './database/schema';
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
}),
DataPaasModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
connectionString: configService.get<string>('DATABASE_URL')!,
schema,
logger: configService.get<boolean>('DATABASE_LOGGER') || false,
timeout: configService.get<number>('DATABASE_TIMEOUT') || 10000,
maxConnections: configService.get<number>('DATABASE_MAX_CONNECTIONS') || 7,
ssl: configService.get<boolean>('DATABASE_SSL') || false,
autoContext: true,
}),
inject: [ConfigService],
}),
],
})
export class AppModule {}
提示:
- 使用
forRootAsync时,配置会在应用启动时从ConfigService异步获取- 支持
useFactory、useClass和useExisting三种配置方式- 详细的异步配置使用方法请参考 ASYNC_USAGE.md
注意: 新版本使用标准的 NestJS 依赖注入模式,所有服务都会自动初始化和管理。
import { Injectable, Inject } from '@nestjs/common';
import {
DataPaasDatabaseService,
DrizzleDatabaseManager,
Database,
DatabaseManager,
DatabaseService,
DRIZZLE_DATABASE,
type PostgresJsDatabase
} from '@lark-apaas/nestjs-datapaas';
@Injectable()
export class UserService {
constructor(
private readonly databaseService: DataPaasDatabaseService,
private readonly databaseManager: DrizzleDatabaseManager,
@Inject(DRIZZLE_DATABASE) private readonly db: PostgresJsDatabase,
) {}
// 方式一:构造函数注入数据库实例
async getUsersByCtor() {
return this.db.select().from(users);
}
// 方式二:方法参数装饰器(请求上下文友好)
async getUsers(@Database() db: PostgresJsDatabase) {
return db.select().from(users);
}
// 使用装饰器注入数据库管理器
async getConnectionStatus(@DatabaseManager() manager: DrizzleDatabaseManager) {
return manager.getConnectionPoolStatus();
}
// 使用装饰器注入数据库服务
async getHealthStatus(@DatabaseService() service: DataPaasDatabaseService) {
return service.isConnected();
}
// 健康检查
async checkHealth() {
return this.databaseService.testConnection();
}
// 获取连接池状态
async getPoolStatus() {
return this.databaseManager.getConnectionPoolStatus();
}
}
数据源由环境变量 MIAODA_DATASOURCE_CONF 决定,平台 PG(engine: pg)和 Base(engine: base)各 0 或 1 个,workspace 为数据源所在的 workspace:
{ "version": 1, "datasources": [
{ "workspace": "workspace_xxx", "engine": "pg", "url": "postgresql://…?schema=workspace_xxx" },
{ "workspace": "workspace_yyy", "engine": "base", "url": "postgresql://…?schema=workspace_yyy" }
] }
MIAODA_DATASOURCE_CONF 时,connectionString 作为唯一的平台 PG(存量行为)。SET LOCAL ROLE / app.*)按查询所用连接的数据源生成,ROLE 取自该数据源连接串的 schema 参数。data,Base 为 data-base。全栈应用开发环境分别显示 Database:PG 和 Database:Base。req.headers['x-tt-logid'],将 SET LOCAL context.log_id = '<log_id>' 与身份语句合并为同一份 preSql,供 PG / Base 查询关联请求日志。缺失或空请求头不注入;并发请求分别保存各自的 log ID。x-tt-env、x-schedule-vdc 分别写入事务内的 context.tt_env、context.schedule_vdc。两个字段独立读取,去掉首尾空白后有值才注入。DataSourceUnboundException(503)。import { BASE_DATABASE, PG_DATABASE, type BaseDatabase, type PostgresJsDatabase } from '@lark-apaas/nestjs-datapaas';
@Injectable()
export class CustomerService {
constructor(
@Inject(PG_DATABASE) private readonly db: PostgresJsDatabase,
@Inject(BASE_DATABASE) private readonly base: BaseDatabase,
) {}
}
同步配置方法。
参数:
connectionString: PostgreSQL 连接串(必填)schema: Drizzle schema(可选)logger: 是否启用日志(可选,默认 false)timeout: 请求超时(ms,可选,默认 10000)maxConnections: PG 和 Base 各自的连接池上限(可选,默认每池 7 条)idleTimeout: 空闲连接超时(秒,可选,默认 20)connectionTimeout: 连接超时(秒,可选,默认 10)ssl: 是否启用 SSL(可选,默认 false)autoContext: 是否为请求自动设置上下文(可选,默认 true)异步配置方法,支持从 ConfigModule 等异步源获取配置。
参数:
imports: 需要导入的模块(例如 [ConfigModule])inject: 工厂函数需要注入的依赖useExisting: 已存在的配置 providerDataPaasModule.forRootAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({
connectionString: configService.get('DATABASE_URL')!,
}),
inject: [ConfigService],
})
testConnection(): 测试数据库连接isConnected(): 检查连接状态getConnectionPoolStatus(): 获取连接池状态@Database(): 注入 Drizzle 数据库实例PG_DATABASE: 平台 PG 的数据库实例BASE_DATABASE: Base 数据源的数据库实例(类型 BaseDatabase)DRIZZLE_DATABASE: 已废弃,与 PG_DATABASE 是同一个实例DatabaseUtils.safeExecute(): 安全执行数据库操作DatabaseUtils.batchExecute(): 批量执行操作DatabaseUtils.executeWithRetry(): 带重试的执行DatabaseUtils.tableExists(): 检查表是否存在DatabaseUtils.getTableStructure(): 获取表结构DatabaseUtils.getDatabaseVersion(): 获取数据库版本DatabaseUtils.getConnectionStats(): 获取连接统计DatabaseUtils.healthCheck(): 健康检查Find threats in your stack.
OX Radar can check high-priority threats, like critical package CVEs, against your context.
Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.
The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).
The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.