RuleStack

Configs

Stacks

Compare

Diff

RuleStack

Configs

Stacks

Compare

Diff

Read API

RuleStack

Configs

Stacks

Compare

Diff

Read API

Configs/Cursor rules/sferg989/fergfo.om

Cursor rule

.cursor/rules/astro-database-integration.mdc

Astro 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 blocks

Repository

0

— · pushed 262 days ago

Last changed

3 days ago

First indexed 3 days ago.
sferg989/fergfo.om/.cursor/rules/astro-database-integration.mdcRawGitHub
1---
2globs: *.astro
3description: Astro D1 database integration patterns and best practices
4---
5 
6# Astro D1 Database Integration
7 
8## Database Access Pattern
9 
10Always follow this pattern for accessing D1 database in Astro components:
11 
12```astro
13---
14import { DatabaseService } from '../services/database_service';
15 
16// Standard D1 database access pattern
17const db = (Astro.locals.runtime?.env?.DB as D1Database) || null;
18 
19let data: { results: any[]; error?: string } = { results: [] };
20 
21if (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```
36 
37## Key Principles
38 
39- **Always check for db availability**: Database may not be available in all environments
40- **Use proper error handling**: Wrap database calls in try-catch blocks
41- **Log errors appropriately**: Console.error for debugging, user-friendly messages for UI
42- **Provide fallbacks**: Handle cases where database is unavailable gracefully
43- **Type safety**: Cast database connection with proper TypeScript types
44 
45## Service Layer Pattern
46 
47- Use service classes (like `OptionsService`, `DatabaseService`) to encapsulate database logic
48- Pass database connection to service instances
49- Keep database queries out of component frontmatter - delegate to services
50 
51## Error Handling Strategy
52 
53```astro
54---
55// Individual try-catch for each operation
56let snapshotsData: { snapshots: any[]; error?: string } = { snapshots: [] };
57let performanceData: { data: any[]; error?: string } = { data: [] };
58 
59if (db) {
60 try {
61 const service = SomeService.getInstance(db);
62
63 // Separate error handling for each operation
64 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 }
70
71 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```

Sections

  • Astro D1 Database Integration
  • Database Access Pattern
  • Key Principles
  • Service Layer Pattern
  • Error Handling Strategy

What it covers

database

Stack — with the evidence

typescript

(1.00)

astro

(1.00)

tailwind

(1.00)

eslint

(1.00)

javascript

(0.60)

node

(0.60)

github-actions

(0.60)

cloudflare

(0.60)

Glob targeting

  • *.astro

Format

Cursor rules

The most expressive format here. Many small .mdc files, each with frontmatter declaring when it should load, so a rule about migrations only enters context when a migration is open. Costs the most to maintain and only one editor reads it.

What the corpus says about it

Repository

Owner
sferg989
Language
—
License
—
Archived
no

All configs in this repo

Also in sferg989/fergfo.om

Diff this repo’s formats

One 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?

The other instruction files in this repository
RepositoryFormatStackCoversScoreChanged
sferg989/fergfo.om.cursor/rules/astro-component-structure.mdc · 0Cursor rulestypescriptastro+6stylearchui58/1003 days ago
sferg989/fergfo.om.cursor/rules/astro-error-handling.mdc · 0Cursor rulestypescriptastro+6styledatabaseui58/1003 days ago
sferg989/fergfo.om.cursor/rules/astro-performance-patterns.mdc · 0Cursor rulestypescriptastro+6buildstyledatabaseperformance62/1003 days ago
sferg989/fergfo.om.cursor/rules/astro-ssr-patterns.mdc · 0Cursor rulestypescriptastro+6style49/1003 days ago
sferg989/fergfo.om.cursor/rules/ts-typecheck.mdc · 0Cursor rulestypescriptastro+6do-not23/1003 days ago
sferg989/fergfo.om.cursor/rules/ts.mdc · 0Cursor rulestypescriptastro+6styletypesdo-notdocs55/1003 days ago
sferg989/fergfo.om.cursorrules · 0.cursorrulestypescriptastro+6do-not49/1003 days ago
sferg989/fergfo.omCLAUDE.md · 0CLAUDE.mdtypescriptastro+6setupbuildteststyle+789/1003 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.

Same format, overlapping stack, ranked by quality
RepositoryFormatStackCoversScoreChanged
hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126Cursor rulesgobun+5setupbuildtestlint-format+6100/1003 days ago
TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45Cursor rulestypescriptpytest+15testlint-formatstylearch+5100/1003 days ago
markstev/mark-starter.cursor/rules/frontend.mdc · 0Cursor rulestypescriptturborepo+14setuptestlint-formatstyle+699/1003 days ago
Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0Cursor rulestypescriptturborepo+13setuptestlint-formatstyle+799/1003 days ago
dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0Cursor rulestypescriptturborepo+15setuptestlint-formatstyle+799/1003 days ago
deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1Cursor rulestypescriptnextjs+5setuptestlint-formatstyle+799/1003 days ago
langflow-ai/langflow.cursor/rules/docs_development.mdc · 153kCursor rulespythonnode+16setupbuildtestlint-format+797/1003 days ago
TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45Cursor rulestypescriptpytest+15teststyletesting-strategysecurity+397/1003 days ago
RuleStack

Built by

Kynth Studio

Directory

Configs
Stacks
Compare formats
Diff two configs
Best AGENTS.md examples

Formats

AGENTS.md
CLAUDE.md
Cursor rules
Copilot instructions

Reference

Read API
Corpus health
Privacy Policy
Terms

RuleStack

RuleStack

Built by

Kynth Studio

Directory

Configs
Stacks
Compare formats
Diff two configs
Best AGENTS.md examples

Formats

AGENTS.md
CLAUDE.md
Cursor rules
Copilot instructions

Reference

Read API
Corpus health
Privacy Policy
Terms

RuleStack

RuleStack

Built by

Kynth Studio

Directory

Configs
Stacks
Compare formats
Diff two configs
Best AGENTS.md examples

Formats

AGENTS.md
CLAUDE.md
Cursor rules
Copilot instructions

Reference

Read API
Corpus health
Privacy Policy
Terms

RuleStack