# sequelize-logger

> A very simple tool for logging sequelize data, including whole tables and queries

Latest version **1.0.0** (published 2022-08-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install sequelize-logger
pnpm add sequelize-logger
yarn add sequelize-logger
bun add sequelize-logger
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-08-14 |
| First published | 2022-08-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Simon Haines |
| Maintainers | nimonian |
| Keywords | sequelize, logging |

## Links

- npm: https://www.npmjs.com/package/sequelize-logger
- Repository: https://github.com/nimonian/sequelize-logger
- Issues: https://github.com/nimonian/sequelize-logger/issues
- npm.io page: https://npm.io/package/sequelize-logger

## Dependencies (1)

- [sequelize](https://npm.io/package/sequelize.md) ^6.21.3

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2022-08-14

## README

# Sequelize Logger

A very basic utility for logging Sequelize data. This package can log multiple tables, the entire database (including junction tables), and individual queries. It saves a few lines of code.

![Some example tables](./example.png)

## Running the example

If you wish to run `example.js`, you need to run
```bash
npm install sqlite3 sequelize
```

## Functions

Suppose we have the following schema:

```js
// initialise the database
const db = new Sequelize({
  storage: ':memory:',
  dialect: 'sqlite',
  logging: false
})

// create some models
const Character = db.define('Character', {
  name: { type: DataTypes.STRING },
  age: { type: DataTypes.INTEGER }
})

const Race = db.define('Race', {
  name: { type: DataTypes.STRING }
})

// define some associations
Race.belongsToMany(Character, { through: 'Character_Race' })
Character.belongsToMany(Race, { through: 'Character_Race' })
```

### Log a table

```js
// Pass in a model and its table will be logged
await logTable(Character)
// If model name is used, sequelize instance must be passed
// If this is omitted, a warning will be logged
await logTable('Race', db)
// You generally don't have the junction table model at hand, but it can be
// logged like so:
await logTable(db.models.Character_Race)
```

### Log multiple tables

```js
// Can log the tables for multiple models
await logTables(Character, Race)
// If any model is given by its name, sequelize instance must be passed
await logTables('Character', Race, db)
```
### Log all tables

```js
// All tables associated with the instance are logged
// This includes junction tables
await logAllTables(db)
```

### Log query

```js
// Can handle single entry returns as well as arrays
await logQuery(Character.findOne())
// Optional text appears above log
await logQuery(Character.findAll(), { text: 'All characters' })
// Table can't deal with nested objects so it can be turned off
await logQuery(Race.findOne({ include: Character }))
```

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