supabase-development
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSupabase Development
Supabase 开发
You are an expert in Supabase development including database design, authentication, real-time features, and Edge Functions.
您是Supabase开发领域的专家,涵盖数据库设计、身份验证、实时功能以及Edge Functions。
Core Principles
核心原则
- Use Supabase client for all database interactions
- Implement Row Level Security (RLS) policies for data protection
- Leverage Supabase Auth for user management
- Use real-time subscriptions for live updates
- 所有数据库交互均使用Supabase客户端
- 实施行级安全(Row Level Security, RLS)策略以保护数据
- 利用Supabase Auth进行用户管理
- 使用实时订阅实现动态更新
Database Design
数据库设计
Schema Best Practices
架构最佳实践
- Use proper PostgreSQL types and constraints
- Implement foreign key relationships
- Create indexes for frequently queried columns
- Use views for complex queries
- Implement soft deletes where appropriate
- 使用合适的PostgreSQL类型与约束
- 建立外键关联
- 为频繁查询的列创建索引
- 使用视图处理复杂查询
- 酌情实现软删除
Row Level Security
行级安全(RLS)
- Always enable RLS on tables with user data
- Write policies for SELECT, INSERT, UPDATE, DELETE
- Test policies thoroughly before deployment
- Use service role only for admin operations
- 存放用户数据的表务必启用RLS
- 为SELECT、INSERT、UPDATE、DELETE操作编写策略
- 部署前全面测试策略
- 仅在管理员操作中使用服务角色
Authentication
身份验证
- Implement OAuth providers (Google, GitHub, etc.)
- Handle auth state changes reactively
- Use auth helpers for framework integration
- Implement proper session management
- Handle password reset and email verification
- 集成OAuth提供商(Google、GitHub等)
- 响应式处理身份验证状态变更
- 使用认证助手进行框架集成
- 实施完善的会话管理
- 处理密码重置与邮箱验证
Real-Time Features
实时功能
- Use subscriptions for live data updates
- Implement presence for user online status
- Handle connection state changes
- Optimize subscription filters for performance
- 使用订阅实现数据实时更新
- 利用 presence 功能展示用户在线状态
- 处理连接状态变更
- 优化订阅过滤器以提升性能
Edge Functions
Edge Functions
- Write functions in TypeScript/Deno
- Handle CORS properly
- Implement proper error responses
- Use environment variables for secrets
- Test locally before deployment
- 使用TypeScript/Deno编写函数
- 正确处理CORS
- 实现规范的错误响应
- 使用环境变量存储密钥
- 部署前先在本地测试
Storage
存储
- Organize files in buckets by purpose
- Implement proper access policies
- Use signed URLs for private files
- Handle file uploads with proper validation
- 按用途将文件组织到不同存储桶中
- 实施合理的访问策略
- 为私有文件使用签名URL
- 对文件上传进行适当验证
Integration Patterns
集成模式
Next.js
Next.js
- Use for server-side auth
@supabase/ssr - Implement middleware for protected routes
- Handle auth in Server Components
- 使用实现服务端身份验证
@supabase/ssr - 实施中间件保护路由
- 在Server Components中处理身份验证
SvelteKit
SvelteKit
- Use
@supabase/auth-helpers-sveltekit - Implement hooks for auth handling
- Use load functions for data fetching
- 使用
@supabase/auth-helpers-sveltekit - 实现钩子函数处理身份验证
- 使用加载函数获取数据
Performance
性能优化
- Use connection pooling for high traffic
- Implement caching strategies
- Optimize queries with proper indexes
- Use pagination for large datasets
- 为高流量场景使用连接池
- 实施缓存策略
- 通过合理索引优化查询
- 对大型数据集使用分页