@venizia/ignis-docs 0.0.8-3 → 0.1.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 +7 -7
- package/{wiki → content}/best-practices/api-usage-examples.md +15 -12
- package/{wiki → content}/best-practices/architectural-patterns.md +70 -78
- package/{wiki → content}/best-practices/architecture-decisions.md +91 -60
- package/{wiki → content}/best-practices/code-style-standards/advanced-patterns.md +56 -44
- package/{wiki → content}/best-practices/code-style-standards/constants-configuration.md +11 -11
- package/{wiki → content}/best-practices/code-style-standards/control-flow.md +5 -2
- package/{wiki → content}/best-practices/code-style-standards/documentation.md +13 -13
- package/{wiki → content}/best-practices/code-style-standards/function-patterns.md +9 -10
- package/{wiki → content}/best-practices/code-style-standards/index.md +1 -1
- package/{wiki → content}/best-practices/code-style-standards/naming-conventions.md +10 -8
- package/{wiki → content}/best-practices/code-style-standards/route-definitions.md +30 -12
- package/{wiki → content}/best-practices/code-style-standards/tooling.md +8 -5
- package/{wiki → content}/best-practices/code-style-standards/type-safety.md +13 -12
- package/{wiki → content}/best-practices/common-pitfalls.md +56 -37
- package/{wiki → content}/best-practices/contribution-workflow.md +13 -14
- package/{wiki → content}/best-practices/data-modeling.md +44 -20
- package/{wiki → content}/best-practices/deployment-strategies.md +28 -27
- package/{wiki → content}/best-practices/error-handling.md +48 -24
- package/{wiki → content}/best-practices/index.md +5 -5
- package/{wiki → content}/best-practices/performance-optimization.md +36 -28
- package/{wiki → content}/best-practices/security-guidelines.md +52 -23
- package/{wiki → content}/best-practices/testing-strategies.md +65 -51
- package/{wiki → content}/best-practices/troubleshooting-tips.md +24 -24
- package/{wiki/extensions/components/swagger.md → content/extensions/components/api-reference.md} +40 -31
- package/{wiki → content}/extensions/components/authentication/api.md +19 -19
- package/{wiki → content}/extensions/components/authentication/errors.md +7 -7
- package/{wiki → content}/extensions/components/authentication/index.md +10 -8
- package/{wiki → content}/extensions/components/authentication/usage.md +101 -6
- package/{wiki → content}/extensions/components/authorization/api.md +45 -25
- package/{wiki → content}/extensions/components/authorization/errors.md +6 -6
- package/{wiki → content}/extensions/components/authorization/index.md +11 -10
- package/{wiki → content}/extensions/components/authorization/usage.md +21 -21
- package/{wiki → content}/extensions/components/health-check.md +1 -1
- package/{wiki → content}/extensions/components/index.md +5 -5
- package/{wiki → content}/extensions/components/mail/errors.md +15 -15
- package/{wiki → content}/extensions/components/mail/index.md +1 -2
- package/{wiki → content}/extensions/components/mail/usage.md +1 -1
- package/{wiki → content}/extensions/components/request-tracker.md +1 -1
- package/{wiki → content}/extensions/components/socket-io/api.md +9 -9
- package/{wiki → content}/extensions/components/socket-io/errors.md +5 -5
- package/{wiki → content}/extensions/components/socket-io/index.md +8 -8
- package/{wiki → content}/extensions/components/socket-io/usage.md +1 -1
- package/{wiki → content}/extensions/components/static-asset/api.md +17 -4
- package/{wiki → content}/extensions/components/static-asset/errors.md +4 -4
- package/{wiki → content}/extensions/components/static-asset/index.md +26 -28
- package/{wiki → content}/extensions/components/static-asset/usage.md +13 -12
- package/{wiki → content}/extensions/components/template/index.md +2 -2
- package/{wiki → content}/extensions/components/template/setup-page.md +1 -1
- package/{wiki → content}/extensions/components/websocket/api.md +3 -3
- package/{wiki → content}/extensions/components/websocket/errors.md +5 -5
- package/{wiki → content}/extensions/components/websocket/index.md +5 -5
- package/{wiki → content}/extensions/components/websocket/usage.md +3 -3
- package/{wiki → content}/extensions/helpers/cron/index.md +2 -2
- package/{wiki → content}/extensions/helpers/crypto/index.md +1 -1
- package/{wiki → content}/extensions/helpers/env/index.md +27 -12
- package/content/extensions/helpers/error/index.md +283 -0
- package/{wiki → content}/extensions/helpers/index.md +2 -3
- package/{wiki → content}/extensions/helpers/inversion/index.md +15 -7
- package/{wiki → content}/extensions/helpers/kafka/examples.md +1 -1
- package/{wiki → content}/extensions/helpers/logger/index.md +32 -2
- package/{wiki → content}/extensions/helpers/network/index.md +6 -0
- package/{wiki → content}/extensions/helpers/queue/index.md +14 -17
- package/content/extensions/helpers/redis/index.md +713 -0
- package/{wiki → content}/extensions/helpers/socket-io/index.md +14 -10
- package/{wiki → content}/extensions/helpers/storage/api.md +44 -8
- package/{wiki → content}/extensions/helpers/storage/index.md +43 -7
- package/{wiki → content}/extensions/helpers/template/index.md +6 -3
- package/{wiki → content}/extensions/helpers/types/index.md +11 -8
- package/{wiki → content}/extensions/helpers/websocket/api.md +9 -9
- package/{wiki → content}/extensions/helpers/websocket/index.md +7 -7
- package/{wiki → content}/extensions/helpers/worker-thread/index.md +2 -2
- package/{wiki → content}/extensions/index.md +3 -4
- package/{wiki → content}/extensions/src-details/mcp-server.md +18 -24
- package/{wiki → content}/guides/core-concepts/application/bootstrapping.md +11 -14
- package/{wiki → content}/guides/core-concepts/application/index.md +3 -3
- package/{wiki → content}/guides/core-concepts/components.md +19 -10
- package/{wiki → content}/guides/core-concepts/dependency-injection.md +6 -3
- package/{wiki → content}/guides/core-concepts/grpc-controllers.md +6 -5
- package/{wiki → content}/guides/core-concepts/persistent/datasources.md +33 -27
- package/{wiki → content}/guides/core-concepts/persistent/index.md +16 -5
- package/{wiki → content}/guides/core-concepts/persistent/models.md +24 -20
- package/content/guides/core-concepts/persistent/postgres-drivers.md +167 -0
- package/{wiki → content}/guides/core-concepts/persistent/repositories.md +40 -23
- package/content/guides/core-concepts/persistent/search-meilisearch.md +183 -0
- package/content/guides/core-concepts/persistent/search-typesense.md +429 -0
- package/{wiki → content}/guides/core-concepts/persistent/transactions.md +61 -25
- package/{wiki → content}/guides/core-concepts/rest-controllers.md +12 -9
- package/content/guides/core-concepts/services.md +389 -0
- package/{wiki → content}/guides/get-started/5-minute-quickstart.md +19 -19
- package/{wiki → content}/guides/get-started/philosophy.md +36 -36
- package/{wiki → content}/guides/get-started/setup.md +3 -3
- package/{wiki → content}/guides/index.md +3 -3
- package/content/guides/migrations/redis-helpers-migration.md +177 -0
- package/{wiki → content}/guides/migrations/scoped-rbac-migration.md +17 -17
- package/content/guides/migrations/unified-connectors-migration.md +113 -0
- package/{wiki → content}/guides/reference/glossary.md +19 -12
- package/{wiki → content}/guides/reference/mcp-docs-server.md +22 -18
- package/{wiki → content}/guides/tutorials/building-a-crud-api.md +30 -33
- package/{wiki → content}/guides/tutorials/complete-installation.md +17 -17
- package/{wiki → content}/guides/tutorials/ecommerce-api.md +158 -119
- package/{wiki → content}/guides/tutorials/realtime-chat.md +176 -130
- package/content/guides/tutorials/testing.md +264 -0
- package/content/index.md +5 -0
- package/content/public/apple-touch-icon.png +0 -0
- package/content/public/og-image.png +0 -0
- package/content/public/site.webmanifest +11 -0
- package/{wiki → content}/references/base/application.md +4 -5
- package/{wiki → content}/references/base/bootstrapping.md +18 -5
- package/{wiki → content}/references/base/components.md +149 -120
- package/content/references/base/connectors.md +178 -0
- package/{wiki → content}/references/base/controllers.md +41 -30
- package/content/references/base/datasources.md +527 -0
- package/{wiki → content}/references/base/dependency-injection.md +34 -22
- package/{wiki → content}/references/base/filter-system/application-usage.md +17 -14
- package/{wiki → content}/references/base/filter-system/array-operators.md +7 -2
- package/{wiki → content}/references/base/filter-system/comparison-operators.md +3 -0
- package/{wiki → content}/references/base/filter-system/default-filter.md +89 -71
- package/{wiki → content}/references/base/filter-system/fields-order-pagination.md +22 -22
- package/{wiki → content}/references/base/filter-system/index.md +6 -3
- package/{wiki → content}/references/base/filter-system/json-filtering.md +20 -1
- package/{wiki → content}/references/base/filter-system/list-operators.md +1 -1
- package/{wiki → content}/references/base/filter-system/logical-operators.md +33 -1
- package/{wiki → content}/references/base/filter-system/null-operators.md +30 -1
- package/{wiki → content}/references/base/filter-system/quick-reference.md +23 -4
- package/{wiki → content}/references/base/filter-system/tips.md +5 -5
- package/{wiki → content}/references/base/filter-system/use-cases.md +12 -12
- package/{wiki → content}/references/base/grpc-controllers.md +13 -13
- package/{wiki → content}/references/base/index.md +24 -12
- package/{wiki/references/base/middleware.md → content/references/base/middlewares.md} +205 -24
- package/{wiki → content}/references/base/models.md +63 -49
- package/{wiki → content}/references/base/providers.md +136 -130
- package/{wiki → content}/references/base/repositories/advanced.md +59 -58
- package/{wiki → content}/references/base/repositories/index.md +115 -91
- package/content/references/base/repositories/mixins.md +99 -0
- package/{wiki → content}/references/base/repositories/relations.md +54 -64
- package/{wiki → content}/references/base/repositories/soft-deletable.md +31 -30
- package/content/references/base/services.md +404 -0
- package/{wiki → content}/references/configuration/environment-variables.md +46 -30
- package/{wiki → content}/references/configuration/index.md +6 -6
- package/{wiki → content}/references/index.md +17 -12
- package/{wiki → content}/references/quick-reference.md +65 -106
- package/content/references/utilities/crypto.md +98 -0
- package/{wiki → content}/references/utilities/index.md +3 -3
- package/{wiki → content}/references/utilities/jsx.md +6 -4
- package/content/references/utilities/module.md +90 -0
- package/{wiki → content}/references/utilities/parse.md +4 -14
- package/{wiki → content}/references/utilities/promise.md +9 -7
- package/{wiki → content}/references/utilities/schema.md +5 -3
- package/dist/mcp-server/common/guards.d.ts +8 -0
- package/dist/mcp-server/common/guards.d.ts.map +1 -0
- package/dist/mcp-server/common/guards.js +14 -0
- package/dist/mcp-server/common/guards.js.map +1 -0
- package/dist/mcp-server/common/index.d.ts +1 -0
- package/dist/mcp-server/common/index.d.ts.map +1 -1
- package/dist/mcp-server/common/index.js +1 -0
- package/dist/mcp-server/common/index.js.map +1 -1
- package/dist/mcp-server/common/paths.d.ts.map +1 -1
- package/dist/mcp-server/common/paths.js +2 -2
- package/dist/mcp-server/common/paths.js.map +1 -1
- package/dist/mcp-server/helpers/docs.helper.d.ts.map +1 -1
- package/dist/mcp-server/helpers/docs.helper.js +4 -2
- package/dist/mcp-server/helpers/docs.helper.js.map +1 -1
- package/dist/mcp-server/helpers/github.helper.js +1 -1
- package/dist/mcp-server/index.js +7 -2
- package/dist/mcp-server/index.js.map +1 -1
- package/dist/mcp-server/tools/base.tool.d.ts +6 -2
- package/dist/mcp-server/tools/base.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/base.tool.js.map +1 -1
- package/dist/mcp-server/tools/docs/search-documents.tool.d.ts +1 -1
- package/dist/mcp-server/tools/github/list-project-files.tool.d.ts +1 -1
- package/dist/mcp-server/tools/github/search-code.tool.d.ts +1 -1
- package/dist/mcp-server/tools/github/search-code.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/github/search-code.tool.js +4 -1
- package/dist/mcp-server/tools/github/search-code.tool.js.map +1 -1
- package/dist/mcp-server/tools/github/verify-dependencies.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/github/verify-dependencies.tool.js +3 -1
- package/dist/mcp-server/tools/github/verify-dependencies.tool.js.map +1 -1
- package/package.json +12 -12
- package/wiki/extensions/helpers/error/index.md +0 -227
- package/wiki/extensions/helpers/redis/index.md +0 -488
- package/wiki/extensions/helpers/testing/index.md +0 -510
- package/wiki/guides/core-concepts/services.md +0 -119
- package/wiki/guides/tutorials/testing.md +0 -722
- package/wiki/index.md +0 -183
- package/wiki/references/base/datasources.md +0 -454
- package/wiki/references/base/middlewares.md +0 -590
- package/wiki/references/base/repositories/mixins.md +0 -335
- package/wiki/references/base/services.md +0 -201
- package/wiki/references/utilities/crypto.md +0 -56
- package/wiki/references/utilities/module.md +0 -42
- /package/{wiki → content}/extensions/components/mail/api.md +0 -0
- /package/{wiki → content}/extensions/components/template/api-page.md +0 -0
- /package/{wiki → content}/extensions/components/template/errors-page.md +0 -0
- /package/{wiki → content}/extensions/components/template/single-page.md +0 -0
- /package/{wiki → content}/extensions/components/template/usage-page.md +0 -0
- /package/{wiki → content}/extensions/helpers/kafka/admin.md +0 -0
- /package/{wiki → content}/extensions/helpers/kafka/consumer.md +0 -0
- /package/{wiki → content}/extensions/helpers/kafka/index.md +0 -0
- /package/{wiki → content}/extensions/helpers/kafka/producer.md +0 -0
- /package/{wiki → content}/extensions/helpers/kafka/schema-registry.md +0 -0
- /package/{wiki → content}/extensions/helpers/network/api.md +0 -0
- /package/{wiki → content}/extensions/helpers/socket-io/api.md +0 -0
- /package/{wiki → content}/extensions/helpers/template/single-page.md +0 -0
- /package/{wiki → content}/extensions/helpers/uid/index.md +0 -0
- /package/{wiki → content}/guides/core-concepts/components-guide.md +0 -0
- /package/{wiki → content}/public/logo.svg +0 -0
- /package/{wiki → content}/references/base/filter-system/pattern-matching.md +0 -0
- /package/{wiki → content}/references/base/filter-system/range-operators.md +0 -0
- /package/{wiki → content}/references/utilities/date.md +0 -0
- /package/{wiki → content}/references/utilities/performance.md +0 -0
- /package/{wiki → content}/references/utilities/request.md +0 -0
- /package/{wiki → content}/references/utilities/statuses.md +0 -0
package/wiki/index.md
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
layout: home
|
|
3
|
-
|
|
4
|
-
hero:
|
|
5
|
-
name: IGNIS
|
|
6
|
-
text: Enterprise APIs at Hono Speed
|
|
7
|
-
tagline: "Architecture that scales, performance that flies. Enterprise patterns, raw performance speed, DI Powered."
|
|
8
|
-
image:
|
|
9
|
-
src: /logo.svg
|
|
10
|
-
alt: IGNIS
|
|
11
|
-
actions:
|
|
12
|
-
- theme: brand
|
|
13
|
-
text: Get Started
|
|
14
|
-
link: /guides/get-started/5-minute-quickstart
|
|
15
|
-
- theme: alt
|
|
16
|
-
text: Why Ignis?
|
|
17
|
-
link: /guides/get-started/philosophy
|
|
18
|
-
- theme: alt
|
|
19
|
-
text: GitHub
|
|
20
|
-
link: https://github.com/VENIZIA-AI/ignis
|
|
21
|
-
|
|
22
|
-
features:
|
|
23
|
-
- title: 140k+ req/s
|
|
24
|
-
details: Built on Hono, one of the fastest web frameworks. Near-native performance on Bun, Node, and edge runtimes.
|
|
25
|
-
link: /guides/get-started/philosophy
|
|
26
|
-
linkText: See benchmarks
|
|
27
|
-
|
|
28
|
-
- title: Enterprise Architecture
|
|
29
|
-
details: Layered design with Controllers, Services, and Repositories. Clean separation of concerns out of the box.
|
|
30
|
-
link: /guides/core-concepts/application/
|
|
31
|
-
linkText: Learn more
|
|
32
|
-
|
|
33
|
-
- title: Dependency Injection
|
|
34
|
-
details: Lightweight DI container with decorators. Testable, loosely coupled code without the boilerplate.
|
|
35
|
-
link: /guides/core-concepts/dependency-injection
|
|
36
|
-
linkText: See how
|
|
37
|
-
|
|
38
|
-
- title: Auto-Generated Docs
|
|
39
|
-
details: OpenAPI/Swagger from Zod schemas. Interactive API explorer included with zero config.
|
|
40
|
-
link: /extensions/components/swagger
|
|
41
|
-
linkText: View example
|
|
42
|
-
|
|
43
|
-
- title: Type-Safe Database
|
|
44
|
-
details: Drizzle ORM integration with advanced filtering, relations, JSON queries, and transactions.
|
|
45
|
-
link: /references/base/repositories/
|
|
46
|
-
linkText: Explore
|
|
47
|
-
|
|
48
|
-
- title: Batteries Included
|
|
49
|
-
details: Auth, WebSockets, Queues, Cron, Redis, S3, Email — ready-to-use components and helpers.
|
|
50
|
-
link: /references/
|
|
51
|
-
linkText: Browse all
|
|
52
|
-
---
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
## Quick Start
|
|
57
|
-
|
|
58
|
-
```bash
|
|
59
|
-
# Install dependencies
|
|
60
|
-
bun add hono @hono/zod-openapi @scalar/hono-api-reference @venizia/ignis
|
|
61
|
-
bun add -d typescript @types/bun
|
|
62
|
-
|
|
63
|
-
# Create src/index.ts with your first API
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
```typescript
|
|
67
|
-
import { BaseApplication, BaseRestController, controller, get, jsonContent, SwaggerComponent } from '@venizia/ignis';
|
|
68
|
-
import { HTTP } from '@venizia/ignis-helpers';
|
|
69
|
-
import { z } from '@hono/zod-openapi';
|
|
70
|
-
|
|
71
|
-
// 1. Define your controller
|
|
72
|
-
@controller({ path: '/hello' })
|
|
73
|
-
class HelloController extends BaseRestController {
|
|
74
|
-
constructor() {
|
|
75
|
-
super({ scope: 'HelloController', path: '/hello' });
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
override binding() {} // Required: register additional routes or dependencies here
|
|
79
|
-
|
|
80
|
-
@get({
|
|
81
|
-
configs: {
|
|
82
|
-
path: '/',
|
|
83
|
-
responses: {
|
|
84
|
-
[HTTP.ResultCodes.RS_2.Ok]: jsonContent({
|
|
85
|
-
schema: z.object({ message: z.string() }),
|
|
86
|
-
}),
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
})
|
|
90
|
-
sayHello(c) {
|
|
91
|
-
return c.json({ message: 'Hello from Ignis! 🔥' });
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// 2. Create and configure your application
|
|
96
|
-
class App extends BaseApplication {
|
|
97
|
-
getAppInfo() {
|
|
98
|
-
return { name: 'my-app', version: '1.0.0', description: 'My Ignis App' };
|
|
99
|
-
}
|
|
100
|
-
staticConfigure() {}
|
|
101
|
-
preConfigure() {
|
|
102
|
-
this.component(SwaggerComponent); // API docs at /doc/explorer
|
|
103
|
-
this.controller(HelloController);
|
|
104
|
-
}
|
|
105
|
-
postConfigure() {}
|
|
106
|
-
setupMiddlewares() {}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// 3. Start the server
|
|
110
|
-
const app = new App({
|
|
111
|
-
scope: 'App',
|
|
112
|
-
config: { host: '0.0.0.0', port: 3000, path: { base: '/api' } },
|
|
113
|
-
});
|
|
114
|
-
app.start();
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
```bash
|
|
118
|
-
# Run it
|
|
119
|
-
bun run src/index.ts
|
|
120
|
-
|
|
121
|
-
# Visit http://localhost:3000/api/hello
|
|
122
|
-
# API docs at http://localhost:3000/doc/explorer
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
<div class="tip custom-block" style="padding-top: 8px">
|
|
126
|
-
|
|
127
|
-
Ready for a step-by-step guide? Follow the [5-minute quickstart →](/guides/get-started/5-minute-quickstart)
|
|
128
|
-
|
|
129
|
-
</div>
|
|
130
|
-
|
|
131
|
-
## When to Use Ignis
|
|
132
|
-
|
|
133
|
-
<div class="use-ignis-grid">
|
|
134
|
-
|
|
135
|
-
<div class="use-ignis-card">
|
|
136
|
-
<h3>Perfect For</h3>
|
|
137
|
-
<ul>
|
|
138
|
-
<li><strong>SaaS backends</strong> — Multi-tenant, complex business logic</li>
|
|
139
|
-
<li><strong>E-commerce APIs</strong> — Products, orders, payments</li>
|
|
140
|
-
<li><strong>Enterprise apps</strong> — Teams need clear patterns</li>
|
|
141
|
-
<li><strong>Growing projects</strong> — 10+ endpoints that need structure</li>
|
|
142
|
-
<li><strong>REST APIs</strong> — Full CRUD with validation & docs</li>
|
|
143
|
-
<li><strong>gRPC APIs</strong> — ConnectRPC-based gRPC with decorator support</li>
|
|
144
|
-
<li><strong>Real-time apps</strong> — WebSocket support built-in</li>
|
|
145
|
-
</ul>
|
|
146
|
-
</div>
|
|
147
|
-
|
|
148
|
-
<div class="use-ignis-card">
|
|
149
|
-
<h3>Consider Alternatives</h3>
|
|
150
|
-
<ul>
|
|
151
|
-
<li><strong>Simple webhooks</strong> — Use plain Hono</li>
|
|
152
|
-
<li><strong>3-5 endpoint APIs</strong> — Ignis adds overhead</li>
|
|
153
|
-
<li><strong>Quick prototypes</strong> — Start with Hono first</li>
|
|
154
|
-
<li><strong>Serverless functions</strong> — Hono alone is lighter</li>
|
|
155
|
-
<li><strong>Static sites</strong> — Use Astro or Next.js</li>
|
|
156
|
-
<li><strong>No TypeScript</strong> — Ignis requires TS</li>
|
|
157
|
-
</ul>
|
|
158
|
-
</div>
|
|
159
|
-
|
|
160
|
-
</div>
|
|
161
|
-
|
|
162
|
-
<div style="padding: 3rem 2rem; margin: 2rem 0; border-radius: 16px; background: var(--vp-c-bg-soft); text-align: center;">
|
|
163
|
-
|
|
164
|
-
<p style="font-size: 0.9rem; color: var(--vp-c-text-2); margin-bottom: 1rem; text-transform: uppercase; letter-spacing: 2px;">Powered by</p>
|
|
165
|
-
|
|
166
|
-
<div style="display: flex; justify-content: center; flex-wrap: wrap; gap: 2rem; margin-bottom: 1.5rem;">
|
|
167
|
-
<a href="https://hono.dev" target="_blank" style="font-size: 1.2rem; font-weight: 500;">Hono</a>
|
|
168
|
-
<a href="https://orm.drizzle.team" target="_blank" style="font-size: 1.2rem; font-weight: 500;">Drizzle ORM</a>
|
|
169
|
-
<a href="https://zod.dev" target="_blank" style="font-size: 1.2rem; font-weight: 500;">Zod</a>
|
|
170
|
-
<a href="https://www.typescriptlang.org" target="_blank" style="font-size: 1.2rem; font-weight: 500;">TypeScript</a>
|
|
171
|
-
<a href="https://bun.sh" target="_blank" style="font-size: 1.2rem; font-weight: 500;">Bun</a>
|
|
172
|
-
</div>
|
|
173
|
-
|
|
174
|
-
<hr style="border: none; border-top: 1px solid var(--vp-c-divider); margin: 1.5rem 0;" />
|
|
175
|
-
|
|
176
|
-
<p style="font-size: 0.9rem; color: var(--vp-c-text-2); margin-bottom: 1rem; text-transform: uppercase; letter-spacing: 2px;">Inspired by</p>
|
|
177
|
-
|
|
178
|
-
<div style="display: flex; justify-content: center; flex-wrap: wrap; gap: 2rem;">
|
|
179
|
-
<a href="https://spring.io/projects/spring-boot" target="_blank" style="font-size: 1.2rem; font-weight: 500;">Spring Boot</a>
|
|
180
|
-
<a href="https://loopback.io/doc/en/lb4/" target="_blank" style="font-size: 1.2rem; font-weight: 500;">LoopBack 4</a>
|
|
181
|
-
</div>
|
|
182
|
-
|
|
183
|
-
</div>
|
|
@@ -1,454 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: DataSources Reference
|
|
3
|
-
description: Technical reference for DataSource classes and database connections
|
|
4
|
-
difficulty: intermediate
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Deep Dive: DataSources
|
|
8
|
-
|
|
9
|
-
Technical reference for DataSource classes - managing database connections in Ignis.
|
|
10
|
-
|
|
11
|
-
**Files:** `packages/core/src/base/datasources/*.ts`
|
|
12
|
-
|
|
13
|
-
## Quick Reference
|
|
14
|
-
|
|
15
|
-
| Class/Interface | Purpose | Key Members |
|
|
16
|
-
|-----------------|---------|-------------|
|
|
17
|
-
| **IDataSource** | Contract for all datasources | `name`, `settings`, `connector`, `getSchema()`, `configure()`, `beginTransaction()` |
|
|
18
|
-
| **AbstractDataSource** | Base implementation with logging | Extends `BaseHelper`, declares abstract methods |
|
|
19
|
-
| **BaseDataSource** | Concrete class to extend | Auto-discovery, transaction support, constructor with config |
|
|
20
|
-
| **ITransaction** | Transaction object | `connector`, `isActive`, `isolationLevel`, `commit()`, `rollback()` |
|
|
21
|
-
| **IsolationLevels** | Isolation level constants | `READ_COMMITTED`, `REPEATABLE_READ`, `SERIALIZABLE` |
|
|
22
|
-
|
|
23
|
-
## `IDataSource` Interface
|
|
24
|
-
|
|
25
|
-
Contract for all datasource classes in the framework.
|
|
26
|
-
|
|
27
|
-
**File:** `packages/core/src/base/datasources/common/types.ts`
|
|
28
|
-
|
|
29
|
-
### Type Parameters
|
|
30
|
-
|
|
31
|
-
```typescript
|
|
32
|
-
interface IDataSource<
|
|
33
|
-
Settings extends object = {},
|
|
34
|
-
Schema extends TAnyDataSourceSchema = TAnyDataSourceSchema,
|
|
35
|
-
ConfigurableOptions extends object = {},
|
|
36
|
-
> extends IConfigurable<ConfigurableOptions>
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
| Type Parameter | Default | Description |
|
|
40
|
-
|----------------|---------|-------------|
|
|
41
|
-
| `Settings` | `{}` | Connection configuration type (host, port, etc.) |
|
|
42
|
-
| `Schema` | `TAnyDataSourceSchema` | Combined Drizzle schema type (tables + relations) |
|
|
43
|
-
| `ConfigurableOptions` | `{}` | Options passed to `configure()` |
|
|
44
|
-
|
|
45
|
-
### Properties & Methods
|
|
46
|
-
|
|
47
|
-
| Member | Type | Description |
|
|
48
|
-
|--------|------|-------------|
|
|
49
|
-
| `name` | `string` | Datasource name |
|
|
50
|
-
| `settings` | `Settings` | Configuration object |
|
|
51
|
-
| `connector` | `TNodePostgresConnector<Schema>` | Drizzle ORM connector instance |
|
|
52
|
-
| `schema` | `Schema` | Combined Drizzle schema (auto-discovered or manual) |
|
|
53
|
-
| `getSchema()` | `Schema` | Returns combined Drizzle schema |
|
|
54
|
-
| `getSettings()` | `Settings` | Returns connection settings |
|
|
55
|
-
| `getConnector()` | `TNodePostgresConnector<Schema>` | Returns the Drizzle connector |
|
|
56
|
-
| `getConnectionString()` | `ValueOrPromise<string>` | Returns connection string |
|
|
57
|
-
| `configure(opts?)` | `ValueOrPromise<void>` | Initializes pool and connector |
|
|
58
|
-
| `beginTransaction(opts?)` | `Promise<ITransaction<Schema>>` | Starts a new database transaction |
|
|
59
|
-
|
|
60
|
-
## `AbstractDataSource` & `BaseDataSource`
|
|
61
|
-
|
|
62
|
-
**File:** `packages/core/src/base/datasources/base.ts`
|
|
63
|
-
|
|
64
|
-
### `AbstractDataSource`
|
|
65
|
-
|
|
66
|
-
Top-level abstract class that implements `IDataSource`. Extends `BaseHelper` for scoped logging. Declares the core properties and abstract methods.
|
|
67
|
-
|
|
68
|
-
```typescript
|
|
69
|
-
abstract class AbstractDataSource<
|
|
70
|
-
Settings extends object = {},
|
|
71
|
-
Schema extends TAnyDataSourceSchema = TAnyDataSourceSchema,
|
|
72
|
-
ConfigurableOptions extends object = {},
|
|
73
|
-
> extends BaseHelper implements IDataSource<Settings, Schema, ConfigurableOptions>
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
**Properties:**
|
|
77
|
-
|
|
78
|
-
| Property | Type | Visibility | Description |
|
|
79
|
-
|----------|------|------------|-------------|
|
|
80
|
-
| `name` | `string` | public | Datasource identifier |
|
|
81
|
-
| `settings` | `Settings` | public | Connection configuration |
|
|
82
|
-
| `connector` | `TNodePostgresConnector<Schema>` | public | Drizzle ORM instance |
|
|
83
|
-
| `schema` | `Schema` | public | Combined schema (tables + relations) |
|
|
84
|
-
| `pool` | `Pool` | protected | node-postgres connection pool |
|
|
85
|
-
|
|
86
|
-
**Abstract methods** (must be implemented by subclasses):
|
|
87
|
-
|
|
88
|
-
| Method | Return Type | Description |
|
|
89
|
-
|--------|-------------|-------------|
|
|
90
|
-
| `configure(opts?)` | `ValueOrPromise<void>` | Initialize pool and Drizzle connector |
|
|
91
|
-
| `getConnectionString()` | `ValueOrPromise<string>` | Return the database connection URL |
|
|
92
|
-
| `beginTransaction(opts?)` | `Promise<ITransaction<Schema>>` | Start a new transaction |
|
|
93
|
-
|
|
94
|
-
**Concrete methods:**
|
|
95
|
-
|
|
96
|
-
| Method | Return Type | Description |
|
|
97
|
-
|--------|-------------|-------------|
|
|
98
|
-
| `getSettings()` | `Settings` | Returns `this.settings` |
|
|
99
|
-
| `getConnector()` | `TNodePostgresConnector<Schema>` | Returns `this.connector` |
|
|
100
|
-
| `getSchema()` | `Schema` | Returns `this.schema` (throws if not initialized) |
|
|
101
|
-
|
|
102
|
-
### `BaseDataSource`
|
|
103
|
-
|
|
104
|
-
Extends `AbstractDataSource` with a constructor, **schema auto-discovery**, and a default `beginTransaction()` implementation.
|
|
105
|
-
|
|
106
|
-
```typescript
|
|
107
|
-
abstract class BaseDataSource<
|
|
108
|
-
Settings extends object = {},
|
|
109
|
-
Schema extends TAnyDataSourceSchema = TAnyDataSourceSchema,
|
|
110
|
-
ConfigurableOptions extends object = {},
|
|
111
|
-
> extends AbstractDataSource<Settings, Schema, ConfigurableOptions>
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
#### Key Features
|
|
115
|
-
|
|
116
|
-
| Feature | Description |
|
|
117
|
-
|---------|-------------|
|
|
118
|
-
| **Schema Auto-Discovery** | Schema is automatically built from registered `@repository` decorators |
|
|
119
|
-
| **Manual Override** | You can manually provide schema in constructor for full control |
|
|
120
|
-
| **Built-in Transaction Support** | `beginTransaction()` implemented using the `pool` property |
|
|
121
|
-
|
|
122
|
-
> [!TIP]
|
|
123
|
-
> Set `autoDiscovery` to `false` in the `@datasource` decorator to disable automatic schema discovery. This is useful when you want to manually provide the schema.
|
|
124
|
-
|
|
125
|
-
### Constructor Options
|
|
126
|
-
|
|
127
|
-
```typescript
|
|
128
|
-
constructor(opts: {
|
|
129
|
-
name: string; // DataSource name (usually class name)
|
|
130
|
-
config: Settings; // Database connection settings
|
|
131
|
-
schema?: Schema; // Optional - auto-discovered if not provided
|
|
132
|
-
})
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### Schema Auto-Discovery
|
|
136
|
-
|
|
137
|
-
When you use `@repository({ model: YourModel, dataSource: YourDataSource })`, the framework automatically:
|
|
138
|
-
|
|
139
|
-
1. Registers the model-datasource binding in the MetadataRegistry
|
|
140
|
-
2. When `getSchema()` is called, discovers all models bound to this datasource
|
|
141
|
-
3. Builds the combined schema (tables + relations) automatically
|
|
142
|
-
|
|
143
|
-
**This means you no longer need to manually merge tables and relations in the DataSource constructor!**
|
|
144
|
-
|
|
145
|
-
### Configuration Flow
|
|
146
|
-
|
|
147
|
-
1. **Your DataSource's `constructor` is called**:
|
|
148
|
-
- You call `super()` with `name` and `config`
|
|
149
|
-
- Schema is auto-discovered from `@repository` bindings (or manually provided via `schema`)
|
|
150
|
-
|
|
151
|
-
2. **`Application.registerDataSources()` is called during startup**:
|
|
152
|
-
- The application gets your `DataSource` instance from the DI container
|
|
153
|
-
- It calls the `configure()` method on your instance
|
|
154
|
-
|
|
155
|
-
3. **Your `configure()` method runs**:
|
|
156
|
-
- Call `this.getSchema()` to get the auto-discovered schema
|
|
157
|
-
- Create a `Pool` instance and assign it to `this.pool` (required for transaction support)
|
|
158
|
-
- Create the Drizzle connector with the pool and schema
|
|
159
|
-
|
|
160
|
-
### Example Implementations
|
|
161
|
-
|
|
162
|
-
#### Pattern 1: Auto-Discovery (Recommended)
|
|
163
|
-
|
|
164
|
-
Simplest approach - schema is auto-discovered from repositories:
|
|
165
|
-
|
|
166
|
-
```typescript
|
|
167
|
-
// src/datasources/postgres.datasource.ts
|
|
168
|
-
import { BaseDataSource, datasource, ValueOrPromise } from '@venizia/ignis';
|
|
169
|
-
import { applicationEnvironment, int } from '@venizia/ignis-helpers';
|
|
170
|
-
import { drizzle } from 'drizzle-orm/node-postgres';
|
|
171
|
-
import { Pool } from 'pg';
|
|
172
|
-
|
|
173
|
-
interface IDSConfigs {
|
|
174
|
-
host: string;
|
|
175
|
-
port: number;
|
|
176
|
-
database: string;
|
|
177
|
-
user: string;
|
|
178
|
-
password: string;
|
|
179
|
-
ssl: boolean;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* PostgresDataSource with auto-discovery support.
|
|
184
|
-
*
|
|
185
|
-
* How it works:
|
|
186
|
-
* 1. @repository decorator binds model to datasource
|
|
187
|
-
* 2. When configure() is called, getSchema() auto-discovers all bound models
|
|
188
|
-
* 3. Drizzle is initialized with the auto-discovered schema
|
|
189
|
-
*/
|
|
190
|
-
@datasource({ driver: 'node-postgres' })
|
|
191
|
-
export class PostgresDataSource extends BaseDataSource<IDSConfigs> {
|
|
192
|
-
private readonly protocol = 'postgresql';
|
|
193
|
-
|
|
194
|
-
constructor() {
|
|
195
|
-
super({
|
|
196
|
-
name: PostgresDataSource.name,
|
|
197
|
-
config: {
|
|
198
|
-
host: applicationEnvironment.get<string>('APP_ENV_POSTGRES_HOST'),
|
|
199
|
-
port: int(applicationEnvironment.get<string>('APP_ENV_POSTGRES_PORT')),
|
|
200
|
-
database: applicationEnvironment.get<string>('APP_ENV_POSTGRES_DATABASE'),
|
|
201
|
-
user: applicationEnvironment.get<string>('APP_ENV_POSTGRES_USERNAME'),
|
|
202
|
-
password: applicationEnvironment.get<string>('APP_ENV_POSTGRES_PASSWORD'),
|
|
203
|
-
ssl: false,
|
|
204
|
-
},
|
|
205
|
-
// NO schema property - auto-discovered from @repository bindings!
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
override configure(): ValueOrPromise<void> {
|
|
210
|
-
// getSchema() auto-discovers models from @repository bindings
|
|
211
|
-
const schema = this.getSchema();
|
|
212
|
-
|
|
213
|
-
const dsSchema = Object.keys(schema);
|
|
214
|
-
this.logger.debug(
|
|
215
|
-
'[configure] Auto-discovered schema | Schema + Relations (%s): %o',
|
|
216
|
-
dsSchema.length,
|
|
217
|
-
dsSchema,
|
|
218
|
-
);
|
|
219
|
-
|
|
220
|
-
// Store pool reference for transaction support
|
|
221
|
-
this.pool = new Pool(this.settings);
|
|
222
|
-
this.connector = drizzle({ client: this.pool, schema });
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
override getConnectionString(): ValueOrPromise<string> {
|
|
226
|
-
const { host, port, user, password, database } = this.settings;
|
|
227
|
-
return `${this.protocol}://${user}:${password}@${host}:${port}/${database}`;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
With this pattern, when you define repositories:
|
|
233
|
-
|
|
234
|
-
```typescript
|
|
235
|
-
@repository({ model: User, dataSource: PostgresDataSource })
|
|
236
|
-
export class UserRepository extends DefaultCRUDRepository<typeof User.schema> {}
|
|
237
|
-
|
|
238
|
-
@repository({ model: Configuration, dataSource: PostgresDataSource })
|
|
239
|
-
export class ConfigurationRepository extends DefaultCRUDRepository<typeof Configuration.schema> {}
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
The `PostgresDataSource.schema` will automatically include User and Configuration tables and their relations.
|
|
243
|
-
|
|
244
|
-
#### Pattern 2: Manual Schema (Full Control)
|
|
245
|
-
|
|
246
|
-
When you need explicit control over schema (e.g., subset of models, custom ordering):
|
|
247
|
-
|
|
248
|
-
```typescript
|
|
249
|
-
import {
|
|
250
|
-
User, userTable, userRelations,
|
|
251
|
-
Configuration, configurationTable, configurationRelations,
|
|
252
|
-
} from '@/models/entities';
|
|
253
|
-
|
|
254
|
-
@datasource({ driver: 'node-postgres' })
|
|
255
|
-
export class PostgresDataSource extends BaseDataSource<IDSConfigs> {
|
|
256
|
-
constructor() {
|
|
257
|
-
super({
|
|
258
|
-
name: PostgresDataSource.name,
|
|
259
|
-
config: {
|
|
260
|
-
host: process.env.APP_ENV_POSTGRES_HOST ?? 'localhost',
|
|
261
|
-
port: +(process.env.APP_ENV_POSTGRES_PORT ?? 5432),
|
|
262
|
-
database: process.env.APP_ENV_POSTGRES_DATABASE ?? 'mydb',
|
|
263
|
-
user: process.env.APP_ENV_POSTGRES_USERNAME ?? 'postgres',
|
|
264
|
-
password: process.env.APP_ENV_POSTGRES_PASSWORD ?? '',
|
|
265
|
-
},
|
|
266
|
-
// Manually provide schema using spread syntax
|
|
267
|
-
schema: {
|
|
268
|
-
[User.TABLE_NAME]: userTable,
|
|
269
|
-
[Configuration.TABLE_NAME]: configurationTable,
|
|
270
|
-
...userRelations.relations,
|
|
271
|
-
...configurationRelations.relations,
|
|
272
|
-
},
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
override configure(): ValueOrPromise<void> {
|
|
277
|
-
// When schema is manually provided, getSchema() returns it directly
|
|
278
|
-
this.pool = new Pool(this.settings);
|
|
279
|
-
this.connector = drizzle({ client: this.pool, schema: this.getSchema() });
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
override getConnectionString(): ValueOrPromise<string> {
|
|
283
|
-
// ...
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
> [!IMPORTANT]
|
|
289
|
-
> You must assign `this.pool` in your `configure()` method. The built-in `beginTransaction()` uses `this.pool` to acquire a `PoolClient` for transaction isolation. If `this.pool` is not set, `beginTransaction()` will throw an error.
|
|
290
|
-
|
|
291
|
-
### `@datasource` Decorator
|
|
292
|
-
|
|
293
|
-
The `@datasource` decorator registers datasource metadata:
|
|
294
|
-
|
|
295
|
-
```typescript
|
|
296
|
-
@datasource({
|
|
297
|
-
driver: 'node-postgres', // Required - database driver
|
|
298
|
-
autoDiscovery?: true // Optional - defaults to true
|
|
299
|
-
})
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
| Option | Type | Default | Description |
|
|
303
|
-
|--------|------|---------|-------------|
|
|
304
|
-
| `driver` | `TDataSourceDriver` | - | Database driver name (currently only `'node-postgres'`) |
|
|
305
|
-
| `autoDiscovery` | `boolean` | `true` | Enable/disable schema auto-discovery |
|
|
306
|
-
|
|
307
|
-
### Abstract Methods
|
|
308
|
-
|
|
309
|
-
When extending `BaseDataSource`, these methods must be implemented:
|
|
310
|
-
|
|
311
|
-
| Method | Return Type | Description |
|
|
312
|
-
|--------|-------------|-------------|
|
|
313
|
-
| `configure(opts?)` | `ValueOrPromise<void>` | Initialize pool and Drizzle connector. Must set `this.pool` and `this.connector`. |
|
|
314
|
-
| `getConnectionString()` | `ValueOrPromise<string>` | Return the database connection string. |
|
|
315
|
-
|
|
316
|
-
### Helper Methods
|
|
317
|
-
|
|
318
|
-
| Method | Description |
|
|
319
|
-
|--------|-------------|
|
|
320
|
-
| `getSchema()` | Returns the schema (auto-discovers via `discoverSchema()` if not manually provided) |
|
|
321
|
-
| `getSettings()` | Returns connection settings |
|
|
322
|
-
| `getConnector()` | Returns the Drizzle connector |
|
|
323
|
-
| `hasDiscoverableModels()` | Returns `true` if there are models registered for this datasource via `@repository` |
|
|
324
|
-
|
|
325
|
-
### Protected Methods
|
|
326
|
-
|
|
327
|
-
| Method | Description |
|
|
328
|
-
|--------|-------------|
|
|
329
|
-
| `discoverSchema()` | Queries the `MetadataRegistry` for all `@repository` bindings targeting this datasource, then calls `registry.buildSchema()` to merge tables and relations into a single schema object. |
|
|
330
|
-
|
|
331
|
-
## Connector Types
|
|
332
|
-
|
|
333
|
-
**File:** `packages/core/src/base/datasources/common/types.ts`
|
|
334
|
-
|
|
335
|
-
| Type | Description |
|
|
336
|
-
|------|-------------|
|
|
337
|
-
| `TNodePostgresConnector<Schema>` | Drizzle connector using `NodePgClient` (Pool or PoolClient) |
|
|
338
|
-
| `TNodePostgresTransactionConnector<Schema>` | Drizzle connector using `PoolClient` specifically (for transaction isolation) |
|
|
339
|
-
| `TAnyConnector<Schema>` | Union of both connector types |
|
|
340
|
-
| `TAnyDataSourceSchema` | `Record<string, any>` — base type for all schema objects |
|
|
341
|
-
|
|
342
|
-
### `DataSourceDrivers`
|
|
343
|
-
|
|
344
|
-
Static class for driver validation:
|
|
345
|
-
|
|
346
|
-
```typescript
|
|
347
|
-
DataSourceDrivers.NODE_POSTGRES // 'node-postgres'
|
|
348
|
-
DataSourceDrivers.isValid('node-postgres') // true
|
|
349
|
-
```
|
|
350
|
-
|
|
351
|
-
## Transaction Support
|
|
352
|
-
|
|
353
|
-
DataSources provide built-in transaction management through the `beginTransaction()` method. This allows you to perform atomic operations across multiple repositories.
|
|
354
|
-
|
|
355
|
-
### How It Works
|
|
356
|
-
|
|
357
|
-
`BaseDataSource.beginTransaction()` does the following:
|
|
358
|
-
|
|
359
|
-
1. Acquires a `PoolClient` from `this.pool`
|
|
360
|
-
2. Executes `BEGIN TRANSACTION ISOLATION LEVEL <level>` on the client
|
|
361
|
-
3. Creates a separate Drizzle connector scoped to that client
|
|
362
|
-
4. Returns an `ITransaction` object with `commit()`, `rollback()`, and the scoped `connector`
|
|
363
|
-
|
|
364
|
-
When `commit()` or `rollback()` is called, the client is released back to the pool.
|
|
365
|
-
|
|
366
|
-
### Transaction Types
|
|
367
|
-
|
|
368
|
-
| Type | Description |
|
|
369
|
-
|------|-------------|
|
|
370
|
-
| `ITransaction<Schema>` | Transaction object with `commit()`, `rollback()`, and `connector` |
|
|
371
|
-
| `ITransactionOptions` | Options for starting a transaction (e.g., `isolationLevel`) |
|
|
372
|
-
| `TIsolationLevel` | Union type: `'READ COMMITTED'` \| `'REPEATABLE READ'` \| `'SERIALIZABLE'` |
|
|
373
|
-
| `IsolationLevels` | Static class with isolation level constants and validation |
|
|
374
|
-
|
|
375
|
-
### ITransaction Interface
|
|
376
|
-
|
|
377
|
-
```typescript
|
|
378
|
-
interface ITransaction<Schema> {
|
|
379
|
-
connector: TNodePostgresTransactionConnector<Schema>;
|
|
380
|
-
isActive: boolean; // read-only getter, false after commit/rollback
|
|
381
|
-
isolationLevel: TIsolationLevel;
|
|
382
|
-
|
|
383
|
-
commit(): Promise<void>;
|
|
384
|
-
rollback(): Promise<void>;
|
|
385
|
-
}
|
|
386
|
-
```
|
|
387
|
-
|
|
388
|
-
### Isolation Levels
|
|
389
|
-
|
|
390
|
-
Use the `IsolationLevels` static class for type-safe isolation level constants:
|
|
391
|
-
|
|
392
|
-
```typescript
|
|
393
|
-
import { IsolationLevels } from '@venizia/ignis';
|
|
394
|
-
|
|
395
|
-
// Available levels
|
|
396
|
-
IsolationLevels.READ_COMMITTED // Default - prevents dirty reads
|
|
397
|
-
IsolationLevels.REPEATABLE_READ // Consistent reads within transaction
|
|
398
|
-
IsolationLevels.SERIALIZABLE // Strictest isolation
|
|
399
|
-
|
|
400
|
-
// Validation
|
|
401
|
-
IsolationLevels.isValid('READ COMMITTED'); // true
|
|
402
|
-
IsolationLevels.isValid('INVALID'); // false
|
|
403
|
-
```
|
|
404
|
-
|
|
405
|
-
> [!NOTE]
|
|
406
|
-
> The default isolation level is `READ COMMITTED` when no `isolationLevel` option is provided.
|
|
407
|
-
|
|
408
|
-
### Usage Example
|
|
409
|
-
|
|
410
|
-
```typescript
|
|
411
|
-
// Start transaction from datasource or repository
|
|
412
|
-
const tx = await dataSource.beginTransaction({
|
|
413
|
-
isolationLevel: IsolationLevels.SERIALIZABLE
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
try {
|
|
417
|
-
// Use tx.connector for operations
|
|
418
|
-
await tx.connector.insert(userTable).values({ name: 'Alice' });
|
|
419
|
-
await tx.connector.insert(profileTable).values({ userId: '...', bio: 'Hello' });
|
|
420
|
-
|
|
421
|
-
await tx.commit();
|
|
422
|
-
} catch (error) {
|
|
423
|
-
await tx.rollback();
|
|
424
|
-
throw error;
|
|
425
|
-
}
|
|
426
|
-
```
|
|
427
|
-
|
|
428
|
-
> **Note:** For most use cases, prefer using `repository.beginTransaction()` which provides a higher-level API. See [Repositories Reference](./repositories/#transactions) for details.
|
|
429
|
-
|
|
430
|
-
This architecture ensures that datasources are configured consistently and that the fully-initialized Drizzle connector, aware of all schemas and relations, is available to repositories for querying.
|
|
431
|
-
|
|
432
|
-
## See Also
|
|
433
|
-
|
|
434
|
-
- **Related Concepts:**
|
|
435
|
-
- [DataSources Guide](/guides/core-concepts/persistent/datasources) - Creating DataSources tutorial
|
|
436
|
-
- [Repositories](/guides/core-concepts/persistent/repositories) - Using DataSources for database access
|
|
437
|
-
- [Models](/guides/core-concepts/persistent/models) - Entity schemas loaded by DataSource
|
|
438
|
-
- [Transactions](/guides/core-concepts/persistent/transactions) - Multi-operation database transactions
|
|
439
|
-
|
|
440
|
-
- **References:**
|
|
441
|
-
- [Repositories API](/references/base/repositories/) - Data access layer
|
|
442
|
-
- [Environment Variables](/references/configuration/environment-variables) - Configuration management
|
|
443
|
-
|
|
444
|
-
- **External Resources:**
|
|
445
|
-
- [Drizzle ORM Documentation](https://orm.drizzle.team/) - ORM configuration
|
|
446
|
-
- [node-postgres Documentation](https://node-postgres.com/) - Connection pooling guide
|
|
447
|
-
|
|
448
|
-
- **Best Practices:**
|
|
449
|
-
- [Performance Optimization](/best-practices/performance-optimization) - Connection pool tuning
|
|
450
|
-
- [Security Guidelines](/best-practices/security-guidelines) - Database credential management
|
|
451
|
-
|
|
452
|
-
- **Tutorials:**
|
|
453
|
-
- [Complete Installation](/guides/tutorials/complete-installation) - Database setup
|
|
454
|
-
- [Building a CRUD API](/guides/tutorials/building-a-crud-api) - DataSource configuration
|