orm-playground
v0.1.0
Published
A lightweight ORM playground for PostgreSQL
Maintainers
Readme
ORM Playground
A lightweight ORM playground for PostgreSQL that helps you explore and understand your database schema.
Installation
npm install orm-playgroundUsage
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();API Reference
initPool(connectionUrl: string): Pool
Initializes a new PostgreSQL connection pool.
getTables(): Promise<string[]>
Returns a list of all tables in the database.
getTableSchema(tableName: string): Promise<ColumnInfo[]>
Returns the schema information for a specific table.
disconnect(): Promise<void>
Closes the database connection pool.
License
MIT
