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