# metalize

> Node.js tool for easy work with database metadata

Latest version **0.1.4** (published 2020-07-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install metalize
pnpm add metalize
yarn add metalize
bun add metalize
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2020-07-16 |
| First published | 2019-09-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8.10 |
| Dependencies | 0 |
| Unpacked size | 32.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Andrew Vereshchak |
| Maintainers | multum |
| Keywords | mysql, postgres, metalize, database, metadata, structure |

## Links

- npm: https://www.npmjs.com/package/metalize
- Repository: https://github.com/multum/metalize
- Homepage: https://multum.github.io/metalize
- Issues: https://github.com/multum/metalize/issues
- npm.io page: https://npm.io/package/metalize

## Alternatives

- [@libsql/sqlite3](https://npm.io/package/@libsql/sqlite3.md) — 39.8K weekly downloads
- [@fortemi/core](https://npm.io/package/@fortemi/core.md) — 461 weekly downloads
- [cdb-converter](https://npm.io/package/cdb-converter.md) — 341 weekly downloads
- [@uplo/adapter-prisma](https://npm.io/package/@uplo/adapter-prisma.md) — 75 weekly downloads
- [typeorm-aios](https://npm.io/package/typeorm-aios.md) — 30 weekly downloads

## Recent versions

- 0.1.4 (latest) — 2020-07-16
- 0.1.3 — 2020-05-02
- 0.1.2 — 2020-05-02
- 0.1.1 — 2020-04-17
- 0.1.0 — 2020-04-05
- 0.0.7 — 2020-03-20
- 0.0.6 — 2020-02-27
- 0.0.5 — 2020-02-11
- 0.0.4 — 2020-01-13
- 0.0.3 — 2019-10-25
- 0.0.2 — 2019-10-01
- 0.0.1 — 2019-09-12

## README

<br/>
<br/>

<p align='center'>
  <img src='https://multum.github.io/metalize/logo.svg' alt='metalize' width='500px'>
</p>
<p align='center'>Node.js tool for easy work with <strong>database metadata</strong></p>

<p align='center'>
  <img src='https://github.com/multum/metalize/workflows/Lint%20and%20test/badge.svg' alt=''/>
  <a href='https://github.com/multum/metalize/blob/master/LICENSE'><img src='https://img.shields.io/npm/l/metalize.svg?style=flat' alt=''></a>
  <a href='https://www.npmjs.com/package/metalize'><img src='https://img.shields.io/npm/v/metalize.svg?style=flat' alt=''></a>
  <img src='https://img.shields.io/codecov/c/github/multum/metalize.svg?style=flat' alt=''>
</p>

<br/>

## Features

- Fully tested
- Fully documented
- **PostgreSQL** and **MySQL** dialects
- [**Tables**](https://multum.github.io/metalize/#/metadata/table)
  - Detailed [column](https://multum.github.io/metalize/#/metadata/column) metadata
  - Multi-column constraints
  - [Indexes](https://multum.github.io/metalize/#/metadata/index)
- [**Sequences**](https://multum.github.io/metalize/#/metadata/sequence)

## Documentation

- [Documentation](https://multum.github.io/metalize/#/)
- [Contributing](https://github.com/multum/metalize/blob/master/CONTRIBUTING.md)

## Getting Started

```bash
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

```javascript
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

```javascript
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](https://github.com/multum/metalize/blob/master/LICENSE).

---
_Source: https://npm.io/package/metalize · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
