servcraft 0.1.0 → 0.1.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/.claude/settings.local.json +29 -0
- package/.github/CODEOWNERS +18 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +46 -0
- package/.github/dependabot.yml +59 -0
- package/.github/workflows/ci.yml +188 -0
- package/.github/workflows/release.yml +195 -0
- package/AUDIT.md +602 -0
- package/README.md +1070 -1
- package/dist/cli/index.cjs +2026 -2168
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +2026 -2168
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +595 -616
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +114 -52
- package/dist/index.d.ts +114 -52
- package/dist/index.js +595 -616
- package/dist/index.js.map +1 -1
- package/docs/CLI-001_MULTI_DB_PLAN.md +546 -0
- package/docs/DATABASE_MULTI_ORM.md +399 -0
- package/docs/PHASE1_BREAKDOWN.md +346 -0
- package/docs/PROGRESS.md +550 -0
- package/docs/modules/ANALYTICS.md +226 -0
- package/docs/modules/API-VERSIONING.md +252 -0
- package/docs/modules/AUDIT.md +192 -0
- package/docs/modules/AUTH.md +431 -0
- package/docs/modules/CACHE.md +346 -0
- package/docs/modules/EMAIL.md +254 -0
- package/docs/modules/FEATURE-FLAG.md +291 -0
- package/docs/modules/I18N.md +294 -0
- package/docs/modules/MEDIA-PROCESSING.md +281 -0
- package/docs/modules/MFA.md +266 -0
- package/docs/modules/NOTIFICATION.md +311 -0
- package/docs/modules/OAUTH.md +237 -0
- package/docs/modules/PAYMENT.md +804 -0
- package/docs/modules/QUEUE.md +540 -0
- package/docs/modules/RATE-LIMIT.md +339 -0
- package/docs/modules/SEARCH.md +288 -0
- package/docs/modules/SECURITY.md +327 -0
- package/docs/modules/SESSION.md +382 -0
- package/docs/modules/SWAGGER.md +305 -0
- package/docs/modules/UPLOAD.md +296 -0
- package/docs/modules/USER.md +505 -0
- package/docs/modules/VALIDATION.md +294 -0
- package/docs/modules/WEBHOOK.md +270 -0
- package/docs/modules/WEBSOCKET.md +691 -0
- package/package.json +53 -38
- package/prisma/schema.prisma +395 -1
- package/src/cli/commands/add-module.ts +520 -87
- package/src/cli/commands/db.ts +3 -4
- package/src/cli/commands/docs.ts +256 -6
- package/src/cli/commands/generate.ts +12 -19
- package/src/cli/commands/init.ts +384 -214
- package/src/cli/index.ts +0 -4
- package/src/cli/templates/repository.ts +6 -1
- package/src/cli/templates/routes.ts +6 -21
- package/src/cli/utils/docs-generator.ts +6 -7
- package/src/cli/utils/env-manager.ts +717 -0
- package/src/cli/utils/field-parser.ts +16 -7
- package/src/cli/utils/interactive-prompt.ts +223 -0
- package/src/cli/utils/template-manager.ts +346 -0
- package/src/config/database.config.ts +183 -0
- package/src/config/env.ts +0 -10
- package/src/config/index.ts +0 -14
- package/src/core/server.ts +1 -1
- package/src/database/adapters/mongoose.adapter.ts +132 -0
- package/src/database/adapters/prisma.adapter.ts +118 -0
- package/src/database/connection.ts +190 -0
- package/src/database/interfaces/database.interface.ts +85 -0
- package/src/database/interfaces/index.ts +7 -0
- package/src/database/interfaces/repository.interface.ts +129 -0
- package/src/database/models/mongoose/index.ts +7 -0
- package/src/database/models/mongoose/payment.schema.ts +347 -0
- package/src/database/models/mongoose/user.schema.ts +154 -0
- package/src/database/prisma.ts +1 -4
- package/src/database/redis.ts +101 -0
- package/src/database/repositories/mongoose/index.ts +7 -0
- package/src/database/repositories/mongoose/payment.repository.ts +380 -0
- package/src/database/repositories/mongoose/user.repository.ts +255 -0
- package/src/database/seed.ts +6 -1
- package/src/index.ts +9 -20
- package/src/middleware/security.ts +2 -6
- package/src/modules/analytics/analytics.routes.ts +80 -0
- package/src/modules/analytics/analytics.service.ts +364 -0
- package/src/modules/analytics/index.ts +18 -0
- package/src/modules/analytics/types.ts +180 -0
- package/src/modules/api-versioning/index.ts +15 -0
- package/src/modules/api-versioning/types.ts +86 -0
- package/src/modules/api-versioning/versioning.middleware.ts +120 -0
- package/src/modules/api-versioning/versioning.routes.ts +54 -0
- package/src/modules/api-versioning/versioning.service.ts +189 -0
- package/src/modules/audit/audit.repository.ts +206 -0
- package/src/modules/audit/audit.service.ts +27 -59
- package/src/modules/auth/auth.controller.ts +2 -2
- package/src/modules/auth/auth.middleware.ts +3 -9
- package/src/modules/auth/auth.routes.ts +10 -107
- package/src/modules/auth/auth.service.ts +126 -23
- package/src/modules/auth/index.ts +3 -4
- package/src/modules/cache/cache.service.ts +367 -0
- package/src/modules/cache/index.ts +10 -0
- package/src/modules/cache/types.ts +44 -0
- package/src/modules/email/email.service.ts +3 -10
- package/src/modules/email/templates.ts +2 -8
- package/src/modules/feature-flag/feature-flag.repository.ts +303 -0
- package/src/modules/feature-flag/feature-flag.routes.ts +247 -0
- package/src/modules/feature-flag/feature-flag.service.ts +566 -0
- package/src/modules/feature-flag/index.ts +20 -0
- package/src/modules/feature-flag/types.ts +192 -0
- package/src/modules/i18n/i18n.middleware.ts +186 -0
- package/src/modules/i18n/i18n.routes.ts +191 -0
- package/src/modules/i18n/i18n.service.ts +456 -0
- package/src/modules/i18n/index.ts +18 -0
- package/src/modules/i18n/types.ts +118 -0
- package/src/modules/media-processing/index.ts +17 -0
- package/src/modules/media-processing/media-processing.routes.ts +111 -0
- package/src/modules/media-processing/media-processing.service.ts +245 -0
- package/src/modules/media-processing/types.ts +156 -0
- package/src/modules/mfa/index.ts +20 -0
- package/src/modules/mfa/mfa.repository.ts +206 -0
- package/src/modules/mfa/mfa.routes.ts +595 -0
- package/src/modules/mfa/mfa.service.ts +572 -0
- package/src/modules/mfa/totp.ts +150 -0
- package/src/modules/mfa/types.ts +57 -0
- package/src/modules/notification/index.ts +20 -0
- package/src/modules/notification/notification.repository.ts +356 -0
- package/src/modules/notification/notification.service.ts +483 -0
- package/src/modules/notification/types.ts +119 -0
- package/src/modules/oauth/index.ts +20 -0
- package/src/modules/oauth/oauth.repository.ts +219 -0
- package/src/modules/oauth/oauth.routes.ts +446 -0
- package/src/modules/oauth/oauth.service.ts +293 -0
- package/src/modules/oauth/providers/apple.provider.ts +250 -0
- package/src/modules/oauth/providers/facebook.provider.ts +181 -0
- package/src/modules/oauth/providers/github.provider.ts +248 -0
- package/src/modules/oauth/providers/google.provider.ts +189 -0
- package/src/modules/oauth/providers/twitter.provider.ts +214 -0
- package/src/modules/oauth/types.ts +94 -0
- package/src/modules/payment/index.ts +19 -0
- package/src/modules/payment/payment.repository.ts +733 -0
- package/src/modules/payment/payment.routes.ts +390 -0
- package/src/modules/payment/payment.service.ts +354 -0
- package/src/modules/payment/providers/mobile-money.provider.ts +274 -0
- package/src/modules/payment/providers/paypal.provider.ts +190 -0
- package/src/modules/payment/providers/stripe.provider.ts +215 -0
- package/src/modules/payment/types.ts +140 -0
- package/src/modules/queue/cron.ts +438 -0
- package/src/modules/queue/index.ts +87 -0
- package/src/modules/queue/queue.routes.ts +600 -0
- package/src/modules/queue/queue.service.ts +842 -0
- package/src/modules/queue/types.ts +222 -0
- package/src/modules/queue/workers.ts +366 -0
- package/src/modules/rate-limit/index.ts +59 -0
- package/src/modules/rate-limit/rate-limit.middleware.ts +134 -0
- package/src/modules/rate-limit/rate-limit.routes.ts +269 -0
- package/src/modules/rate-limit/rate-limit.service.ts +348 -0
- package/src/modules/rate-limit/stores/memory.store.ts +165 -0
- package/src/modules/rate-limit/stores/redis.store.ts +322 -0
- package/src/modules/rate-limit/types.ts +153 -0
- package/src/modules/search/adapters/elasticsearch.adapter.ts +326 -0
- package/src/modules/search/adapters/meilisearch.adapter.ts +261 -0
- package/src/modules/search/adapters/memory.adapter.ts +278 -0
- package/src/modules/search/index.ts +21 -0
- package/src/modules/search/search.service.ts +234 -0
- package/src/modules/search/types.ts +214 -0
- package/src/modules/security/index.ts +40 -0
- package/src/modules/security/sanitize.ts +223 -0
- package/src/modules/security/security-audit.service.ts +388 -0
- package/src/modules/security/security.middleware.ts +398 -0
- package/src/modules/session/index.ts +3 -0
- package/src/modules/session/session.repository.ts +159 -0
- package/src/modules/session/session.service.ts +340 -0
- package/src/modules/session/types.ts +38 -0
- package/src/modules/swagger/index.ts +7 -1
- package/src/modules/swagger/schema-builder.ts +16 -4
- package/src/modules/swagger/swagger.service.ts +9 -10
- package/src/modules/swagger/types.ts +0 -2
- package/src/modules/upload/index.ts +14 -0
- package/src/modules/upload/types.ts +83 -0
- package/src/modules/upload/upload.repository.ts +199 -0
- package/src/modules/upload/upload.routes.ts +311 -0
- package/src/modules/upload/upload.service.ts +448 -0
- package/src/modules/user/index.ts +3 -3
- package/src/modules/user/user.controller.ts +15 -9
- package/src/modules/user/user.repository.ts +237 -113
- package/src/modules/user/user.routes.ts +39 -164
- package/src/modules/user/user.service.ts +4 -3
- package/src/modules/validation/validator.ts +12 -17
- package/src/modules/webhook/index.ts +91 -0
- package/src/modules/webhook/retry.ts +196 -0
- package/src/modules/webhook/signature.ts +135 -0
- package/src/modules/webhook/types.ts +181 -0
- package/src/modules/webhook/webhook.repository.ts +358 -0
- package/src/modules/webhook/webhook.routes.ts +442 -0
- package/src/modules/webhook/webhook.service.ts +457 -0
- package/src/modules/websocket/features.ts +504 -0
- package/src/modules/websocket/index.ts +106 -0
- package/src/modules/websocket/middlewares.ts +298 -0
- package/src/modules/websocket/types.ts +181 -0
- package/src/modules/websocket/websocket.service.ts +692 -0
- package/src/utils/errors.ts +7 -0
- package/src/utils/pagination.ts +4 -1
- package/tests/helpers/db-check.ts +79 -0
- package/tests/integration/auth-redis.test.ts +94 -0
- package/tests/integration/cache-redis.test.ts +387 -0
- package/tests/integration/mongoose-repositories.test.ts +410 -0
- package/tests/integration/payment-prisma.test.ts +637 -0
- package/tests/integration/queue-bullmq.test.ts +417 -0
- package/tests/integration/user-prisma.test.ts +441 -0
- package/tests/integration/websocket-socketio.test.ts +552 -0
- package/tests/setup.ts +11 -9
- package/vitest.config.ts +3 -8
- package/npm-cache/_cacache/content-v2/sha512/1c/d0/03440d500a0487621aad1d6402978340698976602046db8e24fa03c01ee6c022c69b0582f969042d9442ee876ac35c038e960dd427d1e622fa24b8eb7dba +0 -0
- package/npm-cache/_cacache/content-v2/sha512/42/55/28b493ca491833e5aab0e9c3108d29ab3f36c248ca88f45d4630674fce9130959e56ae308797ac2b6328fa7f09a610b9550ed09cb971d039876d293fc69d +0 -0
- package/npm-cache/_cacache/content-v2/sha512/e0/12/f360dc9315ee5f17844a0c8c233ee6bf7c30837c4a02ea0d56c61c7f7ab21c0e958e50ed2c57c59f983c762b93056778c9009b2398ffc26def0183999b13 +0 -0
- package/npm-cache/_cacache/content-v2/sha512/ed/b0/fae1161902898f4c913c67d7f6cdf6be0665aec3b389b9c4f4f0a101ca1da59badf1b59c4e0030f5223023b8d63cfe501c46a32c20c895d4fb3f11ca2232 +0 -0
- package/npm-cache/_cacache/index-v5/58/94/c2cba79e0f16b4c10e95a87e32255741149e8222cc314a476aab67c39cc0 +0 -5
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
# Multi-ORM Database Support Documentation
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
ServCraft now supports multiple ORMs and databases, giving you complete flexibility in choosing your data persistence layer. This implementation provides a unified interface across all ORMs while preserving their unique capabilities.
|
|
6
|
+
|
|
7
|
+
## Supported Configurations
|
|
8
|
+
|
|
9
|
+
### ORM Support
|
|
10
|
+
|
|
11
|
+
| ORM | Version | Databases Supported | Best For |
|
|
12
|
+
|-----|---------|---------------------|----------|
|
|
13
|
+
| **Prisma** | Latest | PostgreSQL, MySQL, SQLite, MongoDB | Modern TypeScript projects, strong type safety |
|
|
14
|
+
| **Mongoose** | ^8.8.4 | MongoDB | MongoDB-specific features, schema validation |
|
|
15
|
+
| **Sequelize** | Coming soon | PostgreSQL, MySQL, SQLite, MariaDB | Legacy SQL projects |
|
|
16
|
+
| **TypeORM** | Coming soon | All databases | Decorator-based approach |
|
|
17
|
+
|
|
18
|
+
### Database Support
|
|
19
|
+
|
|
20
|
+
| Database | ORMs Available | Default Port | Use Case |
|
|
21
|
+
|----------|---------------|--------------|----------|
|
|
22
|
+
| **PostgreSQL** | Prisma, Sequelize*, TypeORM* | 5432 | Production SQL, ACID compliance |
|
|
23
|
+
| **MySQL** | Prisma, Sequelize*, TypeORM* | 3306 | Popular SQL database |
|
|
24
|
+
| **SQLite** | Prisma, Sequelize*, TypeORM* | N/A | Development, embedded |
|
|
25
|
+
| **MongoDB** | Mongoose, Prisma, TypeORM* | 27017 | NoSQL, document-oriented |
|
|
26
|
+
| **MariaDB** | Sequelize*, TypeORM* | 3306 | MySQL alternative |
|
|
27
|
+
|
|
28
|
+
*Coming soon
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
### Using Prisma (PostgreSQL)
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# Initialize project
|
|
36
|
+
npx servcraft init my-app
|
|
37
|
+
|
|
38
|
+
# Select:
|
|
39
|
+
# - Database: PostgreSQL
|
|
40
|
+
# - ORM: Auto-selected (Prisma)
|
|
41
|
+
|
|
42
|
+
# Configure .env
|
|
43
|
+
DATABASE_URL="postgresql://user:password@localhost:5432/mydb"
|
|
44
|
+
DATABASE_ORM=prisma
|
|
45
|
+
DATABASE_TYPE=postgresql
|
|
46
|
+
|
|
47
|
+
# Run migrations
|
|
48
|
+
npx prisma migrate dev
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Using Mongoose (MongoDB)
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# Initialize project
|
|
55
|
+
npx servcraft init my-app
|
|
56
|
+
|
|
57
|
+
# Select:
|
|
58
|
+
# - Database: MongoDB
|
|
59
|
+
# - ORM: Auto-selected (Mongoose)
|
|
60
|
+
|
|
61
|
+
# Configure .env
|
|
62
|
+
MONGODB_URI="mongodb://localhost:27017/mydb"
|
|
63
|
+
DATABASE_ORM=mongoose
|
|
64
|
+
DATABASE_TYPE=mongodb
|
|
65
|
+
|
|
66
|
+
# No migrations needed - Mongoose creates collections automatically
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Architecture
|
|
70
|
+
|
|
71
|
+
### Unified Interface Pattern
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
// All ORMs implement the same interfaces
|
|
75
|
+
interface IDatabaseAdapter {
|
|
76
|
+
connect(): Promise<void>;
|
|
77
|
+
disconnect(): Promise<void>;
|
|
78
|
+
healthCheck(): Promise<boolean>;
|
|
79
|
+
getType(): 'prisma' | 'mongoose' | 'sequelize' | 'typeorm';
|
|
80
|
+
getDatabaseType(): 'postgresql' | 'mysql' | 'sqlite' | 'mongodb';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface IRepository<T> {
|
|
84
|
+
findById(id: string): Promise<T | null>;
|
|
85
|
+
findMany(filter?, options?): Promise<PaginatedResult<T>>;
|
|
86
|
+
findOne(filter): Promise<T | null>;
|
|
87
|
+
create(data): Promise<T>;
|
|
88
|
+
update(id, data): Promise<T | null>;
|
|
89
|
+
delete(id): Promise<boolean>;
|
|
90
|
+
count(filter?): Promise<number>;
|
|
91
|
+
exists(id): Promise<boolean>;
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Factory Pattern
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { DatabaseFactory } from './database/connection.js';
|
|
99
|
+
|
|
100
|
+
// Initialize with config
|
|
101
|
+
const adapter = await DatabaseFactory.initialize({
|
|
102
|
+
orm: 'prisma',
|
|
103
|
+
database: 'postgresql',
|
|
104
|
+
url: process.env.DATABASE_URL,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Or get current adapter
|
|
108
|
+
const adapter = DatabaseFactory.getAdapter();
|
|
109
|
+
|
|
110
|
+
// Health check
|
|
111
|
+
const isHealthy = await DatabaseFactory.healthCheck();
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Usage Examples
|
|
115
|
+
|
|
116
|
+
### Prisma Adapter
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import { DatabaseFactory } from './database/connection.js';
|
|
120
|
+
import { PrismaAdapter } from './database/adapters/prisma.adapter.js';
|
|
121
|
+
|
|
122
|
+
// Initialize
|
|
123
|
+
const adapter = await DatabaseFactory.initialize({
|
|
124
|
+
orm: 'prisma',
|
|
125
|
+
database: 'postgresql',
|
|
126
|
+
url: 'postgresql://localhost:5432/mydb',
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// Get Prisma client
|
|
130
|
+
const prismaAdapter = adapter as PrismaAdapter;
|
|
131
|
+
const prisma = prismaAdapter.getClient();
|
|
132
|
+
|
|
133
|
+
// Use Prisma directly
|
|
134
|
+
const users = await prisma.user.findMany();
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Mongoose Adapter
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
import { DatabaseFactory } from './database/connection.js';
|
|
141
|
+
import { MongooseAdapter } from './database/adapters/mongoose.adapter.js';
|
|
142
|
+
|
|
143
|
+
// Initialize
|
|
144
|
+
const adapter = await DatabaseFactory.initialize({
|
|
145
|
+
orm: 'mongoose',
|
|
146
|
+
database: 'mongodb',
|
|
147
|
+
url: 'mongodb://localhost:27017/mydb',
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// Get Mongoose instance
|
|
151
|
+
const mongooseAdapter = adapter as MongooseAdapter;
|
|
152
|
+
const mongoose = mongooseAdapter.getMongoose();
|
|
153
|
+
|
|
154
|
+
// Use Mongoose models
|
|
155
|
+
import { UserModel } from './database/models/mongoose/user.schema.js';
|
|
156
|
+
const user = await UserModel.findOne({ email: 'test@example.com' });
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Using Repositories (ORM-Agnostic)
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
// Works with ANY ORM!
|
|
163
|
+
import { MongooseUserRepository } from './database/repositories/mongoose/user.repository.js';
|
|
164
|
+
// or
|
|
165
|
+
import { UserRepository } from './modules/user/user.repository.js'; // Prisma
|
|
166
|
+
|
|
167
|
+
const userRepo = new MongooseUserRepository();
|
|
168
|
+
|
|
169
|
+
// Standard interface - works the same regardless of ORM
|
|
170
|
+
const user = await userRepo.create({
|
|
171
|
+
email: 'user@example.com',
|
|
172
|
+
password: 'password123',
|
|
173
|
+
name: 'John Doe',
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const found = await userRepo.findById(user.id);
|
|
177
|
+
const all = await userRepo.findMany({}, { page: 1, limit: 10 });
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Environment Variables
|
|
181
|
+
|
|
182
|
+
### Universal Variables
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
# Required
|
|
186
|
+
DATABASE_ORM=prisma # or mongoose, sequelize, typeorm
|
|
187
|
+
DATABASE_TYPE=postgresql # or mysql, sqlite, mongodb, mariadb
|
|
188
|
+
|
|
189
|
+
# Optional
|
|
190
|
+
DATABASE_LOGGING=false
|
|
191
|
+
DATABASE_SSL=false
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Prisma (SQL Databases)
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
DATABASE_URL="postgresql://user:password@localhost:5432/mydb"
|
|
198
|
+
# or
|
|
199
|
+
DATABASE_URL="mysql://user:password@localhost:3306/mydb"
|
|
200
|
+
# or
|
|
201
|
+
DATABASE_URL="file:./dev.db" # SQLite
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Mongoose (MongoDB)
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
MONGODB_URI="mongodb://localhost:27017/mydb"
|
|
208
|
+
# or with auth
|
|
209
|
+
MONGODB_URI="mongodb://user:password@localhost:27017/mydb"
|
|
210
|
+
# or
|
|
211
|
+
DATABASE_URL="mongodb://localhost:27017/mydb"
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Migration Between ORMs
|
|
215
|
+
|
|
216
|
+
### From Prisma to Mongoose
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
# 1. Export data with Prisma
|
|
220
|
+
npx prisma db push # Ensure schema is synced
|
|
221
|
+
# Export your data
|
|
222
|
+
|
|
223
|
+
# 2. Switch to Mongoose
|
|
224
|
+
# Update .env
|
|
225
|
+
DATABASE_ORM=mongoose
|
|
226
|
+
DATABASE_TYPE=mongodb
|
|
227
|
+
MONGODB_URI="mongodb://localhost:27017/mydb"
|
|
228
|
+
|
|
229
|
+
# 3. Import data to MongoDB
|
|
230
|
+
# Mongoose creates collections automatically
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### From Mongoose to Prisma
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
# 1. Export MongoDB data
|
|
237
|
+
mongoexport --db=mydb --collection=users --out=users.json
|
|
238
|
+
|
|
239
|
+
# 2. Switch to Prisma
|
|
240
|
+
DATABASE_ORM=prisma
|
|
241
|
+
DATABASE_TYPE=postgresql
|
|
242
|
+
DATABASE_URL="postgresql://localhost:5432/mydb"
|
|
243
|
+
|
|
244
|
+
# 3. Run Prisma migrations
|
|
245
|
+
npx prisma migrate dev
|
|
246
|
+
|
|
247
|
+
# 4. Import data (write custom script)
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Testing
|
|
251
|
+
|
|
252
|
+
### Run ORM-Specific Tests
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
# Prisma tests (PostgreSQL)
|
|
256
|
+
npm test tests/integration/user-prisma.test.ts
|
|
257
|
+
|
|
258
|
+
# Mongoose tests (MongoDB)
|
|
259
|
+
# Ensure MongoDB running
|
|
260
|
+
docker run -d -p 27017:27017 mongo:7
|
|
261
|
+
npm test tests/integration/mongoose-repositories.test.ts
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Best Practices
|
|
265
|
+
|
|
266
|
+
### When to Use Prisma
|
|
267
|
+
|
|
268
|
+
✅ Modern TypeScript/JavaScript projects
|
|
269
|
+
✅ Need strong type safety with auto-generated types
|
|
270
|
+
✅ Want excellent VS Code autocomplete
|
|
271
|
+
✅ Working with PostgreSQL, MySQL, or SQLite
|
|
272
|
+
✅ Prefer declarative schema (schema.prisma)
|
|
273
|
+
✅ Need great migration system
|
|
274
|
+
|
|
275
|
+
### When to Use Mongoose
|
|
276
|
+
|
|
277
|
+
✅ MongoDB-only projects
|
|
278
|
+
✅ Need MongoDB-specific features (aggregations, GridFS)
|
|
279
|
+
✅ Prefer schema-based validation in code
|
|
280
|
+
✅ Want middleware hooks (pre/post save)
|
|
281
|
+
✅ Working with document-oriented data
|
|
282
|
+
✅ Need flexible schema evolution
|
|
283
|
+
|
|
284
|
+
### When to Use Sequelize (Coming Soon)
|
|
285
|
+
|
|
286
|
+
✅ Existing Sequelize projects
|
|
287
|
+
✅ Need mature SQL ORM with wide DB support
|
|
288
|
+
✅ Prefer promise-based API
|
|
289
|
+
✅ Working with legacy databases
|
|
290
|
+
|
|
291
|
+
### When to Use TypeORM (Coming Soon)
|
|
292
|
+
|
|
293
|
+
✅ Like decorator-based approach (@Entity, @Column)
|
|
294
|
+
✅ Need Active Record or Data Mapper pattern
|
|
295
|
+
✅ Want to support multiple databases simultaneously
|
|
296
|
+
✅ TypeScript-first projects
|
|
297
|
+
|
|
298
|
+
## Performance Considerations
|
|
299
|
+
|
|
300
|
+
| Aspect | Prisma | Mongoose | Sequelize | TypeORM |
|
|
301
|
+
|--------|--------|----------|-----------|---------|
|
|
302
|
+
| Query Performance | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ |
|
|
303
|
+
| Type Safety | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
|
|
304
|
+
| DX (Developer Experience) | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐ |
|
|
305
|
+
| Learning Curve | ⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐ |
|
|
306
|
+
| MongoDB Support | ⭐⭐⭐ (Preview) | ⭐⭐⭐⭐⭐ | ❌ | ⭐⭐⭐⭐ |
|
|
307
|
+
| SQL Support | ⭐⭐⭐⭐⭐ | ❌ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
|
|
308
|
+
|
|
309
|
+
## Troubleshooting
|
|
310
|
+
|
|
311
|
+
### Prisma Connection Issues
|
|
312
|
+
|
|
313
|
+
**Problem**: Can't connect to PostgreSQL
|
|
314
|
+
|
|
315
|
+
**Solution**:
|
|
316
|
+
```bash
|
|
317
|
+
# Check PostgreSQL is running
|
|
318
|
+
pg_isready
|
|
319
|
+
|
|
320
|
+
# Verify DATABASE_URL format
|
|
321
|
+
DATABASE_URL="postgresql://user:password@localhost:5432/dbname?schema=public"
|
|
322
|
+
|
|
323
|
+
# Run Prisma introspection
|
|
324
|
+
npx prisma db pull
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### Mongoose Connection Issues
|
|
328
|
+
|
|
329
|
+
**Problem**: Can't connect to MongoDB
|
|
330
|
+
|
|
331
|
+
**Solution**:
|
|
332
|
+
```bash
|
|
333
|
+
# Check MongoDB is running
|
|
334
|
+
mongosh --eval "db.runCommand({ ping: 1 })"
|
|
335
|
+
|
|
336
|
+
# Verify MONGODB_URI format
|
|
337
|
+
MONGODB_URI="mongodb://localhost:27017/mydb"
|
|
338
|
+
|
|
339
|
+
# Check MongoDB logs
|
|
340
|
+
docker logs <container-id>
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
### Switching ORMs
|
|
344
|
+
|
|
345
|
+
**Problem**: Want to change ORM after project initialization
|
|
346
|
+
|
|
347
|
+
**Solution**:
|
|
348
|
+
1. Export existing data
|
|
349
|
+
2. Update `.env` file (DATABASE_ORM, DATABASE_TYPE, DATABASE_URL)
|
|
350
|
+
3. Install new ORM dependencies if needed
|
|
351
|
+
4. Run migrations/setup for new ORM
|
|
352
|
+
5. Import data
|
|
353
|
+
6. Update repository imports in your code
|
|
354
|
+
|
|
355
|
+
## Roadmap
|
|
356
|
+
|
|
357
|
+
### Currently Available
|
|
358
|
+
- ✅ Prisma (PostgreSQL, MySQL, SQLite, MongoDB)
|
|
359
|
+
- ✅ Mongoose (MongoDB)
|
|
360
|
+
- ✅ Common interfaces and adapters
|
|
361
|
+
- ✅ Repository pattern
|
|
362
|
+
- ✅ Factory pattern with validation
|
|
363
|
+
|
|
364
|
+
### Coming Soon
|
|
365
|
+
- 🔄 Sequelize adapter
|
|
366
|
+
- 🔄 TypeORM adapter
|
|
367
|
+
- 🔄 Automatic migration between ORMs
|
|
368
|
+
- 🔄 ORM-agnostic query builder
|
|
369
|
+
- 🔄 Advanced transaction support
|
|
370
|
+
|
|
371
|
+
## Related Documentation
|
|
372
|
+
|
|
373
|
+
- [Prisma Modules](./modules/USER.md) - User module with Prisma
|
|
374
|
+
- [Mongoose Schemas](../src/database/models/mongoose/) - Mongoose schema definitions
|
|
375
|
+
- [Database Interfaces](../src/database/interfaces/) - Common interfaces
|
|
376
|
+
- [CLI Documentation](../README.md#cli) - CLI usage
|
|
377
|
+
|
|
378
|
+
## Changelog
|
|
379
|
+
|
|
380
|
+
### v0.3.0 (2025-12-19)
|
|
381
|
+
|
|
382
|
+
**Multi-ORM Support - MVP:**
|
|
383
|
+
- ✅ Added common database interfaces (IDatabaseAdapter, IRepository)
|
|
384
|
+
- ✅ Implemented Factory pattern with lazy loading
|
|
385
|
+
- ✅ Created Prisma adapter (PostgreSQL, MySQL, SQLite, MongoDB)
|
|
386
|
+
- ✅ Created Mongoose adapter (MongoDB)
|
|
387
|
+
- ✅ Implemented Mongoose schemas (User, Payment, Subscription, Plan, Webhook)
|
|
388
|
+
- ✅ Implemented Mongoose repositories
|
|
389
|
+
- ✅ Added configuration validation
|
|
390
|
+
- ✅ Added compatibility matrix
|
|
391
|
+
- ✅ Updated CLI to support MongoDB with Mongoose
|
|
392
|
+
- ✅ Added integration tests for Mongoose
|
|
393
|
+
- ✅ Added comprehensive documentation
|
|
394
|
+
|
|
395
|
+
### v0.2.0
|
|
396
|
+
- Prisma-only support
|
|
397
|
+
|
|
398
|
+
### v0.1.0
|
|
399
|
+
- Initial release
|