A lightweight ORM playground for PostgreSQL that helps you explore and understand your database schema.
npm install orm-playground
const { initPool, getTables, getTableSchema, disconnect } = require('orm-playground');
// Initialize the database connection
const pool = initPool('postgresql://user:password@localhost:5432/dbname');
// Get all tables in the database
async function listTables() {
try {
const tables = await getTables();
console.log('Available tables:', tables);
} catch (error) {
console.error('Error:', error);
}
}
// Get schema for a specific table
async function getSchema(tableName) {
try {
const schema = await getTableSchema(tableName);
console.log(`Schema for ${tableName}:`, schema);
} catch (error) {
console.error('Error:', error);
}
}
// Don't forget to disconnect when done
async function cleanup() {
await disconnect();
}
// Example usage
async function main() {
await listTables();
await getSchema('users');
await cleanup();
}
main();
Initializes a new PostgreSQL connection pool.
Returns a list of all tables in the database.
Returns the schema information for a specific table.
Closes the database connection pool.
MIT