Skip to content

Commit bfac141

Browse files
committed
docs: add README
1 parent 91ca3f2 commit bfac141

1 file changed

Lines changed: 122 additions & 0 deletions

File tree

README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# @backendworks/post-db
2+
3+
[![Release](https://github.com/BackendWorks/post-db/actions/workflows/release.yml/badge.svg)](https://github.com/BackendWorks/post-db/actions/workflows/release.yml)
4+
[![npm](https://img.shields.io/badge/npm-GitHub%20Packages-blue)](https://github.com/BackendWorks/post-db/packages)
5+
6+
ORM-agnostic database package for the post domain. Exposes a repository interface (`IPostRepository`) backed by Prisma internally. Apps and workers import only the interface — never `PrismaClient` directly — so the underlying ORM can be swapped without touching any service.
7+
8+
## Schema
9+
10+
```prisma
11+
model Post {
12+
id String @id @default(uuid())
13+
title String
14+
content String
15+
images String[]
16+
createdBy String @map("created_by") @db.Uuid
17+
updatedBy String? @map("updated_by") @db.Uuid
18+
deletedBy String? @map("deleted_by") @db.Uuid
19+
createdAt DateTime @default(now())
20+
updatedAt DateTime @updatedAt
21+
deletedAt DateTime?
22+
isDeleted Boolean @default(false)
23+
}
24+
```
25+
26+
`createdBy`, `updatedBy`, `deletedBy` store user UUIDs. The actual user data is fetched from `auth-service` by `post-service`'s `PostMappingService`.
27+
28+
## Installation
29+
30+
```bash
31+
# Requires GitHub Packages auth — ensure ~/.npmrc contains:
32+
# @backendworks:registry=https://npm.pkg.github.com
33+
# //npm.pkg.github.com/:_authToken=YOUR_GITHUB_PAT
34+
35+
npm install @backendworks/post-db
36+
```
37+
38+
## Usage
39+
40+
```typescript
41+
import { createPostDbManager, IPostDbManager, IPostRepository } from '@backendworks/post-db';
42+
43+
// In your NestJS module
44+
const dbManager: IPostDbManager = createPostDbManager(process.env.DATABASE_URL);
45+
const postRepository: IPostRepository = dbManager.postRepository;
46+
47+
// Use the repository
48+
const post = await postRepository.findById('uuid-here');
49+
const posts = await postRepository.findMany({ page: 1, limit: 10, search: 'nestjs' });
50+
```
51+
52+
## Public API
53+
54+
```typescript
55+
// Factory
56+
createPostDbManager(databaseUrl: string): IPostDbManager
57+
resetPostDbManager(): void
58+
59+
// Interfaces (type-only imports)
60+
IPostDbManager
61+
IPostRepository
62+
CreatePostInput
63+
UpdatePostInput
64+
Post
65+
PaginatedResult<T>
66+
QueryOptions
67+
```
68+
69+
## Repository Interface
70+
71+
`IPostRepository` extends base operations:
72+
73+
| Method | Description |
74+
|---|---|
75+
| `findById(id)` | Find post by UUID |
76+
| `findOne(filter)` | Find single post by filter |
77+
| `findMany(options)` | Paginated post list with search/filter |
78+
| `create(input)` | Create new post |
79+
| `update(id, input)` | Update post fields |
80+
| `softDelete(id, deletedBy)` | Set `deletedAt` and `isDeleted = true` |
81+
82+
All `findMany` queries automatically filter `deletedAt: null` and `isDeleted: false`.
83+
84+
## Database Migrations
85+
86+
Migrations are owned by this package. **Never add a `schema.prisma` in your app.**
87+
88+
```bash
89+
npm run prisma:migrate # prisma migrate dev
90+
npm run prisma:generate # regenerate Prisma client
91+
npm run prisma:studio # open Prisma Studio
92+
```
93+
94+
## Versioning
95+
96+
| Change | Version bump |
97+
|---|---|
98+
| Schema change | Minor |
99+
| Breaking interface change | Major |
100+
| Bug fix / non-breaking | Patch |
101+
102+
Apps and their paired worker must always pin to the **same version range**.
103+
104+
## Publishing
105+
106+
Releases are triggered via `workflow_dispatch` on the GitHub Actions release workflow. The package is published to GitHub Packages under `@backendworks`.
107+
108+
## Scripts
109+
110+
```bash
111+
npm run build # tsc → dist/
112+
npm run lint # ESLint --fix
113+
npm run format # Prettier --write
114+
npm test # Unit tests (100% coverage enforced)
115+
npm run version:patch # Bump patch version
116+
npm run version:minor # Bump minor version
117+
npm run version:major # Bump major version
118+
```
119+
120+
## License
121+
122+
[MIT](LICENSE)

0 commit comments

Comments
 (0)