content.tsx64 lines · main
| 1 | import { MultipleCodeBlock } from 'ui-patterns/MultipleCodeBlock' |
| 2 | |
| 3 | import type { StepContentProps } from '@/components/interfaces/ConnectSheet/Connect.types' |
| 4 | |
| 5 | const ContentFile = ({ connectionStringPooler }: StepContentProps) => { |
| 6 | const files = [ |
| 7 | { |
| 8 | name: '.env', |
| 9 | language: 'bash', |
| 10 | code: |
| 11 | connectionStringPooler.ipv4SupportedForDedicatedPooler && |
| 12 | connectionStringPooler.transactionDedicated |
| 13 | ? ` |
| 14 | DATABASE_URL="${connectionStringPooler.transactionDedicated}" |
| 15 | ` |
| 16 | : connectionStringPooler.transactionDedicated && |
| 17 | !connectionStringPooler.ipv4SupportedForDedicatedPooler |
| 18 | ? ` |
| 19 | # Use Shared connection pooler (supports both IPv4/IPv6) |
| 20 | DATABASE_URL="${connectionStringPooler.transactionShared}" |
| 21 | |
| 22 | # If your network supports IPv6 or you purchased IPv4 addon, use dedicated pooler |
| 23 | # DATABASE_URL="${connectionStringPooler.transactionDedicated}" |
| 24 | ` |
| 25 | : ` |
| 26 | DATABASE_URL="${connectionStringPooler.transactionShared}" |
| 27 | `, |
| 28 | }, |
| 29 | { |
| 30 | name: 'drizzle/schema.ts', |
| 31 | language: 'tsx', |
| 32 | code: ` |
| 33 | import { pgTable, serial, text, varchar } from "drizzle-orm/pg-core"; |
| 34 | |
| 35 | export const users = pgTable('users', { |
| 36 | id: serial('id').primaryKey(), |
| 37 | fullName: text('full_name'), |
| 38 | phone: varchar('phone', { length: 256 }), |
| 39 | }); |
| 40 | `, |
| 41 | }, |
| 42 | { |
| 43 | name: 'index.tsx', |
| 44 | language: 'tsx', |
| 45 | code: ` |
| 46 | import { drizzle } from 'drizzle-orm/postgres-js' |
| 47 | import postgres from 'postgres' |
| 48 | import { users } from './drizzle/schema' |
| 49 | |
| 50 | const connectionString = process.env.DATABASE_URL |
| 51 | |
| 52 | // Disable prefetch as it is not supported for "Transaction" pool mode |
| 53 | const client = postgres(connectionString, { prepare: false }) |
| 54 | const db = drizzle(client); |
| 55 | |
| 56 | const allUsers = await db.select().from(users); |
| 57 | `, |
| 58 | }, |
| 59 | ] |
| 60 | |
| 61 | return <MultipleCodeBlock files={files} /> |
| 62 | } |
| 63 | |
| 64 | export default ContentFile |