Skip to content

Commit

Permalink
support generic Postgres providers (#1055)
Browse files Browse the repository at this point in the history
### Description

- Replace `@vercel/postgres` by `postgres`, supporting any marketplace
Postgres providers
- replace Vercel Postgres copies to Postgres
- update deploy url
- rename `users` table to `profiles` as Nile reserves the `users` table 

Affected templates:

- postgres-starter
- postgres-kysley
- postgres-drizzle
- postgres-nuxt
- postgres-sveltekit

Related PR vercel/front#41198

### Demo URL

<!--
Provide a URL to a live deployment where we can test your PR. If a demo
isn't possible feel free to omit this section.
-->

### Type of Change

- [ ] New Example
- [ ] Example updates (Bug fixes, new features, etc.)
- [ ] Other (changes to the codebase, but not to examples)

### New Example Checklist

- [ ] 🛫 `npm run new-example` was used to create the example
- [ ] 📚 The template wasn't used but I carefuly read the [Adding a new
example](https://github.com/vercel/examples#adding-a-new-example) steps
and implemented them in the example
- [ ] 📱 Is it responsive? Are mobile and tablets considered?
  • Loading branch information
correttojs authored Feb 10, 2025
1 parent 3da86a3 commit 9c755fe
Show file tree
Hide file tree
Showing 34 changed files with 14,124 additions and 9,200 deletions.
14 changes: 7 additions & 7 deletions storage/postgres-drizzle/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
---
name: Vercel Postgres + Drizzle Next.js Starter
name: Postgres + Drizzle Next.js Starter
slug: postgres-drizzle
description: Simple Next.js template that uses Vercel Postgres as the database and Drizzle as the ORM.
description: Simple Next.js template that uses a Postgres database and Drizzle as the ORM.
framework: Next.js
useCase: Starter
css: Tailwind
database: Vercel Postgres
deployUrl: https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fexamples%2Ftree%2Fmain%2Fstorage%2Fpostgres-drizzle&project-name=postgres-drizzle&repository-name=postgres-drizzle&demo-title=Vercel%20Postgres%20%2B%20Drizzle%20Next.js%20Starter&demo-description=Simple%20Next.js%20template%20that%20uses%20Vercel%20Postgres%20as%20the%20database%20and%20Drizzle%20as%20the%20ORM.&demo-url=https%3A%2F%2Fpostgres-drizzle.vercel.app%2F&demo-image=https%3A%2F%2Fpostgres-drizzle.vercel.app%2Fopengraph-image.png&stores=%5B%7B"type"%3A"postgres"%7D%5D
database: Postgres
deployUrl: https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fexamples%2Ftree%2Fmain%2Fstorage%2Fpostgres-drizzle&project-name=postgres-drizzle&repository-name=postgres-drizzle&demo-title=Vercel%20Postgres%20%2B%20Drizzle%20Next.js%20Starter&demo-description=Simple%20Next.js%20template%20that%20uses%20Vercel%20Postgres%20as%20the%20database%20and%20Drizzle%20as%20the%20ORM.&demo-url=https%3A%2F%2Fpostgres-drizzle.vercel.app%2F&demo-image=https%3A%2F%2Fpostgres-drizzle.vercel.app%2Fopengraph-image.png&products=%5B%7B%22type%22%3A%22integration%22%2C%22group%22%3A%22postgres%22%7D%5D
demoUrl: https://postgres-drizzle.vercel.app/
relatedTemplates:
- postgres-starter
- postgres-prisma
- postgres-kysely
---

# Vercel Postgres + Drizzle Next.js Starter
# Postgres + Drizzle Next.js Starter

Simple Next.js template that uses [Vercel Postgres](https://vercel.com/postgres) as the database and [Drizzle](https://github.com/drizzle-team/drizzle-orm) as the ORM.
Simple Next.js template that uses a Postgres database and [Drizzle](https://github.com/drizzle-team/drizzle-orm) as the ORM.

## Demo

Expand All @@ -30,7 +30,7 @@ You can choose from one of the following two methods to use this repository:

Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=vercel-examples):

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fexamples%2Ftree%2Fmain%2Fstorage%2Fpostgres-drizzle&project-name=postgres-drizzle&repository-name=postgres-drizzle&demo-title=Vercel%20Postgres%20%2B%20Drizzle%20Next.js%20Starter&demo-description=Simple%20Next.js%20template%20that%20uses%20Vercel%20Postgres%20as%20the%20database%20and%20Drizzle%20as%20the%20ORM.&demo-url=https%3A%2F%2Fpostgres-drizzle.vercel.app%2F&demo-image=https%3A%2F%2Fpostgres-drizzle.vercel.app%2Fopengraph-image.png&stores=%5B%7B"type"%3A"postgres"%7D%5D)
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fexamples%2Ftree%2Fmain%2Fstorage%2Fpostgres-drizzle&project-name=postgres-drizzle&repository-name=postgres-drizzle&demo-title=Vercel%20Postgres%20%2B%20Drizzle%20Next.js%20Starter&demo-description=Simple%20Next.js%20template%20that%20uses%20Vercel%20Postgres%20as%20the%20database%20and%20Drizzle%20as%20the%20ORM.&demo-url=https%3A%2F%2Fpostgres-drizzle.vercel.app%2F&demo-image=https%3A%2F%2Fpostgres-drizzle.vercel.app%2Fopengraph-image.png&products=%5B%7B%22type%22%3A%22integration%22%2C%22group%22%3A%22postgres%22%7D%5D)

### Clone and Deploy

Expand Down
4 changes: 2 additions & 2 deletions storage/postgres-drizzle/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Inter } from 'next/font/google'

export const metadata = {
metadataBase: new URL('https://postgres-drizzle.vercel.app'),
title: 'Vercel Postgres Demo with Drizzle',
title: 'Postgres Demo with Drizzle',
description:
'A simple Next.js app with Vercel Postgres as the database and Drizzle as the ORM',
'A simple Next.js app with a Postgres database and Drizzle as the ORM',
}

const inter = Inter({
Expand Down
9 changes: 1 addition & 8 deletions storage/postgres-drizzle/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Table from '@/components/table'
import TablePlaceholder from '@/components/table-placeholder'
import ExpandingArrow from '@/components/expanding-arrow'

export const runtime = 'edge'
export const dynamic = 'force-dynamic'

export default function Home() {
Expand All @@ -25,13 +24,7 @@ export default function Home() {
<Table />
</Suspense>
<p className="font-light text-gray-600 w-full max-w-lg text-center mt-6">
<Link
href="https://vercel.com/postgres"
className="font-medium underline underline-offset-4 hover:text-black transition-colors"
>
Vercel Postgres
</Link>{' '}
demo with{' '}
Postgres demo with{' '}
<Link
href="https://github.com/drizzle-team/drizzle-orm"
className="font-medium underline underline-offset-4 hover:text-black transition-colors"
Expand Down
10 changes: 6 additions & 4 deletions storage/postgres-drizzle/lib/drizzle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import {
uniqueIndex,
} from 'drizzle-orm/pg-core'
import { InferSelectModel, InferInsertModel } from 'drizzle-orm'
import { sql } from '@vercel/postgres'
import { drizzle } from 'drizzle-orm/vercel-postgres'
import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'

const sql = postgres(process.env.POSTGRES_URL!, { ssl: 'require' })

export const UsersTable = pgTable(
'users',
'profiles',
{
id: serial('id').primaryKey(),
name: text('name').notNull(),
Expand All @@ -28,5 +30,5 @@ export const UsersTable = pgTable(
export type User = InferSelectModel<typeof UsersTable>
export type NewUser = InferInsertModel<typeof UsersTable>

// Connect to Vercel Postgres
// Connect to Postgres
export const db = drizzle(sql)
8 changes: 5 additions & 3 deletions storage/postgres-drizzle/lib/seed.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { sql } from '@vercel/postgres'
import { db } from '@/lib/drizzle'
import { UsersTable, User, NewUser } from './drizzle'
import postgres from 'postgres'

const sql = postgres(process.env.POSTGRES_URL!, { ssl: 'require' })

const newUsers: NewUser[] = [
{
Expand All @@ -26,15 +28,15 @@ const newUsers: NewUser[] = [
export async function seed() {
// Create table with raw SQL
const createTable = await sql.query(`
CREATE TABLE IF NOT EXISTS users (
CREATE TABLE IF NOT EXISTS profiles (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
image VARCHAR(255),
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
`)
console.log(`Created "users" table`)
console.log(`Created "profiles" table`)

const insertedUsers: User[] = await db
.insert(UsersTable)
Expand Down
14 changes: 7 additions & 7 deletions storage/postgres-drizzle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
"dependencies": {
"@types/ms": "^0.7.32",
"@types/node": "20.8.3",
"@types/react": "18.2.25",
"@types/react-dom": "18.2.11",
"@vercel/postgres": "0.5.0",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"autoprefixer": "10.4.16",
"drizzle-kit": "^0.19.13",
"drizzle-orm": "^0.28.6",
"eslint": "8.51.0",
"eslint-config-next": "13.5.4",
"eslint-config-next": "^15.1.6",
"ms": "^2.1.3",
"next": "13.5.4",
"next": "^15.1.6",
"postcss": "8.4.31",
"react": "18.2.0",
"react-dom": "18.2.0",
"postgres": "^3.4.5",
"react": "19.0.0",
"react-dom": "19.0.0",
"tailwindcss": "3.3.3",
"typescript": "5.2.2"
}
Expand Down
Loading

0 comments on commit 9c755fe

Please sign in to comment.