@@ -2,10 +2,16 @@ import assert from 'node:assert';
22import test , { beforeEach } from 'node:test' ;
33import pgvector from 'pgvector' ;
44import { SparseVector } from 'pgvector' ;
5- import { PrismaClient } from '@prisma/client' ;
5+ import { PrismaClient } from '../prisma/generated/client.mts' ;
6+ import { PrismaPg } from '@prisma/adapter-pg' ;
7+
8+ function prismaClient ( ) {
9+ const adapter = new PrismaPg ( { connectionString : 'postgresql://runner@localhost/pgvector_node_test' } ) ;
10+ return new PrismaClient ( { adapter : adapter } ) ;
11+ }
612
713test ( 'vector' , async ( ) => {
8- const prisma = new PrismaClient ( ) ;
14+ const prisma = prismaClient ( ) ;
915
1016 // TODO use create when possible (field is not available in the generated client)
1117 // https://www.prisma.io/docs/concepts/components/prisma-schema/features-without-psl-equivalent#unsupported-field-types
@@ -21,10 +27,12 @@ test('vector', async () => {
2127 assert . deepEqual ( pgvector . fromSql ( items [ 0 ] . embedding ) , [ 1 , 1 , 1 ] ) ;
2228 assert . deepEqual ( pgvector . fromSql ( items [ 1 ] . embedding ) , [ 1 , 1 , 2 ] ) ;
2329 assert . deepEqual ( pgvector . fromSql ( items [ 2 ] . embedding ) , [ 2 , 2 , 2 ] ) ;
30+
31+ await prisma . $disconnect ( ) ;
2432} ) ;
2533
2634test ( 'halfvec' , async ( ) => {
27- const prisma = new PrismaClient ( ) ;
35+ const prisma = prismaClient ( ) ;
2836
2937 // TODO use create when possible (field is not available in the generated client)
3038 // https://www.prisma.io/docs/concepts/components/prisma-schema/features-without-psl-equivalent#unsupported-field-types
@@ -40,10 +48,12 @@ test('halfvec', async () => {
4048 assert . deepEqual ( pgvector . fromSql ( items [ 0 ] . half_embedding ) , [ 1 , 1 , 1 ] ) ;
4149 assert . deepEqual ( pgvector . fromSql ( items [ 1 ] . half_embedding ) , [ 1 , 1 , 2 ] ) ;
4250 assert . deepEqual ( pgvector . fromSql ( items [ 2 ] . half_embedding ) , [ 2 , 2 , 2 ] ) ;
51+
52+ await prisma . $disconnect ( ) ;
4353} ) ;
4454
4555test ( 'bit' , async ( ) => {
46- const prisma = new PrismaClient ( ) ;
56+ const prisma = prismaClient ( ) ;
4757
4858 await prisma . item . createMany ( {
4959 data : [
@@ -60,10 +70,12 @@ test('bit', async () => {
6070 assert . equal ( items [ 0 ] . binary_embedding , '101' ) ;
6171 assert . equal ( items [ 1 ] . binary_embedding , '111' ) ;
6272 assert . equal ( items [ 2 ] . binary_embedding , '000' ) ;
73+
74+ await prisma . $disconnect ( ) ;
6375} ) ;
6476
6577test ( 'sparsevec' , async ( ) => {
66- const prisma = new PrismaClient ( ) ;
78+ const prisma = prismaClient ( ) ;
6779
6880 // TODO use create when possible (field is not available in the generated client)
6981 // https://www.prisma.io/docs/concepts/components/prisma-schema/features-without-psl-equivalent#unsupported-field-types
@@ -79,9 +91,12 @@ test('sparsevec', async () => {
7991 assert . deepEqual ( pgvector . fromSql ( items [ 0 ] . sparse_embedding ) . toArray ( ) , [ 1 , 1 , 1 ] ) ;
8092 assert . deepEqual ( pgvector . fromSql ( items [ 1 ] . sparse_embedding ) . toArray ( ) , [ 1 , 1 , 2 ] ) ;
8193 assert . deepEqual ( pgvector . fromSql ( items [ 2 ] . sparse_embedding ) . toArray ( ) , [ 2 , 2 , 2 ] ) ;
94+
95+ await prisma . $disconnect ( ) ;
8296} ) ;
8397
8498beforeEach ( async ( ) => {
85- const prisma = new PrismaClient ( ) ;
99+ const prisma = prismaClient ( ) ;
86100 await prisma . item . deleteMany ( { } ) ;
101+ await prisma . $disconnect ( ) ;
87102} ) ;
0 commit comments