kfreelance-project-postgresql-prisma-2 0.0.1
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 +217 -0
- package/dist/client.d.ts +3 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +7 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/generated/prisma/client.d.ts +1 -0
- package/generated/prisma/client.js +4 -0
- package/generated/prisma/default.d.ts +1 -0
- package/generated/prisma/default.js +4 -0
- package/generated/prisma/edge.d.ts +1 -0
- package/generated/prisma/edge.js +363 -0
- package/generated/prisma/index-browser.js +345 -0
- package/generated/prisma/index.d.ts +19091 -0
- package/generated/prisma/index.js +388 -0
- package/generated/prisma/libquery_engine-darwin-arm64.dylib.node +0 -0
- package/generated/prisma/libquery_engine-linux-musl-arm64-openssl-3.0.x.so.node +0 -0
- package/generated/prisma/package.json +183 -0
- package/generated/prisma/query_engine_bg.js +2 -0
- package/generated/prisma/query_engine_bg.wasm +0 -0
- package/generated/prisma/runtime/edge-esm.js +34 -0
- package/generated/prisma/runtime/edge.js +34 -0
- package/generated/prisma/runtime/index-browser.d.ts +370 -0
- package/generated/prisma/runtime/index-browser.js +16 -0
- package/generated/prisma/runtime/library.d.ts +3976 -0
- package/generated/prisma/runtime/library.js +146 -0
- package/generated/prisma/runtime/react-native.js +83 -0
- package/generated/prisma/runtime/wasm-compiler-edge.js +84 -0
- package/generated/prisma/runtime/wasm-engine-edge.js +36 -0
- package/generated/prisma/schema.prisma +212 -0
- package/generated/prisma/wasm-edge-light-loader.mjs +4 -0
- package/generated/prisma/wasm-worker-loader.mjs +4 -0
- package/generated/prisma/wasm.d.ts +1 -0
- package/generated/prisma/wasm.js +370 -0
- package/package.json +55 -0
- package/prisma/migrations/20251003030244_init/migration.sql +33 -0
- package/prisma/migrations/20251006071441_update_user_columns_name/migration.sql +10 -0
- package/prisma/migrations/20251229080245_add_is_admin_in_user/migration.sql +2 -0
- package/prisma/migrations/20251229092526_remove_passort_reset/migration.sql +11 -0
- package/prisma/migrations/20251229101534_init_trip_domain/migration.sql +186 -0
- package/prisma/migrations/migration_lock.toml +3 -0
- package/prisma/models/trips.prisma +183 -0
- package/prisma/models/users.prisma +11 -0
- package/prisma/schema.prisma +16 -0
package/README.MD
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# kfreelance-project-postgresql-prisma
|
|
2
|
+
|
|
3
|
+
A shared Prisma client library for microservices, providing a centralized database schema and ORM functionality.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install kfreelance-project-postgresql-prisma
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### Basic Usage
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { PrismaClient } from 'kfreelance-project-postgresql-prisma';
|
|
17
|
+
|
|
18
|
+
const prisma = new PrismaClient();
|
|
19
|
+
|
|
20
|
+
async function main() {
|
|
21
|
+
// Create a user
|
|
22
|
+
const user = await prisma.user.create({
|
|
23
|
+
data: {
|
|
24
|
+
username: 'john_doe',
|
|
25
|
+
email: 'john@example.com',
|
|
26
|
+
passwordHash: 'hashed_password_here',
|
|
27
|
+
is_active: true,
|
|
28
|
+
must_reset_password: false,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Find all users
|
|
33
|
+
const users = await prisma.user.findMany();
|
|
34
|
+
console.log(users);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
main()
|
|
38
|
+
.then(async () => {
|
|
39
|
+
await prisma.$disconnect();
|
|
40
|
+
})
|
|
41
|
+
.catch(async (e) => {
|
|
42
|
+
console.error(e);
|
|
43
|
+
await prisma.$disconnect();
|
|
44
|
+
process.exit(1);
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Using Custom Database URL
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { createPrismaClient } from 'kfreelance-project-postgresql-prisma';
|
|
52
|
+
|
|
53
|
+
const prisma = createPrismaClient({
|
|
54
|
+
databaseUrl: 'postgresql://user:password@localhost:5432/mydb',
|
|
55
|
+
log: ['query', 'error'],
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Direct Client Import (Alternative)
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { PrismaClient } from 'kfreelance-project-postgresql-prisma/client';
|
|
63
|
+
|
|
64
|
+
const prisma = new PrismaClient();
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Environment Variables
|
|
68
|
+
|
|
69
|
+
Set the following environment variable in your microservice:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
DATABASE_URL="postgresql://postgres:your_secure_password@localhost:5432/freelance_db?schema=public"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Available Types
|
|
76
|
+
|
|
77
|
+
The library exports all Prisma-generated types:
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import type { User, PasswordResetToken, Prisma } from 'kfreelance-project-postgresql-prisma';
|
|
81
|
+
|
|
82
|
+
// Use types for function parameters
|
|
83
|
+
function createUser(userData: Prisma.UserCreateInput): Promise<User> {
|
|
84
|
+
return prisma.user.create({ data: userData });
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Database Schema
|
|
89
|
+
|
|
90
|
+
The library includes the following models:
|
|
91
|
+
|
|
92
|
+
### User
|
|
93
|
+
- `id`: String (UUID)
|
|
94
|
+
- `username`: String (unique)
|
|
95
|
+
- `email`: String (unique)
|
|
96
|
+
- `passwordHash`: String
|
|
97
|
+
- `is_active`: Boolean
|
|
98
|
+
- `must_reset_password`: Boolean
|
|
99
|
+
- `created_at`: DateTime
|
|
100
|
+
- `updated_at`: DateTime
|
|
101
|
+
|
|
102
|
+
### PasswordResetToken
|
|
103
|
+
- `id`: String (UUID)
|
|
104
|
+
- `user_id`: String (foreign key to User)
|
|
105
|
+
- `reset_token`: String (hashed)
|
|
106
|
+
- `expires_at`: DateTime
|
|
107
|
+
- `used`: Boolean
|
|
108
|
+
|
|
109
|
+
## Utility Functions
|
|
110
|
+
|
|
111
|
+
### `createPrismaClient(options?)`
|
|
112
|
+
|
|
113
|
+
Create a PrismaClient instance with custom configuration:
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
const prisma = createPrismaClient({
|
|
117
|
+
databaseUrl: 'your-custom-database-url',
|
|
118
|
+
log: ['query', 'info', 'warn', 'error'], // Optional logging
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### `getDefaultDatabaseUrl()`
|
|
123
|
+
|
|
124
|
+
Get the default database URL (useful for debugging):
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
import { getDefaultDatabaseUrl } from 'kfreelance-project-postgresql-prisma';
|
|
128
|
+
|
|
129
|
+
console.log('Using database:', getDefaultDatabaseUrl());
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Development
|
|
133
|
+
|
|
134
|
+
If you're working on this library:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
# Install dependencies
|
|
138
|
+
npm install
|
|
139
|
+
|
|
140
|
+
# Copy environment file
|
|
141
|
+
cp .env.example .env
|
|
142
|
+
|
|
143
|
+
# Generate Prisma client
|
|
144
|
+
npm run generate
|
|
145
|
+
|
|
146
|
+
# Build the library
|
|
147
|
+
npm run build
|
|
148
|
+
|
|
149
|
+
# Run development example
|
|
150
|
+
npm run dev
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Publishing
|
|
154
|
+
|
|
155
|
+
To publish a new version:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
# Build the library
|
|
159
|
+
npm run build
|
|
160
|
+
|
|
161
|
+
# Publish to npm
|
|
162
|
+
npm publish --access public
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Integration in Microservices
|
|
166
|
+
|
|
167
|
+
### 1. Install the library
|
|
168
|
+
```bash
|
|
169
|
+
npm install kfreelance-project-postgresql-prisma
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### 2. Set environment variables
|
|
173
|
+
```bash
|
|
174
|
+
# .env
|
|
175
|
+
DATABASE_URL="postgresql://postgres:password@localhost:5432/freelance_db?schema=public"
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### 3. Use in your microservice
|
|
179
|
+
```typescript
|
|
180
|
+
import { PrismaClient, type User } from 'kfreelance-project-postgresql-prisma';
|
|
181
|
+
|
|
182
|
+
const prisma = new PrismaClient();
|
|
183
|
+
|
|
184
|
+
export class UserService {
|
|
185
|
+
async findUserById(id: string): Promise<User | null> {
|
|
186
|
+
return prisma.user.findUnique({ where: { id } });
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async createUser(userData: {
|
|
190
|
+
username: string;
|
|
191
|
+
email: string;
|
|
192
|
+
passwordHash: string;
|
|
193
|
+
}): Promise<User> {
|
|
194
|
+
return prisma.user.create({
|
|
195
|
+
data: {
|
|
196
|
+
...userData,
|
|
197
|
+
is_active: true,
|
|
198
|
+
must_reset_password: false,
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Migration Notes
|
|
206
|
+
|
|
207
|
+
When the database schema changes:
|
|
208
|
+
|
|
209
|
+
1. Update the Prisma schema in this library
|
|
210
|
+
2. Generate new migrations
|
|
211
|
+
3. Build and publish a new version
|
|
212
|
+
4. Update the library version in your microservices
|
|
213
|
+
5. Run database migrations
|
|
214
|
+
|
|
215
|
+
## Support
|
|
216
|
+
|
|
217
|
+
For issues or questions about this library, please contact the platform team or create an issue in the repository.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,mBAAmB,8BAA8B,CAAC"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PrismaClient = void 0;
|
|
4
|
+
// Direct client export for simple usage
|
|
5
|
+
var index_js_1 = require("../generated/prisma/index.js");
|
|
6
|
+
Object.defineProperty(exports, "PrismaClient", { enumerable: true, get: function () { return index_js_1.PrismaClient; } });
|
|
7
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,wCAAwC;AACxC,yDAA4D;AAAnD,wGAAA,YAAY,OAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { PrismaClient } from "../generated/prisma";
|
|
2
|
+
export type { Prisma, User } from "../generated/prisma";
|
|
3
|
+
export declare const getDefaultDatabaseUrl: () => string;
|
|
4
|
+
export declare const createPrismaClient: (options?: {
|
|
5
|
+
databaseUrl?: string;
|
|
6
|
+
log?: Array<"query" | "info" | "warn" | "error">;
|
|
7
|
+
}) => any;
|
|
8
|
+
import { PrismaClient } from "../generated/prisma";
|
|
9
|
+
export default PrismaClient;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAGxD,eAAO,MAAM,qBAAqB,cAKjC,CAAC;AAGF,eAAO,MAAM,kBAAkB,GAAI,UAAU;IAC3C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,KAAK,CAAC,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;CAClD,QAWA,CAAC;AAGF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,eAAe,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPrismaClient = exports.getDefaultDatabaseUrl = exports.PrismaClient = void 0;
|
|
4
|
+
// Export Prisma Client and types
|
|
5
|
+
var prisma_1 = require("../generated/prisma");
|
|
6
|
+
Object.defineProperty(exports, "PrismaClient", { enumerable: true, get: function () { return prisma_1.PrismaClient; } });
|
|
7
|
+
// Default database URL helper
|
|
8
|
+
const getDefaultDatabaseUrl = () => {
|
|
9
|
+
return (process.env.DATABASE_URL ||
|
|
10
|
+
"postgresql://postgres:password@localhost:5432/freelance_db");
|
|
11
|
+
};
|
|
12
|
+
exports.getDefaultDatabaseUrl = getDefaultDatabaseUrl;
|
|
13
|
+
// Factory function to create Prisma client with custom options
|
|
14
|
+
const createPrismaClient = (options) => {
|
|
15
|
+
const { PrismaClient } = require("../generated/prisma");
|
|
16
|
+
return new PrismaClient({
|
|
17
|
+
datasources: {
|
|
18
|
+
db: {
|
|
19
|
+
url: options?.databaseUrl || (0, exports.getDefaultDatabaseUrl)(),
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
log: options?.log || ["error", "warn"],
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
exports.createPrismaClient = createPrismaClient;
|
|
26
|
+
// Default export for convenience
|
|
27
|
+
const prisma_2 = require("../generated/prisma");
|
|
28
|
+
exports.default = prisma_2.PrismaClient;
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,8CAAmD;AAA1C,sGAAA,YAAY,OAAA;AAGrB,8BAA8B;AACvB,MAAM,qBAAqB,GAAG,GAAG,EAAE;IACxC,OAAO,CACL,OAAO,CAAC,GAAG,CAAC,YAAY;QACxB,4DAA4D,CAC7D,CAAC;AACJ,CAAC,CAAC;AALW,QAAA,qBAAqB,yBAKhC;AAEF,+DAA+D;AACxD,MAAM,kBAAkB,GAAG,CAAC,OAGlC,EAAE,EAAE;IACH,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAExD,OAAO,IAAI,YAAY,CAAC;QACtB,WAAW,EAAE;YACX,EAAE,EAAE;gBACF,GAAG,EAAE,OAAO,EAAE,WAAW,IAAI,IAAA,6BAAqB,GAAE;aACrD;SACF;QACD,GAAG,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC;KACvC,CAAC,CAAC;AACL,CAAC,CAAC;AAdW,QAAA,kBAAkB,sBAc7B;AAEF,iCAAiC;AACjC,gDAAmD;AACnD,kBAAe,qBAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./index"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./index"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./default"
|