@kanjijs/store 0.2.0-beta.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 +57 -0
- package/dist/index.js +6219 -0
- package/package.json +23 -0
package/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# @kanjijs/store
|
|
2
|
+
|
|
3
|
+
Database integration module for Kanjijs Framework.
|
|
4
|
+
|
|
5
|
+
Currently supports **Postgres** (via `postgres.js` driver) and integrates seamlessly with **Drizzle ORM**.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun add @kanjijs/store drizzle-orm postgres
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### 1. Register the Module
|
|
16
|
+
Import `StoreModule` in your root `AppModule`.
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
// app.module.ts
|
|
20
|
+
import { Module } from "@kanjijs/core";
|
|
21
|
+
import { StoreModule } from "@kanjijs/store";
|
|
22
|
+
import * as schema from "./db/schema"; // Drizzle Schema
|
|
23
|
+
|
|
24
|
+
@Module({
|
|
25
|
+
imports: [
|
|
26
|
+
StoreModule.forRoot({
|
|
27
|
+
url: process.env.DATABASE_URL!,
|
|
28
|
+
schema: schema
|
|
29
|
+
})
|
|
30
|
+
]
|
|
31
|
+
})
|
|
32
|
+
export class AppModule {}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 2. Inject the Database Client
|
|
36
|
+
Use the `@InjectDb()` decorator to inject the Drizzle client into your services.
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
// users.service.ts
|
|
40
|
+
import { Injectable } from "@kanjijs/core";
|
|
41
|
+
import { InjectDb, type DrizzleDb } from "@kanjijs/store";
|
|
42
|
+
import { users } from "./db/schema";
|
|
43
|
+
|
|
44
|
+
@Injectable()
|
|
45
|
+
export class UserService {
|
|
46
|
+
constructor(@InjectDb() private db: DrizzleDb) {}
|
|
47
|
+
|
|
48
|
+
async findAll() {
|
|
49
|
+
// Full Type-Safety & Auto-Completion
|
|
50
|
+
return await this.db.select().from(users);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Extensibility
|
|
56
|
+
|
|
57
|
+
While this package defaults to Postgres/Drizzle, the dependency injection pattern (`DATABASE_CLIENT` token) allows you to swap this for other providers (e.g., Mongo, SQLite) by implementing your own dynamic module if needed.
|