Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions orm/postgis-express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
"version": "1.0.0",
"license": "MIT",
"scripts": {
"dev": "ts-node src/index.ts",
"dev": "tsx src/index.ts",
"test": "jest"
},
"dependencies": {
"@prisma/client": "6.9.0",
"@prisma/client": "^6.18.0",
"@prisma/extension-accelerate": "^2.0.2",
"@types/node": "22.15.32",
"dotenv": "^16.4.7",
"express": "5.1.0"
},
"devDependencies": {
Expand All @@ -19,11 +21,11 @@
"@types/supertest": "6.0.3",
"jest": "29.7.0",
"jest-environment-node": "29.7.0",
"prisma": "6.9.0",
"prisma": "^6.18.0",
"randomstring": "1.3.1",
"supertest": "7.1.1",
"ts-jest": "29.4.5",
"ts-node": "10.9.2",
"tsx": "^4.20.6",
"typescript": "5.8.2"
}
}
4 changes: 3 additions & 1 deletion orm/postgis-express/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
generator client {
provider = "prisma-client-js"
provider = "prisma-client"
output = "./generated"
engineType = "client"
}

datasource db {
Expand Down
2 changes: 1 addition & 1 deletion orm/postgis-express/prisma/test-environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const NodeEnvironment = require('jest-environment-node').default
const randomString = require('randomstring')
const util = require('util')
const exec = util.promisify(require('child_process').exec)
const { PrismaClient } = require('@prisma/client')
const { PrismaClient } = require('./generated/client')

class PrismaTestEnvironment extends NodeEnvironment {
constructor(config) {
Expand Down
10 changes: 6 additions & 4 deletions orm/postgis-express/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { PrismaClient } from '@prisma/client'
import 'dotenv/config'
import { PrismaClient } from '../prisma/generated/client'
import express from 'express'
import { withAccelerate } from '@prisma/extension-accelerate'

export const prisma = new PrismaClient()
export const prisma = new PrismaClient().$extends(withAccelerate())
const app = express()

app.use(express.json())
Expand Down Expand Up @@ -53,8 +55,8 @@ app.get(`/:userId/nearby-places`, async (req, res) => {
try {
const locations = await prisma.$queryRaw`
select * from "locations_near_user"(${parseInt(
userId,
)}::int, ${distance}::int)
userId,
)}::int, ${distance}::int)
`
res.json({ data: { locations } })
} catch (e) {
Expand Down
6 changes: 4 additions & 2 deletions orm/prisma-mocking-javascript/client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { PrismaClient } = require('@prisma/client')
const { PrismaClient } = require('./prisma/generated/client')
const { PrismaBetterSQLite3 } = require('@prisma/adapter-better-sqlite3')

const prisma = new PrismaClient()
const adapter = new PrismaBetterSQLite3({ url: process.env.DATABASE_URL })
const prisma = new PrismaClient({ adapter });

module.exports = {
prisma,
Expand Down
9 changes: 5 additions & 4 deletions orm/prisma-mocking-javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
"license": "MIT",
"scripts": {
"test": "jest",
"dev": "node ./script.js"
"dev": "node ./client.js"
},
"dependencies": {
"@prisma/client": "6.9.0"
"@prisma/adapter-better-sqlite3": "^6.17.1",
"@prisma/client": "^6.17.1"
},
"devDependencies": {
"jest-mock-extended": "3.0.7",
"prisma": "6.9.0"
"prisma": "^6.17.1"
}
}
}
14 changes: 8 additions & 6 deletions orm/prisma-mocking-javascript/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
generator client {
provider = "prisma-client-js"
provider = "prisma-client"
output = "./generated"
engineType = "client"
}

datasource db {
Expand All @@ -16,9 +18,9 @@ model User {
}

model Post {
id Int @id @default(autoincrement())
title String
content String
author User @relation(fields: [authorId], references: [id])
authorId Int
id Int @id @default(autoincrement())
title String
content String
author User @relation(fields: [authorId], references: [id])
authorId Int
}
11 changes: 6 additions & 5 deletions orm/script/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
"name": "script",
"license": "MIT",
"scripts": {
"dev": "ts-node ./script.ts"
"dev": "tsx ./script.ts"
},
"dependencies": {
"@prisma/client": "6.9.0",
"@prisma/client": "^6.17.1",
"@prisma/extension-accelerate": "^2.0.2",
"@types/node": "22.15.32",
"@prisma/extension-accelerate": "2.0.2"
"dotenv": "^16.4.7"
},
"devDependencies": {
"prisma": "6.9.0",
"ts-node": "10.9.2",
"prisma": "^6.17.1",
"tsx": "^4.20.6",
"typescript": "5.8.2"
}
}
4 changes: 3 additions & 1 deletion orm/script/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
generator client {
provider = "prisma-client-js"
provider = "prisma-client"
output = "./generated"
engineType = "client"
}

datasource db {
Expand Down
3 changes: 2 additions & 1 deletion orm/script/script.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PrismaClient } from '@prisma/client'
import 'dotenv/config'
import { PrismaClient } from './prisma/generated/client'
import { withAccelerate } from '@prisma/extension-accelerate'

const prisma = new PrismaClient().$extends(withAccelerate())
Expand Down
9 changes: 5 additions & 4 deletions orm/starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
"devDependencies": {
"@types/node": "22.15.32",
"nodemon": "3.1.10",
"prisma": "6.9.0",
"tsx": "4.20.6",
"prisma": "^6.17.1",
"tsx": "^4.20.6",
"typescript": "5.8.2"
},
"dependencies": {
"@prisma/client": "6.9.0",
"@prisma/extension-accelerate": "2.0.2"
"@prisma/client": "^6.17.1",
"@prisma/extension-accelerate": "^2.0.2",
"dotenv": "^16.4.7"
},
"prettier": {
"trailingComma": "all",
Expand Down
4 changes: 3 additions & 1 deletion orm/starter/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
provider = "prisma-client"
output = "./generated"
engineType = "client"
}

datasource db {
Expand Down
3 changes: 2 additions & 1 deletion orm/starter/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PrismaClient } from '@prisma/client';
import 'dotenv/config';
import { PrismaClient } from '../prisma/generated/client';
import { withAccelerate } from '@prisma/extension-accelerate';

const prisma = new PrismaClient().$extends(withAccelerate());
Expand Down
16 changes: 8 additions & 8 deletions orm/starter/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"rootDir": "./src",
"outDir": "./dist",
"target": "es6",
"module": "commonjs",
"rootDir": ".",
"outDir": "./dist",
"strict": true,
"esModuleInterop": true,
"typeRoots": [
"./node_modules/@types"
],
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true
},
}
"include": [
"src"
]
}
1 change: 1 addition & 0 deletions orm/testing-express/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL="postgresql://USER:PASSWORD@HOST:PORT/DATABASE"
19 changes: 13 additions & 6 deletions orm/testing-express/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
const path = require('path')
const { defaults } = require('jest-config')
import { fileURLToPath } from 'node:url'
import { dirname, join } from 'node:path'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
preset: 'ts-jest',
moduleFileExtensions: [...defaults.moduleFileExtensions, 'mjs'],
testEnvironment: path.join(__dirname, 'prisma', 'prisma-test-environment.mjs'),
preset: 'ts-jest/presets/default-esm',
moduleFileExtensions: ['js', 'json', 'ts', 'mjs'],
testEnvironment: join(__dirname, 'prisma', 'prisma-test-environment.mjs'),
setupFilesAfterEnv: ['<rootDir>/setupTests.ts'],
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
}

module.exports = config
export default config
16 changes: 9 additions & 7 deletions orm/testing-express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
"name": "testing-express",
"version": "1.0.0",
"license": "MIT",
"type": "module",
"scripts": {
"dev": "ts-node src/index.ts",
"test": "jest --detectOpenHandles"
"dev": "tsx src/index.ts",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles"
},
"prettier": {
"semi": false,
"singleQuote": true
},
"dependencies": {
"@prisma/client": "6.9.0",
"@prisma/extension-accelerate": "2.0.2",
"@prisma/client": "^6.17.1",
"@prisma/extension-accelerate": "^2.0.2",
"@types/node": "22.15.32",
"dotenv": "^16.6.1",
"express": "5.1.0",
"jest-config": "29.7.0"
},
Expand All @@ -25,13 +27,13 @@
"jest": "29.7.0",
"jest-environment-node": "29.7.0",
"nanoid": "5.1.5",
"prisma": "6.9.0",
"prisma": "^6.17.1",
"supertest": "7.1.1",
"ts-jest": "29.4.5",
"ts-node": "10.9.2",
"tsx": "^4.20.6",
"typescript": "5.8.2"
},
"prisma": {
"seed": "ts-node prisma/seed.ts"
"seed": "tsx prisma/seed.ts"
}
}
14 changes: 10 additions & 4 deletions orm/testing-express/prisma/prisma-test-environment.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import fs from 'fs'
import { nanoid } from 'nanoid'
import { TestEnvironment } from 'jest-environment-node'
import { exec } from 'child_process'
import { promisify } from 'util'
import { fileURLToPath } from 'url'
import "dotenv/config"

const execAsync = promisify(exec)

// fix for 'How to fix "__dirname is not defined in ES module scope"'
const __filename = fileURLToPath(import.meta.url);
Expand All @@ -24,20 +28,22 @@ class PrismaTestEnvironment extends TestEnvironment {
constructor(config, _context) {
super(config, _context)

// Generate a unique sqlite identifier for this test context
// Generate a unique database file for this test context
this.dbName = `test_${nanoid()}.db`
process.env.DB_URL = `file:${this.dbName}`
this.global.process.env.DB_URL = `file:${this.dbName}`
const dbUrl = `file:${this.dbName}`
process.env.DATABASE_URL = dbUrl
this.global.process.env.DATABASE_URL = dbUrl
this.dbPath = path.join(__dirname, this.dbName)
}

async setup() {
// Run the migrations to ensure our schema has the required structure
await exec(`${prismaBinary} db push `)
await execAsync(`${prismaBinary} db push --skip-generate`)
return super.setup()
}

async teardown() {
// Clean up the test database file
try {
await fs.promises.unlink(this.dbPath)
} catch (error) {
Expand Down
5 changes: 3 additions & 2 deletions orm/testing-express/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
generator client {
provider = "prisma-client-js"
output = "./generated"
}

datasource db {
provider = "postgresql"
provider = "sqlite"
url = env("DATABASE_URL")
}

model User {
id Int @default(autoincrement()) @id
id Int @id @default(autoincrement())
name String?
email String @unique
}
2 changes: 1 addition & 1 deletion orm/testing-express/prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PrismaClient, Prisma } from '@prisma/client'
import { PrismaClient, Prisma } from './generated/client'
import { withAccelerate } from '@prisma/extension-accelerate'

const prisma = new PrismaClient().$extends(withAccelerate())
Expand Down
2 changes: 2 additions & 0 deletions orm/testing-express/setupTests.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
import { jest } from '@jest/globals'

jest.setTimeout(10000)
6 changes: 3 additions & 3 deletions orm/testing-express/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PrismaClient } from '@prisma/client'
import { withAccelerate } from '@prisma/extension-accelerate'
import 'dotenv/config'
import { PrismaClient } from '../prisma/generated/client.js'
import express from 'express'

export const prisma = new PrismaClient().$extends(withAccelerate())
export const prisma = new PrismaClient()
export const app = express()

app.use(express.json())
Expand Down
2 changes: 1 addition & 1 deletion orm/testing-express/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app } from './app'
import { app } from './app.js'

app.listen(3000, () =>
console.log(`
Expand Down
Loading
Loading