Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add D1 + Cloudflare Pages + Nuxt 3 #5040

Merged
merged 17 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ jobs:
- turso-vercel-nextjs-edgemw
- d1-cf-basic
- d1-cfpages-basic
- d1-cfpages-nuxt
clientEngine: ['wasm']
os: [ubuntu-20.04]
runs-on: ${{ matrix.os }}
Expand Down
26 changes: 26 additions & 0 deletions driver-adapters-wasm/d1-cfpages-nuxt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Nuxt dev/build outputs
.output
.data
.nuxt
.nitro
.cache
dist

# Node dependencies
node_modules

# Logs
logs
*.log

# Misc
.DS_Store
.fleet
.idea

# Local env files
.env
.env.*
!.env.example

.wrangler
32 changes: 32 additions & 0 deletions driver-adapters-wasm/d1-cfpages-nuxt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Prisma Driver Adapters Nuxt

This is a Nuxt 3 project that demonstrates how to use Prisma with Driver Adapters.
This project uses:
- Cloudflare Pages as the web platform
- Cloudflare D1 as a database

Look at the [Nuxt 3 documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.

## Setup

Make sure to install the dependencies:

```bash
pnpm install
```

Create a local Cloudflare D1 database:

```bash
pnpm wrangler d1 migrations apply nuxt-db --local
```

## Development Server

Start the development server on `http://localhost:3000`:

```bash
pnpm run dev
```

Go to `http://localhost:3000/api` to see an example Prisma query.
5 changes: 5 additions & 0 deletions driver-adapters-wasm/d1-cfpages-nuxt/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div>
<NuxtWelcome />
</div>
</template>
12 changes: 12 additions & 0 deletions driver-adapters-wasm/d1-cfpages-nuxt/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { CfProperties, Request, ExecutionContext, KVNamespace } from '@cloudflare/workers-types';

declare module 'h3' {
interface H3EventContext {
cf: CfProperties,
cloudflare: {
request: Request,
env: Env,
context: ExecutionContext,
};
}
}
3 changes: 3 additions & 0 deletions driver-adapters-wasm/d1-cfpages-nuxt/finally.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

cat deployment-logs.txt
151 changes: 151 additions & 0 deletions driver-adapters-wasm/d1-cfpages-nuxt/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// @ts-check
const { test, expect } = require('@jest/globals')
const { dependencies } = require('./package.json')
const fetch = require('node-fetch').default

jest.setTimeout(30_000)

test('prisma version and output', async () => {
const response = await fetch(process.env.DEPLOYMENT_URL + '/api', {
headers: {
'user-agent': 'ecosystem-tests',
},
})
const { regResult } = await response.json()

expect(regResult.prismaVersion).toMatch(dependencies['@prisma/client'])
expect(regResult.deleteMany.count).toBe(0)
expect(regResult.create).toMatchInlineSnapshot(`
{
"age": 27,
"email": "test-1@prisma.io",
"name": "Test 1",
}
`)
expect(regResult.createMany.count).toBe(2)
expect(regResult.createManyAndReturn).toMatchInlineSnapshot(`
[
{
"age": 30,
"email": "test-4@prisma.io",
"name": "Test 4",
},
{
"age": 30,
"email": "test-5@prisma.io",
"name": "Test 5",
},
{
"age": 30,
"email": "test-6@prisma.io",
"name": "Test 6",
},
]
`)
expect(regResult.findMany).toMatchInlineSnapshot(`
[
{
"age": 27,
"email": "test-1@prisma.io",
"name": "Test 1",
},
{
"age": 29,
"email": "test-2@prisma.io",
"name": "Test 2",
},
{
"age": 29,
"email": "test-3@prisma.io",
"name": "Test 3",
},
{
"age": 30,
"email": "test-4@prisma.io",
"name": "Test 4",
},
{
"age": 30,
"email": "test-5@prisma.io",
"name": "Test 5",
},
{
"age": 30,
"email": "test-6@prisma.io",
"name": "Test 6",
},
]
`)
expect(regResult.findUnique).toMatchInlineSnapshot(`
{
"age": 27,
"email": "test-1@prisma.io",
"name": "Test 1",
}
`)
expect(regResult.update).toMatchInlineSnapshot(`
{
"age": 26,
"email": "test-1@prisma.io",
"name": "Test 1",
}
`)
expect(regResult.updateMany.count).toBe(1)
expect(regResult.findFirst).toMatchInlineSnapshot(`
{
"age": 27,
"email": "test-1@prisma.io",
"name": "Test 1",
}
`)
expect(regResult.delete).toMatchInlineSnapshot(`
{
"age": 27,
"email": "test-1@prisma.io",
"name": "Test 1",
}
`)
expect(regResult.count).toBe(5)
expect(regResult.aggregate).toMatchInlineSnapshot(`
{
"age": 29,
}
`)
expect(regResult.groupBy).toMatchInlineSnapshot(`
[
{
"_count": {
"age": 2,
},
"age": 29,
},
{
"_count": {
"age": 3,
},
"age": 30,
},
]
`)
expect(regResult.findFirstOrThrow).toMatchInlineSnapshot(`
{
"age": 29,
"email": "test-2@prisma.io",
"name": "Test 2",
}
`)
expect(regResult.findUniqueOrThrow).toMatchInlineSnapshot(`
{
"age": 29,
"email": "test-2@prisma.io",
"name": "Test 2",
}
`)
expect(regResult.upsert).toMatchInlineSnapshot(`
{
"age": 30,
"email": "test-upsert@prisma.io",
"name": "Test upsert",
}
`)
})
13 changes: 13 additions & 0 deletions driver-adapters-wasm/d1-cfpages-nuxt/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import nitroCloudflareBindings from 'nitro-cloudflare-dev'

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
modules: [nitroCloudflareBindings],
nitro: {
preset: 'cloudflare-pages',
experimental: {
wasm: true,
},
},
devtools: { enabled: true },
})
29 changes: 29 additions & 0 deletions driver-adapters-wasm/d1-cfpages-nuxt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "d1-cfpages-nuxt",
"author": {
"name": "Alberto Schiabel",
"email": "schiabel@prisma.io"
},
"private": true,
"type": "module",
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare"
},
"dependencies": {
"@prisma/adapter-d1": "5.15.0-dev.73",
"@prisma/client": "5.15.0-dev.73",
"nuxt": "^3.11.2",
"vue": "^3.4.27",
"vue-router": "^4.3.2"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240524.0",
"nitro-cloudflare-dev": "^0.1.4",
"prisma": "5.15.0-dev.73",
"wrangler": "^3.57.1"
}
}
Loading
Loading