content.tsx 1.8 KB

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