Skip to main content

@dbml/connector

NPM

This package is responsible for connecting to a database on your local environment and fetch its schema information.

Supported Databases

  • PostgreSQL
  • MySQL
  • MSSQL

Prerequisites

  • Nodejs version 18.0.0 or higher.

Installation

npm install @dbml/connector

APIs

connector

const { connector } = require('@dbml/connector');

connector.fetchSchemaJson(connection, databaseType)

  • Arguments:

    • {string} connection
    • {'postgres'|'mssql'|'mysql'|'snowflake'|'bigquery'} databaseType
  • Returns:

    • {DatabaseSchema} schemaJson
  • Usage: Generate DatabaseSchema object directly from a database.

const { connector } = require('@dbml/connector');

const connection = 'postgresql://dbml_user:dbml_pass@localhost:5432/dbname?schemas=public';
const databaseType = 'postgres';

const schemaJson = await connector.fetchSchemaJson(connection, databaseType);
info

The type definition of DatabaseSchema object can be found here.