Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ Here is an overview of all data service providers and the compute locations avai
| Convex (SDK) | ✅ | ✅ | ✅ |
| Fauna | ✅ | ✅ | ❌ |
| Grafbase (GraphQL) | ✅ | ✅ | ✅ |
| Neon | ✅ | ✅ | ❌ |
| Neon w/ @neondatabase/serverless | ✅ | ✅ | ✅ |
| Neon w/ Drizzle ORM | ✅ | ✅ | ✅ |
| Neon w/ Prisma ORM | ✅ | ✅ | ✅ |
| PlanetScale w/ Kysely | ✅ | ✅ | ❌ |
| PlanetScale w/ Prisma ORM | ✅ | ✅ | ✅ |
| PlanetScale w/ Drizzle | ✅ | ✅ | ✅ |
Expand Down
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"gen:planetscale": "prisma generate --schema ./prisma-planetscale/schema.prisma",
"gen:supabase": "prisma generate --schema ./prisma-supabase/schema.prisma",
"gen:xata": "prisma generate --schema ./prisma-xata/schema.prisma",
"gen:turso": "prisma generate --schema ./prisma-turso/schema.prisma"
"gen:turso": "prisma generate --schema ./prisma-turso/schema.prisma",
"gen:neon": "prisma generate --schema ./prisma-neon/schema.prisma"
},
"dependencies": {
"@headlessui/react": "^1.7.18",
Expand All @@ -18,6 +19,7 @@
"@planetscale/database": "^1.16.0",
"@polyscale/serverless-js": "^1.4.0",
"@prisma/adapter-libsql": "^5.13.0",
"@prisma/adapter-neon": "^5.13.0",
"@prisma/adapter-planetscale": "^5.13.0",
"@prisma/client": "5.13.0",
"@supabase/supabase-js": "^2.39.8",
Expand All @@ -43,13 +45,17 @@
"react": "18.3.1",
"react-dom": "18.3.1",
"tailwindcss": "^3.4.1",
"typescript": "^5.4.2"
"typescript": "^5.4.2",
"ws": "^8.17.0"
},
"pnpm": {
"peerDependencyRules": {
"ignoreMissing": [
"prop-types"
]
}
},
"optionalDependencies": {
"bufferutil": "^4.0.8"
}
}
50 changes: 50 additions & 0 deletions pages/api/neon-drizzle-global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { NextRequest as Request, NextResponse as Response } from "next/server";
import { drizzle } from "drizzle-orm/neon-http";
import { neon } from "@neondatabase/serverless";
import { pgTable, serial, varchar } from "drizzle-orm/pg-core";

export const config = {
runtime: "edge",
};

export const employees = pgTable("employees", {
id: serial("emp_no").primaryKey(),
first_name: varchar("first_name", { length: 256 }),
last_name: varchar("last_name", { length: 256 }),
});

const client = neon(process.env.NEON_DATABASE_URL);
const db = drizzle(client);

const start = Date.now();

export default async function api(req: Request) {
const count = toNumber(new URL(req.url).searchParams.get("count"));
const time = Date.now();

let data = null;
for (let i = 0; i < count; i++) {
data = await db.select().from(employees).limit(10);
}

return Response.json(
{
data,
queryDuration: Date.now() - time,
invocationIsCold: start === time,
invocationRegion: (req.headers.get("x-vercel-id") ?? "").split(":")[1] || null,
},
{
headers: {
"x-edge-is-cold": start === time ? "1" : "0",
},
}
);
}

// convert a query parameter to a number
// also apply a min and a max
function toNumber(queryParam: string | null, min = 1, max = 5) {
const num = Number(queryParam);
return Number.isNaN(num) ? null : Math.min(Math.max(num, min), max);
}
38 changes: 38 additions & 0 deletions pages/api/neon-drizzle-node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { drizzle } from "drizzle-orm/neon-http";
import { neon } from "@neondatabase/serverless";
import { pgTable, serial, varchar } from "drizzle-orm/pg-core";

export const employees = pgTable("employees", {
id: serial("emp_no").primaryKey(),
first_name: varchar("first_name", { length: 256 }),
last_name: varchar("last_name", { length: 256 }),
});

const client = neon(process.env.NEON_DATABASE_URL);
const db = drizzle(client);

const start = Date.now();

export default async function handler (req: NextApiRequest, res: NextApiResponse) {
const { count } = req.query;

const time = Date.now();

let data = null;
for (let i = 0; i < toNumber(count); i++) {
data = await db.select().from(employees).limit(10);
}

return res.status(200).json({
data,
queryDuration: Date.now() - time,
invocationIsCold: start === time,
});
}

// convert a query parameter to a number, applying a min and max, defaulting to 1
function toNumber(queryParam: string | string[] | null, min = 1, max = 5) {
const num = Number(queryParam);
return Number.isNaN(num) ? 1 : Math.min(Math.max(num, min), max);
}
6 changes: 6 additions & 0 deletions pages/api/neon-drizzle-regional.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const config = {
runtime: "edge",
regions: ["iad1"],
};

export { default } from "./neon-drizzle-global";
43 changes: 43 additions & 0 deletions pages/api/neon-prisma-global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { NextRequest as Request, NextResponse as Response } from "next/server";
import { Pool } from '@neondatabase/serverless'
import { PrismaNeon } from '@prisma/adapter-neon'
import { PrismaClient } from '@/prisma-neon/prisma-client'

export const config = {
runtime: "edge",
};
const pool = new Pool({ connectionString: process.env.NEON_DATABASE_URL, idleTimeoutMillis: 1 })
const adapter = new PrismaNeon(pool)
const prisma = new PrismaClient({ adapter })
const start = Date.now()

export default async function api(req: Request) {
const count = toNumber(new URL(req.url).searchParams.get("count"));
const time = Date.now();

let data = null;
for (let i = 0; i < count; i++) {

data = await prisma.employees.findMany({ take: 10 });
}
return Response.json(
{
data,
queryDuration: Date.now() - time,
invocationIsCold: start === time,
invocationRegion: (req.headers.get("x-vercel-id") ?? "").split(":")[1] || null,
},
{
headers: {
"x-edge-is-cold": start === time ? "1" : "0",
},
}
);
}

// convert a query parameter to a number
// also apply a min and a max
function toNumber(queryParam: string | null, min = 1, max = 5) {
const num = Number(queryParam);
return Number.isNaN(num) ? null : Math.min(Math.max(num, min), max);
}
31 changes: 31 additions & 0 deletions pages/api/neon-prisma-node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { Pool } from '@neondatabase/serverless'
import { PrismaNeon } from '@prisma/adapter-neon'
import { PrismaClient } from '@/prisma-neon/prisma-client'

const pool = new Pool({ connectionString: process.env.NEON_DATABASE_URL })
const adapter = new PrismaNeon(pool)
const prisma = new PrismaClient({ adapter })
const start = Date.now();

export default async function handler (req: NextApiRequest, res: NextApiResponse) {
const { count } = req.query;
const time = Date.now();

let data = null;
for (let i = 0; i < toNumber(count); i++) {
data = await prisma.employees.findMany({ take: 10 });
}

return res.status(200).json({
data,
queryDuration: Date.now() - time,
invocationIsCold: start === time,
});
}

// convert a query parameter to a number, applying a min and max, defaulting to 1
function toNumber(queryParam: string | string[] | null, min = 1, max = 5) {
const num = Number(queryParam);
return Number.isNaN(num) ? 1 : Math.min(Math.max(num, min), max);
}
6 changes: 6 additions & 0 deletions pages/api/neon-prisma-regional.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const config = {
runtime: "edge",
regions: ["iad1"],
};

export { default } from "./neon-prisma-global";
11 changes: 10 additions & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ const NODE_AVAILABLE = [
'turso',
'turso-drizzle',
'turso-prisma',
'upstash'
'upstash',
'neon',
'neon-drizzle',
'neon-prisma'
];
const NODE_ONLY = [
'supabase-drizzle',
Expand Down Expand Up @@ -198,6 +201,12 @@ export default function Page() {
<SelectItem data-testid="neon" value="neon" icon={NeonIcon}>
Neon (@neondatabase/serverless driver)
</SelectItem>
<SelectItem data-testid="neon-drizzle" value="neon-drizzle" icon={NeonIcon}>
Neon (w/ Drizzle ORM)
</SelectItem>
<SelectItem data-testid="neon-prisma" value="neon-prisma" icon={NeonIcon}>
Neon (w/ Prisma ORM)
</SelectItem>
<SelectItem
data-testid="planetscale"
value="planetscale"
Expand Down
Loading