Skip to content

Commit 14ae996

Browse files
committed
Updated Prisma examples and tests
1 parent 6a7344f commit 14ae996

File tree

7 files changed

+45
-12
lines changed

7 files changed

+45
-12
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ jobs:
1818
1919
# Node.js
2020
- uses: actions/setup-node@v4
21+
with:
22+
node-version: 24
2123
- run: npm install
24+
- run: npx prisma generate
2225
- run: npx prisma migrate dev
2326
- run: npm test
2427

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules/
2+
prisma/generated/
23
package-lock.json
34
pnpm-lock.yaml
45
bun.lock

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,12 @@ Add the extension to the schema
405405

406406
```prisma
407407
generator client {
408-
provider = "prisma-client-js"
408+
provider = "prisma-client"
409409
previewFeatures = ["postgresqlExtensions"]
410410
}
411411
412412
datasource db {
413413
provider = "postgresql"
414-
url = env("DATABASE_URL")
415414
extensions = [vector]
416415
}
417416
```
@@ -798,6 +797,7 @@ git clone https://github.com/pgvector/pgvector-node.git
798797
cd pgvector-node
799798
npm install
800799
createdb pgvector_node_test
800+
npx prisma generate
801801
npx prisma migrate dev
802802
npm test
803803
```

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,16 @@
9595
"devDependencies": {
9696
"@mikro-orm/core": "^6.1.1",
9797
"@mikro-orm/postgresql": "^6.1.1",
98-
"@prisma/client": "^6.2.1",
98+
"@prisma/adapter-pg": "^7.1.0",
99+
"@prisma/client": "^7.1.0",
99100
"drizzle-orm": "^0.45.0",
100101
"knex": "^3.1.0",
101102
"kysely": "^0.28.2",
102103
"objection": "^3.1.3",
103104
"pg": "^8.6.0",
104105
"pg-promise": "^12.3.0",
105106
"postgres": "^3.3.4",
106-
"prisma": "^6.2.1",
107+
"prisma": "^7.1.0",
107108
"sequelize": "^6.6.2",
108109
"slonik": "^48.8.7",
109110
"typeorm": "^0.3.17",

prisma.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineConfig, env } from 'prisma/config';
2+
3+
export default defineConfig({
4+
schema: 'prisma/schema.prisma',
5+
migrations: {
6+
path: 'prisma/migrations',
7+
},
8+
datasource: {
9+
url: 'postgresql://runner@localhost/pgvector_node_test',
10+
},
11+
});

prisma/schema.prisma

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
// learn more about it in the docs: https://pris.ly/d/prisma-schema
33

44
generator client {
5-
provider = "prisma-client-js"
5+
provider = "prisma-client"
6+
output = "./generated"
7+
generatedFileExtension = "mts"
8+
importFileExtension = "mts"
69
previewFeatures = ["postgresqlExtensions"]
710
}
811

912
datasource db {
1013
provider = "postgresql"
11-
url = "postgresql://runner@localhost/pgvector_node_test"
1214
extensions = [vector]
1315
}
1416

tests/prisma.test.mjs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@ import assert from 'node:assert';
22
import test, { beforeEach } from 'node:test';
33
import pgvector from 'pgvector';
44
import { 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

713
test('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

2634
test('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

4555
test('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

6577
test('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

8498
beforeEach(async () => {
85-
const prisma = new PrismaClient();
99+
const prisma = prismaClient();
86100
await prisma.item.deleteMany({});
101+
await prisma.$disconnect();
87102
});

0 commit comments

Comments
 (0)