-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(drizzle): migrate pgvector example to Drizzle ORM (#923)
- Loading branch information
1 parent
12c5509
commit fdb4f5f
Showing
18 changed files
with
931 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
POSTGRES_URL= | ||
POSTGRES_URL_NON_POOLING= | ||
POSTGRES_USER= | ||
POSTGRES_HOST= | ||
POSTGRES_PASSWORD= | ||
POSTGRES_DATABASE= | ||
OPENAI_API_KEY= | ||
OPENAI_API_KEY= | ||
OPENAI_ORG_ID= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { defineConfig } from 'drizzle-kit' | ||
|
||
export default defineConfig({ | ||
schema: './drizzle/schema.ts', | ||
out: './drizzle/migrations', | ||
dialect: 'postgresql', | ||
dbCredentials: { | ||
url: process.env.POSTGRES_URL!, | ||
}, | ||
// prints all statements that will be executed: https://orm.drizzle.team/kit-docs/config-reference#verbose | ||
// verbose: true, | ||
// always ask for your confirmation to execute statements: https://orm.drizzle.team/kit-docs/config-reference#strict | ||
// strict: true, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { sql } from '@vercel/postgres' | ||
import { drizzle } from 'drizzle-orm/vercel-postgres' | ||
import * as schema from './schema' | ||
|
||
export const db = drizzle(sql, { schema }) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { | ||
boolean, | ||
index, | ||
integer, | ||
pgTable, | ||
text, | ||
vector, | ||
} from 'drizzle-orm/pg-core' | ||
import { randomUUID } from 'crypto' | ||
|
||
export const pokemons = pgTable( | ||
'pokemon', | ||
{ | ||
id: text('id') | ||
.primaryKey() | ||
.notNull() | ||
.$defaultFn(() => randomUUID()), | ||
number: integer('number').notNull(), | ||
name: text('name').notNull(), | ||
type1: text('type1').notNull(), | ||
type2: text('type2'), | ||
total: integer('total').notNull(), | ||
hp: integer('hp').notNull(), | ||
attack: integer('attack').notNull(), | ||
defense: integer('defense').notNull(), | ||
spAtk: integer('spAtk').notNull(), | ||
spDef: integer('spDef').notNull(), | ||
speed: integer('speed').notNull(), | ||
generation: integer('generation').notNull(), | ||
legendary: boolean('legendary').notNull(), | ||
embedding: vector('embedding', { dimensions: 1536 }), | ||
}, | ||
(table) => ({ | ||
embeddingIndex: index().using( | ||
'hnsw', | ||
table.embedding.op('vector_cosine_ops') | ||
), | ||
}) | ||
) | ||
|
||
export type SelectPokemon = typeof pokemons.$inferSelect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,43 @@ | ||
{ | ||
"name": "postgres-prisma-pgvector-openai", | ||
"name": "postgres-drizzle-orm-pgvector-openai", | ||
"repository": "https://github.com/vercel/examples.git", | ||
"license": "MIT", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "prisma generate && next dev", | ||
"build": "prisma generate && prisma db push && prisma db seed && next build", | ||
"dev": "next dev", | ||
"db:seed": "ts-node --compiler-options '{\"module\":\"CommonJS\"}' drizzle/seed.ts", | ||
"build": "drizzle-kit push && pnpm db:seed && next build", | ||
"start": "next start", | ||
"lint": "next lint" | ||
}, | ||
"prisma": { | ||
"seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts" | ||
}, | ||
"dependencies": { | ||
"@ai-sdk/openai": "^0.0.14", | ||
"@prisma/client": "^5.14.0", | ||
"@types/node": "20.12.12", | ||
"@types/react": "18.3.2", | ||
"@types/react-dom": "18.3.0", | ||
"@vercel/postgres": "^0.8.0", | ||
"ai": "^3.1.14", | ||
"autoprefixer": "10.4.19", | ||
"clsx": "^2.1.1", | ||
"cmdk": "^1.0.0", | ||
"drizzle-orm": "^0.31.0", | ||
"eslint": "9.3.0", | ||
"eslint-config-next": "14.2.3", | ||
"gpt3-tokenizer": "^1.1.5", | ||
"next": "14.2.3", | ||
"openai": "^4.47.1", | ||
"postcss": "8.4.38", | ||
"prisma": "^5.14.0", | ||
"react": "18.3.1", | ||
"react-dom": "18.3.1", | ||
"tailwind-merge": "^2.3.0", | ||
"tailwindcss": "3.4.3", | ||
"ts-node": "^10.9.2", | ||
"typescript": "5.4.5", | ||
"use-debounce": "^10.0.0" | ||
}, | ||
"devDependencies": { | ||
"dotenv": "^16.4.5", | ||
"drizzle-kit": "^0.22.0" | ||
} | ||
} |
Oops, something went wrong.