@yayoyunlm/utils_sql_storage 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/index.cjs +38 -0
- package/dist/index.d.cts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +11 -0
- package/package.json +32 -0
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
createDbClient(
|
|
2
|
+
PrismaClientConstructor: typeof PrismaClient, // 外部传入的 Prisma 构造函数
|
|
3
|
+
connectionString: string // PostgreSQL 连接字符串
|
|
4
|
+
): PrismaClient // 返回配置好的 Prisma 客户端实例
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
// 1. 获取数据库连接字符串(环境变量)
|
|
8
|
+
const DATABASE_URL = process.env.DATABASE_URL!;
|
|
9
|
+
PrismaClient=schema.prismaoutput
|
|
10
|
+
|
|
11
|
+
// 2. 传入 PrismaClient + 连接串,创建实例
|
|
12
|
+
const db = createDbClient(PrismaClient, DATABASE_URL);
|
|
13
|
+
|
|
14
|
+
// 3. 导出供全局使用
|
|
15
|
+
export default db;
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
createDbClient: () => createDbClient
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// linkdatabase.ts
|
|
28
|
+
var import_pg = require("pg");
|
|
29
|
+
var import_adapter_pg = require("@prisma/adapter-pg");
|
|
30
|
+
function createDbClient(PrismaClientConstructor, connectionString) {
|
|
31
|
+
const pool = new import_pg.Pool({ connectionString });
|
|
32
|
+
const adapter = new import_adapter_pg.PrismaPg(pool);
|
|
33
|
+
return new PrismaClientConstructor({ adapter });
|
|
34
|
+
}
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
createDbClient
|
|
38
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as _prisma_client_runtime_client from '@prisma/client/runtime/client';
|
|
2
|
+
import { PrismaClient } from '@prisma/client';
|
|
3
|
+
export { PrismaClient } from '@prisma/client';
|
|
4
|
+
import { PrismaPg } from '@prisma/adapter-pg';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 通用数据库客户端工厂函数
|
|
8
|
+
* @param PrismaClientConstructor 外部传入的 PrismaClient 构造函数
|
|
9
|
+
* @param connectionString 数据库连接字符串
|
|
10
|
+
* @returns 配置好 PostgreSQL 适配器的 Prisma 客户端实例
|
|
11
|
+
*/
|
|
12
|
+
declare function createDbClient(PrismaClientConstructor: typeof PrismaClient, connectionString: string): PrismaClient<{
|
|
13
|
+
adapter: PrismaPg;
|
|
14
|
+
}, never, _prisma_client_runtime_client.DefaultArgs>;
|
|
15
|
+
|
|
16
|
+
export { createDbClient };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as _prisma_client_runtime_client from '@prisma/client/runtime/client';
|
|
2
|
+
import { PrismaClient } from '@prisma/client';
|
|
3
|
+
export { PrismaClient } from '@prisma/client';
|
|
4
|
+
import { PrismaPg } from '@prisma/adapter-pg';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 通用数据库客户端工厂函数
|
|
8
|
+
* @param PrismaClientConstructor 外部传入的 PrismaClient 构造函数
|
|
9
|
+
* @param connectionString 数据库连接字符串
|
|
10
|
+
* @returns 配置好 PostgreSQL 适配器的 Prisma 客户端实例
|
|
11
|
+
*/
|
|
12
|
+
declare function createDbClient(PrismaClientConstructor: typeof PrismaClient, connectionString: string): PrismaClient<{
|
|
13
|
+
adapter: PrismaPg;
|
|
14
|
+
}, never, _prisma_client_runtime_client.DefaultArgs>;
|
|
15
|
+
|
|
16
|
+
export { createDbClient };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// linkdatabase.ts
|
|
2
|
+
import { Pool } from "pg";
|
|
3
|
+
import { PrismaPg } from "@prisma/adapter-pg";
|
|
4
|
+
function createDbClient(PrismaClientConstructor, connectionString) {
|
|
5
|
+
const pool = new Pool({ connectionString });
|
|
6
|
+
const adapter = new PrismaPg(pool);
|
|
7
|
+
return new PrismaClientConstructor({ adapter });
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
createDbClient
|
|
11
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yayoyunlm/utils_sql_storage",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "TypeScript library build with tsup",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "yayoyunlm",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"tsup": "^8",
|
|
18
|
+
"typescript": "^5",
|
|
19
|
+
"@types/pg": "^8.11.0",
|
|
20
|
+
"@prisma/client": "^7.8.0",
|
|
21
|
+
"@prisma/adapter-pg": "^7.8.0"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"pg": "^8.20.0",
|
|
25
|
+
"prisma": "^7.8.0",
|
|
26
|
+
"@prisma/client": "^7.8.0",
|
|
27
|
+
"@prisma/adapter-pg": "^7.8.0"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsup index.ts --format cjs,esm --dts"
|
|
31
|
+
}
|
|
32
|
+
}
|