# objection-gen-cli

> An objection models generator

Latest version **0.0.7** (published 2020-08-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install objection-gen-cli
pnpm add objection-gen-cli
yarn add objection-gen-cli
bun add objection-gen-cli
```

Provides the command `objection-cli`.

## Health

**Score 35/100 (D)** — status: abandoned.

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

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2020-08-11 |
| First published | 2020-08-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 27.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Marc Deletang |
| Maintainers | marc-d |
| Keywords | node, objection, model, code generation, generator |

## Links

- npm: https://www.npmjs.com/package/objection-gen-cli
- Repository: https://github.com/MarcDeletang/objection-gen-cli
- Homepage: https://github.com/MarcDeletang/objection-gen-cli#readme
- npm.io page: https://npm.io/package/objection-gen-cli

## Dependencies (5)

- [lodash](https://npm.io/package/lodash.md) ^4.17.19
- [prompts](https://npm.io/package/prompts.md) ^2.3.2
- [fs-extra](https://npm.io/package/fs-extra.md) ^9.0.1
- [@types/lodash](https://npm.io/package/@types/lodash.md) ^4.14.159
- [@types/prompts](https://npm.io/package/@types/prompts.md) ^2.4.0

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 0.0.7 (latest) — 2020-08-11
- 0.0.6 — 2020-08-09
- 0.0.5 — 2020-08-09
- 0.0.3 — 2020-08-09
- 0.0.2 — 2020-08-08
- 0.0.1 — 2020-08-08

## README

[![Known Vulnerabilities](https://snyk.io/test/github/MarcDeletang/objection-gen-cli/badge.svg?targetFile=package.json)](https://snyk.io/test/github/MarcDeletang/objection-gen-cli?targetFile=package.json)
[![Maintainability](https://api.codeclimate.com/v1/badges/5feb4d0abeeb8a8b319e/maintainability)](https://codeclimate.com/github/MarcDeletang/objection-gen-cli/maintainability)
[![codecov](https://codecov.io/gh/MarcDeletang/objection-gen-cli/branch/master/graph/badge.svg)](https://codecov.io/gh/MarcDeletang/objection-gen-cli)
[![Build Status](https://travis-ci.org/MarcDeletang/objection-gen-cli.svg?branch=master)](https://travis-ci.org/MarcDeletang/objection-gen-cli)

# objection-gen-cli

Objection model generator

This package allow you to generate objection model class.

<details>
  <summary>Like this one:</summary>
  
```
import { Model } from 'objection';

export class User extends Model {
    public id: number;
    public firstName?: string;

    static get tableName() {
        return 'users';
    }

    static get relationMappings() {
        const { Product } = require('./product');

        return {
            children: {
                relation: Model.HasManyRelation,
                modelClass: User,
                join: {
                    from: 'users.id',
                    to: 'users.parent_id'
                }
            },
            parent: {
                relation: Model.HasOneRelation,
                modelClass: User,
                join: {
                    from: 'users.parent_id',
                    to: 'users.id'
                }
            },
            userProducts: {
                relation: Model.ManyToManyRelation,
                modelClass: Product,
                join: {
                    from: 'users.id',
                    through: {
                        from: 'user_product.user_id',
                        to: 'user_product.product_id'
                    },
                    to: 'products.id'
                }
            },
        };
    }

}
```
</details>

## Install as dev dependency:

```
yarn add -D objection-gen-cli
```

Or:

```
npm install -D objection-gen-cli
```

## Usage:

```
npx objection-cli
```

Or (after install):

```
yarn run objection-cli
```

## How does it work ?

This script will generate a prompt that will guide you in building your models.

Note: The models generated should have a readable look. I dont plan to allow to configure the syntax (quote, commas ...). Your linter should take care of that.

## Extend it:

All main methods should be exposed so you can use them, but at the moment it's not really customisable.


## Things left to do:

- Testing
- Shortcut for id field generation
- Model update during prompts
- Add cli argument to avoid questions (folder name, extention, id ...)
- Add relations to properties (need to resolve circular deps first)
- Load existing models from the folder to allow relations to them (might be tricky)
- Generate a basic knex migration file (might be tricky)
- Remove remove all dependencies but prompts

If you have any idea of things you would like to add, feel free to fill an issue !

I hope you enjoy it :)

## Other

[Objection relations docs](https://vincit.github.io/objection.js/guide/relations.html)

Thanks a lot for making objection guys, it's an awesome tool !

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