orm-playground
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

ORM Playground

A lightweight ORM playground for PostgreSQL that helps you explore and understand your database schema.

Installation

npm install orm-playground

Usage

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

Package Sidebar

Install

npm i orm-playground

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

10.3 kB

Total Files

5

Last publish

Collaborators

  • karthik_nadar