Drizzle Solid Development
Expert guidance for developing with Drizzle Solid - a TypeScript ORM adapter that translates SQL-like Drizzle operations into SPARQL queries for Solid Pod RDF data storage.
What This Skill Does
This skill provides comprehensive assistance for working with the drizzle-solid codebase, including:
Understanding the architecture (AST-to-SPARQL conversion, Pod dialect, SPARQL execution)Building and testing the projectWorking with core components (PodDialect, SPARQL executor, table schemas)Handling concurrent write conflictsRunning examples and development workflowsFollowing best practices for type-safe, decentralized data operationsInstructions
When the user asks for help with drizzle-solid development, follow these steps:
1. Understand the Request Context
Identify what aspect of drizzle-solid the user needs help with:
Build/test/lint commandsCore architecture components (PodDialect, AST conversion, SPARQL execution)Table schema definitions and RDF mappingsTesting infrastructure (unit tests, integration tests with CSS)Conflict resolution strategiesExample usage patternsDevelopment setup2. Locate Relevant Files
Based on the request, navigate to the appropriate files:
**Core Dialect**: `src/core/pod-dialect.ts` - Main integration point**Query Conversion**: `src/core/ast-to-sparql.ts`, `src/core/ast-to-sparql-v2.ts` - SQL AST to SPARQL**Execution**: `src/core/sparql-executor.ts` - Comunica wrapper and PATCH operations**Schemas**: `src/core/pod-table.ts` - Table definitions and RDF predicate mappings**Type Safety**: `src/core/compile-time-types.ts`, `src/core/zod-integration.ts`**Conflict Handling**: `src/core/conflict-resolution.ts` - Concurrent write strategies**Tests**: `tests/unit/`, `tests/integration/css/`**Examples**: `examples/01-server-setup.ts`, `examples/02-authentication.ts`, `examples/03-basic-usage.ts`3. Provide Development Commands
When the user asks about building, testing, or running the project, provide the relevant commands:
**Build and Quality:**
```bash
yarn build # Compile TypeScript to dist/
yarn test # Run all tests
yarn test:watch # Watch mode
yarn test:coverage # Coverage report
yarn lint # Check linting
yarn lint:fix # Auto-fix issues
yarn quality # Lint + test (CI)
```
**Development:**
```bash
yarn dev # Run with ts-node
yarn example:setup # Pod setup tutorial
yarn example:auth # Authentication demo
yarn example:usage # CRUD walkthrough
yarn server:start # Start CSS server
yarn server:setup # Create test accounts
```
4. Explain Architecture Components
When explaining how drizzle-solid works, describe the data flow:
1. **Query Building**: User writes Drizzle queries (select, insert, update, delete)
2. **AST Conversion**: SQL AST is converted to SPARQL via `ASTToSPARQLConverter`
3. **Execution Strategy**:
- Simple operations use native SPARQL via Comunica
- Complex operations (aggregates, JOINs) use client-side fallback
4. **RDF Mapping**: Results are mapped back to TypeScript objects via table schemas
**Key Components:**
`PodDialect`: Main dialect, handles session management and Pod discovery`AST-to-SPARQL`: Converts Drizzle SQL AST to SPARQL using sparqljs`SPARQL Executor`: Wraps Comunica, handles PATCH operations and authentication`Pod Table`: Defines schemas with RDF predicate mappings and TypeScript inference`Conflict Resolver`: Handles concurrent write conflicts with multiple merge strategies5. Handle Conflict Resolution Requests
If the user asks about handling concurrent writes or 412 errors, explain the conflict resolution strategies:
**Strategies:**
`last-write-wins`: Local changes overwrite remote (default)`field-level-merge`: Update only specified predicates, preserve others`timestamp-based`: Keep most recent version by dateModified`user-resolution`: Custom merge function**Example usage:**
```typescript
import { saveWithConflictResolution } from 'drizzle-solid';
const result = await saveWithConflictResolution(
session.fetch,
'https://pod.example/data/notes.ttl',
async (dataset) => {
// Modify dataset
return updatedDataset;
}
);
```
6. Provide Testing Guidance
For testing-related questions:
Unit tests are in `tests/unit/`Integration tests require Community Solid Server: `yarn server:start`Run specific tests: `yarn test -- --testNamePattern="your test"`Always run `yarn test` before committingCoverage reports: `yarn test:coverage`7. Follow Code Patterns
When modifying code, ensure:
TypeScript strict mode complianceDrizzle-style query builders and type inferenceEstablished RDF predicate mappingsError handling distinguishes network, auth, and validation issuesChanges to `pod-table.ts` consider impact on type inference8. Reference Examples
Direct users to example files for complete patterns:
`examples/01-server-setup.ts`: Pod creation and server setup`examples/02-authentication.ts`: Session management`examples/03-basic-usage.ts`: CRUD operations and queries9. Provide Code References
When referencing specific functionality, use the pattern `file_path:line_range` to help users navigate:
Session management: `src/core/pod-dialect.ts`SPARQL generation: `src/core/ast-to-sparql-v2.ts`Conflict handling: `src/core/conflict-resolution.ts`Key Dependencies Context
**drizzle-orm**: Core ORM functionality and AST system**@comunica/query-sparql-solid**: SPARQL execution engine**@inrupt/solid-client**: Solid Protocol operations**sparqljs**: SPARQL query parsing and generation**n3**: RDF/Turtle parsing and serialization**zod**: Runtime type validationTesting Requirements
Integration tests require Community Solid Server (CSS) running locallyUse `yarn server:start` to launch CSSUse `yarn server:setup` to create preset test accountsTest data is cleaned with `yarn clean:only`Important Notes
This is a TypeScript project with strict mode enabledRDF operations use established predicate mappings from table schemasSPARQL generation is complex - test thoroughly when modifying AST conversionAuthentication and session management are critical for Pod operationsConflict resolution is essential for multi-user scenariosExample Usage
**Basic CRUD with Drizzle Solid:**
```typescript
import { drizzle } from 'drizzle-orm/pod';
import { podTable } from 'drizzle-solid';
import { Session } from '@inrupt/solid-client-authn-node';
const session = new Session();
await session.login(/* ... */);
const usersTable = podTable('users', {
id: 'string',
name: 'string',
email: 'string',
createdAt: 'date'
});
const db = drizzle(session, {
schema: { users: usersTable }
});
// Insert
await db.insert(usersTable).values({
id: '1',
name: 'Alice',
email: '[email protected]',
createdAt: new Date()
});
// Select
const allUsers = await db.select().from(usersTable);
```