Getting Started
This guide will help you integrate Tabula Lens into your existing full-stack application. Tabula Lens provides a secure, interactive database viewer that works with your current database, backend framework, and React frontend.
Prerequisites
Section titled “Prerequisites”Before you begin, ensure you have:
- An existing full-stack application with:
- A PostgreSQL, MySQL, SQLite, or SQL Server database
- A backend server (Express, Fastify, Koa, Hono, etc.)
- A React frontend application
- Node.js 18+ installed
- npm or pnpm package manager
What You’ll Add
Section titled “What You’ll Add”You’ll add:
- A backend API endpoint that securely queries your database
- A React component that displays an interactive database viewer
Step 1: Install Backend Package
Section titled “Step 1: Install Backend Package”Install the Tabula Lens backend package in your backend project:
npm i @tabula-lens/nodepnpm add @tabula-lens/nodeyarn add @tabula-lens/nodeAlso install the database driver for your database:
# # PostgreSQLnpm i pg# # PostgreSQLpnpm add pg# # PostgreSQLyarn add pg# # MySQL/MariaDBnpm i mysql2# # MySQL/MariaDBpnpm add mysql2# # MySQL/MariaDByarn add mysql2# # SQLitenpm i better-sqlite3# # SQLitepnpm add better-sqlite3# # SQLiteyarn add better-sqlite3# # SQL Servernpm i tedious# # SQL Serverpnpm add tedious# # SQL Serveryarn add tediousStep 2: Add Backend API Endpoint
Section titled “Step 2: Add Backend API Endpoint”Add an API endpoint to your backend server using one of the provided middleware adapters.
Express Example
Section titled “Express Example”import express from 'express';import TabulaLens, { expressAdapter } from '@tabula-lens/node';
const app = express();
// Initialize Tabula Lens with your database connectionconst tabulaLens = new TabulaLens({ url: process.env.DATABASE_URL, // type is auto-detected from the connection string});
// Add the Tabula Lens middlewareapp.use('/api/tabula-lens', expressAdapter(tabulaLens));Fastify Example
Section titled “Fastify Example”import Fastify from 'fastify';import TabulaLens, { fastifyAdapter } from '@tabula-lens/node';
const fastify = Fastify();
// Initialize Tabula Lensconst tabulaLens = new TabulaLens({ url: process.env.DATABASE_URL, // type is auto-detected from the connection string});
// Add the Tabula Lens routefastify.route({ method: 'GET', url: '/api/tabula-lens', handler: fastifyAdapter(tabulaLens),});Koa Example
Section titled “Koa Example”import Koa from 'koa';import TabulaLens, { koaAdapter } from '@tabula-lens/node';
const app = new Koa();
// Initialize Tabula Lensconst tabulaLens = new TabulaLens({ url: process.env.DATABASE_URL, // type is auto-detected from the connection string});
// Add the Tabula Lens middlewareapp.use(koaAdapter(tabulaLens));Step 3: Install Frontend Package
Section titled “Step 3: Install Frontend Package”Install the Tabula Lens React package in your frontend project:
npm i @tabula-lens/reactpnpm add @tabula-lens/reactyarn add @tabula-lens/reactStep 4: Add Database Viewer Component
Section titled “Step 4: Add Database Viewer Component”Add the DatabaseViewer component to your React application.
import { DatabaseViewer } from '@tabula-lens/react';
function App() { return ( <DatabaseViewer path="/api/tabula-lens" initialTable="users" /> );}Step 5: Add Authentication (Optional)
Section titled “Step 5: Add Authentication (Optional)”To secure your API endpoint, add authentication using your existing auth system.
Backend Authentication
Section titled “Backend Authentication”Add authentication middleware before the Tabula Lens adapter. Here’s a simple API key example:
// Express example with API key authenticationconst authenticate = (req, res, next) => { const apiKey = req.headers['x-api-key']; if (apiKey === process.env.API_KEY) { next(); } else { res.status(401).json({ error: 'Unauthorized' }); }};
// Apply authentication before the Tabula Lens adapterapp.use('/api/tabula-lens', authenticate, expressAdapter(tabulaLens));You can also integrate with your existing authentication system (JWT, session-based, OAuth, etc.).
Frontend Authentication
Section titled “Frontend Authentication”Pass authentication headers to the DatabaseViewer component:
<DatabaseViewer path="/api/tabula-lens" initialTable="users" getAuthHeaders={async () => ({ 'X-API-Key': 'your-secret-api-key' // or 'Authorization': `Bearer ${token}` })}/>Step 6: Customize the Viewer
Section titled “Step 6: Customize the Viewer”You can customize the DatabaseViewer component with various options:
<DatabaseViewer path="/api/tabula-lens" initialTable="users" // Enable table selector tableSelector="dropdown" // Add filtering filterPosition="top" // Add pagination paginationPosition="bottom" pageSize={10} // Custom styling styles={{ container: { padding: '1rem' } }}/>See the Frontend Implementation guide for more customization options.
Troubleshooting
Section titled “Troubleshooting”Database Connection Issues
Section titled “Database Connection Issues”Problem: Connection refused or database does not exist
Solution:
- Ensure your database is running
- Verify your
DATABASE_URLenvironment variable is correct - Check that the database exists and is accessible
- Verify your database credentials
CORS Errors
Section titled “CORS Errors”Problem: Frontend can’t connect to backend
Solution:
- Ensure CORS is configured in your backend server
- Check that your frontend URL is allowed in CORS settings
- Verify both servers are running on the correct ports
- Check your browser console for specific CORS errors
Empty Results
Section titled “Empty Results”Problem: No data displayed in the viewer
Solution:
- Verify the table name in the
pathprop matches your database - Check that the table has data
- Inspect browser console for errors
- Check the Network tab for failed API requests
- Verify the API endpoint is returning data correctly
Authentication Failures
Section titled “Authentication Failures”Problem: 401 Unauthorized errors
Solution:
- Verify authentication credentials match between frontend and backend
- Check that the header name is correct (e.g.,
X-API-Key,Authorization) - Ensure authentication middleware is properly configured
- Check that your auth system is working correctly
Framework-Specific Issues
Section titled “Framework-Specific Issues”If you’re using a framework not shown in the examples, check the Backend Architecture and Frontend Architecture pages for framework-specific guidance.
Next Steps
Section titled “Next Steps”Now that you’ve integrated Tabula Lens into your application:
- Learn about Frontend Implementation for advanced patterns and customization
- Explore Backend Implementation for framework-specific configurations
- Understand the Architecture to learn about the HTTP API contract and interchangeability
- Read about the Design System for styling and theming options
- Check the Backend Architecture for the full list of supported frameworks