0.1.4 • Published 4 years ago

metalize v0.1.4

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Features

Documentation

Getting Started

npm install metalize pg       # postgres
npm install metalize mysql2   # mysql

Do not use quotes in the name of the object. Metalize automatically adds them when needed

const Metalize = require('metalize');

const metalize = new Metalize({
  dialect: 'postgres', // one of [ 'postgres', 'mysql' ]
  connectionConfig: {
    host: '127.0.0.1',
    port: 5432,
    // other connection options for dialect
  },
});

metalize
  .find({
    tables: ['public.users', 'public.events'],
    sequences: ['public.usersSeq'], // only for 'postgres' dialect
  })
  .then((result) => console.log(result));

/**
Result {
  'tables': Map {
    'public.users' => {
        columns: [ ... ],
        primaryKey: { ... },
        foreignKeys: [ ... ],
        unique: [ ... ],
        indexes: [ ... ],
        checks: [ ... ]
    },
    'public.events' => { ... }
  }
  'sequences': Map {
    'public.usersSeq' => {
      start: '1',
      min: '1',
      max: '9999',
      increment: '1',
      cycle: true,
    }
  }
}
*/

Using an existing connection

const Metalize = require('metalize');
const { Client } = require('pg');

const client = new Client({
  host: '127.0.0.1',
  port: 5432,
  database: 'postgres',
  user: 'postgres',
  password: 'postgres',
});

client.connect();

/**
 * or using 'mysql' dialect
 * @example
 * const { createConnection } = require('mysql2/promise');
 * const client = await createConnection(...)
 */

const metalize = new Metalize('postgres');

metalize
  .find({ tables: ['public.users'] }, { client })
  .then((result) => console.log(result));

/**
 * A new connection will not be opened
 * Instead, the connection from the 'options' will be used
 */

License

Metalize is open source software licensed as MIT.

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago