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 1
1
import type { OutboxAccumulator , OutboxEntry } from '@message-queue-toolkit/outbox-core'
2
2
import type { OutboxStorage } from '@message-queue-toolkit/outbox-core/dist/lib/storage'
3
3
import type { CommonEventDefinition } from '@message-queue-toolkit/schemas'
4
+ import type { PrismaClient } from '@prisma/client'
4
5
5
6
export class OutboxPrismaAdapter < SupportedEvents extends CommonEventDefinition [ ] >
6
7
implements OutboxStorage < SupportedEvents >
7
8
{
9
+ constructor (
10
+ private readonly prisma : PrismaClient ,
11
+ private readonly modelName : string ,
12
+ ) { }
13
+
8
14
createEntry (
9
15
outboxEntry : OutboxEntry < SupportedEvents [ number ] > ,
10
16
) : 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
+ } )
12
22
}
13
23
14
24
flush ( outboxAccumulator : OutboxAccumulator < SupportedEvents > ) : Promise < void > {
Original file line number Diff line number Diff line change 24
24
"docker:stop:dev" : " docker compose down" ,
25
25
"prepublishOnly" : " npm run build:release"
26
26
},
27
- "dependencies" : {},
28
27
"peerDependencies" : {
29
28
"@message-queue-toolkit/core" : " >=14.0.0" ,
29
+ "@message-queue-toolkit/outbox-core" : " >=0.1.0" ,
30
30
"@message-queue-toolkit/schemas" : " >=4.0.0" ,
31
- "@message-queue-toolkit/outbox-core " : " >=0.1.0 "
31
+ "@prisma/client " : " ^5.19.1 "
32
32
},
33
33
"devDependencies" : {
34
34
"@biomejs/biome" : " 1.8.3" ,
35
35
"@kibertoad/biome-config" : " ^1.2.1" ,
36
36
"@types/node" : " ^22.0.0" ,
37
37
"@vitest/coverage-v8" : " ^2.0.4" ,
38
38
"del-cli" : " ^5.1.0" ,
39
+ "prisma" : " ^5.19.1" ,
39
40
"typescript" : " ^5.5.3" ,
40
41
"vitest" : " ^2.0.4" ,
41
42
"zod" : " ^3.23.8"
56
57
" outbox" ,
57
58
" pattern"
58
59
],
59
- "files" : [" README.md" , " LICENSE" , " dist/*" ]
60
+ "files" : [
61
+ " README.md" ,
62
+ " LICENSE" ,
63
+ " dist/*"
64
+ ]
60
65
}
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