File tree Expand file tree Collapse file tree 5 files changed +70
-4
lines changed
packages/outbox-prisma-adapter Expand file tree Collapse file tree 5 files changed +70
-4
lines changed Original file line number Diff line number Diff line change 1+ services :
2+
3+ postgres :
4+ image : postgres:16.2
5+ environment :
6+ POSTGRES_USER : prisma
7+ POSTGRES_PASSWORD : prisma
8+ POSTGRES_DB : prisma
9+ ports :
10+ - 5432:5432
Original file line number Diff line number Diff line change 1+ import { PrismaClient } from '@prisma/client'
2+ import { beforeAll , describe , it } from 'vitest'
3+
4+ describe ( 'outbox-prisma-adapter' , ( ) => {
5+ let prisma : PrismaClient
6+
7+ beforeAll ( async ( ) => {
8+ prisma = new PrismaClient ( )
9+
10+ await prisma . $queryRaw `
11+ CREATE TABLE prisma.outbox_entry (id UUID PRIMARY KEY, created TIMESTAMP NOT NULL)`
12+ } )
13+
14+ it ( 'created outbox entry' , async ( ) => {
15+ const result = await prisma . $queryRaw `SELECT 1 as counter;`
16+
17+ console . log ( result )
18+
19+ await prisma . outboxEntry . create ( {
20+ data : {
21+ id : 'ce08b43b-6162-4913-86ea-fa9367875e3b' ,
22+ created : new Date ( ) ,
23+ } ,
24+ } )
25+ } )
26+ } )
Original file line number Diff line number Diff line change 11import type { OutboxAccumulator , OutboxEntry } from '@message-queue-toolkit/outbox-core'
22import type { OutboxStorage } from '@message-queue-toolkit/outbox-core/dist/lib/storage'
33import type { CommonEventDefinition } from '@message-queue-toolkit/schemas'
4+ import type { PrismaClient } from '@prisma/client'
45
56export class OutboxPrismaAdapter < SupportedEvents extends CommonEventDefinition [ ] >
67 implements OutboxStorage < SupportedEvents >
78{
9+ constructor (
10+ private readonly prisma : PrismaClient ,
11+ private readonly modelName : string ,
12+ ) { }
13+
814 createEntry (
915 outboxEntry : OutboxEntry < SupportedEvents [ number ] > ,
1016 ) : Promise < OutboxEntry < SupportedEvents [ number ] > > {
11- return Promise . resolve ( undefined )
17+ const prismaModel : PrismaClient [ typeof this . modelName ] = this . prisma [ this . modelName ]
18+
19+ return prismaModel . create ( {
20+ data : outboxEntry ,
21+ } )
1222 }
1323
1424 flush ( outboxAccumulator : OutboxAccumulator < SupportedEvents > ) : Promise < void > {
Original file line number Diff line number Diff line change 2424 "docker:stop:dev" : " docker compose down" ,
2525 "prepublishOnly" : " npm run build:release"
2626 },
27- "dependencies" : {},
2827 "peerDependencies" : {
2928 "@message-queue-toolkit/core" : " >=14.0.0" ,
29+ "@message-queue-toolkit/outbox-core" : " >=0.1.0" ,
3030 "@message-queue-toolkit/schemas" : " >=4.0.0" ,
31- "@message-queue-toolkit/outbox-core " : " >=0.1.0 "
31+ "@prisma/client " : " ^5.19.1 "
3232 },
3333 "devDependencies" : {
3434 "@biomejs/biome" : " 1.8.3" ,
3535 "@kibertoad/biome-config" : " ^1.2.1" ,
3636 "@types/node" : " ^22.0.0" ,
3737 "@vitest/coverage-v8" : " ^2.0.4" ,
3838 "del-cli" : " ^5.1.0" ,
39+ "prisma" : " ^5.19.1" ,
3940 "typescript" : " ^5.5.3" ,
4041 "vitest" : " ^2.0.4" ,
4142 "zod" : " ^3.23.8"
5657 " outbox" ,
5758 " pattern"
5859 ],
59- "files" : [" README.md" , " LICENSE" , " dist/*" ]
60+ "files" : [
61+ " README.md" ,
62+ " LICENSE" ,
63+ " dist/*"
64+ ]
6065}
Original file line number Diff line number Diff line change 1+ datasource db {
2+ provider = " postgresql "
3+ url = " postgresql://prisma:prisma@localhost:5432/prisma?schema=testdb "
4+ }
5+
6+ model OutboxEntry {
7+ id String @id @default (uuid () ) @db.Uuid
8+ created DateTime @default (now () )
9+
10+ @@map (" outbox_entry " )
11+ }
12+
13+ generator client {
14+ provider = " prisma-client-js "
15+ }
You can’t perform that action at this time.
0 commit comments