Skip to content

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.

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

You’ll add:

  • A backend API endpoint that securely queries your database
  • A React component that displays an interactive database viewer

Install the Tabula Lens backend package in your backend project:

Terminal window
npm i @tabula-lens/node

Also install the database driver for your database:

Terminal window
# # PostgreSQL
npm i pg
Terminal window
# # MySQL/MariaDB
npm i mysql2
Terminal window
# # SQLite
npm i better-sqlite3
Terminal window
# # SQL Server
npm i tedious

Add an API endpoint to your backend server using one of the provided middleware adapters.

import express from 'express';
import TabulaLens, { expressAdapter } from '@tabula-lens/node';
const app = express();
// Initialize Tabula Lens with your database connection
const tabulaLens = new TabulaLens({
url: process.env.DATABASE_URL,
// type is auto-detected from the connection string
});
// Add the Tabula Lens middleware
app.use('/api/tabula-lens', expressAdapter(tabulaLens));
import Fastify from 'fastify';
import TabulaLens, { fastifyAdapter } from '@tabula-lens/node';
const fastify = Fastify();
// Initialize Tabula Lens
const tabulaLens = new TabulaLens({
url: process.env.DATABASE_URL,
// type is auto-detected from the connection string
});
// Add the Tabula Lens route
fastify.route({
method: 'GET',
url: '/api/tabula-lens',
handler: fastifyAdapter(tabulaLens),
});
import Koa from 'koa';
import TabulaLens, { koaAdapter } from '@tabula-lens/node';
const app = new Koa();
// Initialize Tabula Lens
const tabulaLens = new TabulaLens({
url: process.env.DATABASE_URL,
// type is auto-detected from the connection string
});
// Add the Tabula Lens middleware
app.use(koaAdapter(tabulaLens));

Install the Tabula Lens React package in your frontend project:

Terminal window
npm i @tabula-lens/react

Add the DatabaseViewer component to your React application.

import { DatabaseViewer } from '@tabula-lens/react';
function App() {
return (
<DatabaseViewer
path="/api/tabula-lens"
initialTable="users"
/>
);
}

To secure your API endpoint, add authentication using your existing auth system.

Add authentication middleware before the Tabula Lens adapter. Here’s a simple API key example:

// Express example with API key authentication
const 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 adapter
app.use('/api/tabula-lens', authenticate, expressAdapter(tabulaLens));

You can also integrate with your existing authentication system (JWT, session-based, OAuth, etc.).

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}`
})}
/>

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.

Problem: Connection refused or database does not exist

Solution:

  • Ensure your database is running
  • Verify your DATABASE_URL environment variable is correct
  • Check that the database exists and is accessible
  • Verify your database credentials

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

Problem: No data displayed in the viewer

Solution:

  • Verify the table name in the path prop 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

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

If you’re using a framework not shown in the examples, check the Backend Architecture and Frontend Architecture pages for framework-specific guidance.

Now that you’ve integrated Tabula Lens into your application: