skibbadb-express
v1.0.8
Published
Express.js integration plugin for SkibbaDB with automatic CRUD operations, pagination, filtering, and security features
Maintainers
Readme
SkibbaDB Express
A powerful Express.js wrapper for SkibbaDB that automatically generates REST APIs with built-in security, validation, pagination, and filtering capabilities.
Features
- 🚀 Automatic REST API Generation - Transform SkibbaDB collections into REST endpoints
- 🔒 Built-in Security - XSS protection, SQL injection prevention, input sanitization
- 📄 Pagination Support - Page-based and offset-based pagination
- 🔍 Advanced Filtering - Multiple filter operators and text search
- 📊 Sorting - Flexible sorting with multiple fields
- 🎣 Hooks System - Customize behavior with before/after hooks
- ✅ Automatic Validation - Zod schema validation on all operations
- 🛡️ Error Handling - Comprehensive error responses with detailed messages
- 📚 OpenAPI Specs - Automatic generation of OpenAPI documentation
Quick Start
Installation
bun add skibbadb-express
# or
npm install skibbadb-expressBasic Usage
import express from 'express';
import { Database } from 'skibbadb';
import { createSkibbaExpress } from 'skibbadb-express';
import { z } from 'zod';
const app = express();
const db = new Database('sqlite:example.db');
const skibba = createSkibbaExpress(app, db);
// Define your schema
const userSchema = z.object({
id: z.string(),
name: z.string(),
email: z.string().email(),
age: z.number().int().positive(),
role: z.enum(['user', 'admin']).default('user'),
});
const users = db.collection('users', userSchema);
// Register collection with REST endpoints
skibba.useCollection(users, {
GET: {},
POST: {},
PUT: {},
DELETE: {},
basePath: '/api/users',
});
app.listen(3000, () => {
console.log('Server running on http://localhost:3000');
});This automatically creates these endpoints:
GET /api/users- List users with pagination and filteringGET /api/users/:id- Get user by IDPOST /api/users- Create new userPUT /api/users/:id- Update userDELETE /api/users/:id- Delete user
An OpenAPI 3 document is generated automatically. Retrieve it with
skibba.getOpenAPISpec() or serve it via skibba.serveOpenAPISpec().
Pagination and Filtering
Pagination
# Page-based pagination
GET /api/users?page=1&limit=10
# Offset-based pagination
GET /api/users?limit=20&offset=40Filtering
# Equality filters
GET /api/users?role=admin&isActive=true
# Comparison filters
GET /api/users?age_gt=18&age_lt=65
# Text search
GET /api/users?name_like=%john%
# Array filters
GET /api/users?role_in=admin&role_in=moderatorSorting
# Sort ascending (default)
GET /api/users?orderBy=name
# Sort descending
GET /api/users?orderBy=age&sort=descCombined Example
GET /api/users?page=2&limit=15&role=admin&age_gte=25&orderBy=name&sort=ascSee PAGINATION_FILTERING_EXAMPLES.md for more detailed examples.
Documentation
- Complete Tutorial - Comprehensive guide with examples
- Pagination & Filtering Examples - Detailed API usage examples
- Testing Guide - How to test your APIs
- Automatic OpenAPI spec generation via
getOpenAPISpec()
Installation
bun installDevelopment
# Run in development mode
bun run dev
# Run tests
bun test
# Run security tests
bun run test:securityThis project was created using bun init in bun v1.1.38. Bun is a fast all-in-one JavaScript runtime.
