Overview
The Duckling WebSocket SDK provides a high-performance TypeScript client for querying DuckDB with 5-15ms latency (vs 50-100ms for HTTP). This guide shows you how to integrate it into your Node.js applications.Installation
Basic Usage
Simple Query
The SDK auto-connects on first query - no need to callconnect() manually:
TypeScript Type Safety
Define your schema types for full IntelliSense support:Advanced Features
Parallel Queries
Execute multiple queries concurrently for 3-5x faster performance:Pagination
Automatic LIMIT and OFFSET handling:Batch Queries with Error Handling
Handle individual query failures gracefully:Multi-Database Support
Connect to multiple databases simultaneously:Configuration Options
Auto-Reconnection
Event Handling
Listen to connection lifecycle events:Connection Monitoring
Check connection status and statistics:Performance Tips
Latency Comparison:
- HTTP API: 50-100ms per query
- WebSocket SDK: 5-15ms per query
- 10x faster for real-time dashboards
Throughput Benchmarks
| Method | Throughput | Use Case |
|---|---|---|
| Sequential | ~20-50 queries/sec | Simple queries |
| Parallel (single connection) | ~500-1,000 queries/sec | Batch processing |
| Connection Pool | ~2,000-5,000 queries/sec | High concurrency |
| Maximum Capacity | 10,000+ queries/sec | Enterprise scale |
Best Practices
- Reuse connections: Create one client per database and reuse it
- Use parallel queries: Batch multiple queries with
queryBatch() - Enable auto-ping: Keeps connection alive (enabled by default)
- Close when done: Always call
client.close()to free resources - Handle errors: Wrap queries in try-catch blocks
- Use TypeScript types: Define schema interfaces for type safety
Complete Example
Here’s a complete Express.js API endpoint using the SDK:Next Steps
- Real-Time Dashboards - Build live dashboards with WebSocket streaming
- Microservices Architecture - Integrate Duckling into microservices
- API Reference - Complete API documentation