Cursor rule
.cursor/rules/astro-database-integration.mdcAstro D1 database integration patterns and best practices
Cursor rules
Quality
50/100
Scores the file, not the repository.Length
342 words
5 headings · 2 code blocksRepository
0
— · pushed 262 days agoLast changed
3 days ago
First indexed 3 days ago.123456# Astro D1 Database Integration78## Database Access Pattern910Always follow this pattern for accessing D1 database in Astro components:1112```astro13---14import { DatabaseService } from '../services/database_service';1516// Standard D1 database access pattern17const db = (Astro.locals.runtime?.env?.DB as D1Database) || null;1819let data: { results: any[]; error?: string } = { results: [] };2021if (db) {22 try {23 const dbService = DatabaseService.getInstance(db);24 const results = await dbService.getData();25 data = { results };26 } catch (err) {27 console.error('Database error:', err);28 data = { results: [], error: err instanceof Error ? err.message : 'Database error' };29 }30} else {31 console.warn('Database not available in runtime');32 data = { results: [], error: 'Database not available' };33}34---35```3637## Key Principles3839- **Always check for db availability**: Database may not be available in all environments40- **Use proper error handling**: Wrap database calls in try-catch blocks41- **Log errors appropriately**: Console.error for debugging, user-friendly messages for UI42- **Provide fallbacks**: Handle cases where database is unavailable gracefully43- **Type safety**: Cast database connection with proper TypeScript types4445## Service Layer Pattern4647- Use service classes (like `OptionsService`, `DatabaseService`) to encapsulate database logic48- Pass database connection to service instances49- Keep database queries out of component frontmatter - delegate to services5051## Error Handling Strategy5253```astro54---55// Individual try-catch for each operation56let snapshotsData: { snapshots: any[]; error?: string } = { snapshots: [] };57let performanceData: { data: any[]; error?: string } = { data: [] };5859if (db) {60 try {61 const service = SomeService.getInstance(db);6263 // Separate error handling for each operation64 try {65 const snapshots = await service.getSnapshots();66 snapshotsData = { snapshots };67 } catch (err) {68 snapshotsData = { snapshots: [], error: err instanceof Error ? err.message : 'Snapshots error' };69 }7071 try {72 const performance = await service.getPerformance();73 performanceData = { data: performance };74 } catch (err) {75 performanceData = { data: [], error: err instanceof Error ? err.message : 'Performance error' };76 }77 } catch (err) {78 console.error('Service initialization error:', err);79 }80}81---82```
Also in sferg989/fergfo.om
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| sferg989/fergfo.om.cursor/rules/astro-component-structure.mdc · 0 | Cursor rules | stylearchui | 58/100 | 3 days ago | |
| sferg989/fergfo.om.cursor/rules/astro-error-handling.mdc · 0 | Cursor rules | styledatabaseui | 58/100 | 3 days ago | |
| sferg989/fergfo.om.cursor/rules/astro-performance-patterns.mdc · 0 | Cursor rules | buildstyledatabaseperformance | 62/100 | 3 days ago | |
| sferg989/fergfo.om.cursor/rules/astro-ssr-patterns.mdc · 0 | Cursor rules | style | 49/100 | 3 days ago | |
| sferg989/fergfo.om.cursor/rules/ts-typecheck.mdc · 0 | Cursor rules | do-not | 23/100 | 3 days ago | |
| sferg989/fergfo.om.cursor/rules/ts.mdc · 0 | Cursor rules | styletypesdo-notdocs | 55/100 | 3 days ago | |
| sferg989/fergfo.om.cursorrules · 0 | .cursorrules | do-not | 49/100 | 3 days ago | |
| sferg989/fergfo.omCLAUDE.md · 0 | CLAUDE.md | setupbuildteststyle+7 | 89/100 | 3 days ago |
Diff against .cursor/rules/astro-component-structure.mdc Diff against .cursor/rules/astro-error-handling.mdc Diff against .cursor/rules/astro-performance-patterns.mdc Diff against .cursor/rules/astro-ssr-patterns.mdc Diff against .cursor/rules/ts-typecheck.mdc Diff against .cursor/rules/ts.mdc Diff against .cursorrules Diff against CLAUDE.md
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 3 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 3 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 3 days ago |
