# objection-table-name

> ActiveRecord-style objection.js plugin to auto-fill tableName

Latest version **2.0.2** (published 2021-12-29) · LGPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install objection-table-name
pnpm add objection-table-name
yarn add objection-table-name
bun add objection-table-name
```

## 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 | 2.0.2 |
| Published | 2021-12-29 |
| First published | 2019-07-23 |
| Weekly downloads | 0 |
| License | LGPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 12.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Jane Jeon |
| Maintainers | janejeon |
| Keywords | objection, objection.js, class, tablename, activerecord, plugin |

## Links

- npm: https://www.npmjs.com/package/objection-table-name
- Repository: https://github.com/JaneJeon/objection-table-name
- Homepage: https://github.com/JaneJeon/objection-table-name#readme
- Issues: https://github.com/JaneJeon/objection-table-name/issues
- npm.io page: https://npm.io/package/objection-table-name

## Dependencies (3)

- [pluralize](https://npm.io/package/pluralize.md) ^8.0.0
- [lodash.memoize](https://npm.io/package/lodash.memoize.md) ^4.1.2
- [lodash.camelcase](https://npm.io/package/lodash.camelcase.md) ^4.3.0

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 2.0.2 (latest) — 2021-12-29
- 2.0.1 — 2021-12-20
- 2.0.0 — 2021-12-20
- 1.2.5 — 2021-06-11
- 1.2.4 — 2021-05-10
- 1.2.3 — 2021-01-23
- 1.2.2 — 2020-07-11
- 1.2.1 — 2020-01-06
- 1.2.0 — 2020-01-03
- 1.1.1 — 2019-11-17
- 1.1.0 — 2019-10-08
- 1.0.8 — 2019-09-05
- 1.0.7 — 2019-09-05
- 1.0.6 — 2019-09-04
- 1.0.5 — 2019-09-03
- … 5 more at https://npm.io/package/objection-table-name/versions

## README

# objection-table-name

[![CircleCI](https://circleci.com/gh/JaneJeon/objection-table-name/tree/master.svg?style=shield)](https://circleci.com/gh/JaneJeon/objection-table-name/tree/master)
[![codecov](https://codecov.io/gh/JaneJeon/objection-table-name/branch/master/graph/badge.svg)](https://codecov.io/gh/JaneJeon/objection-table-name)
[![Version](https://img.shields.io/npm/v/objection-table-name)](https://www.npmjs.com/package/objection-table-name)
[![Downloads](https://img.shields.io/npm/dt/objection-table-name)](https://www.npmjs.com/package/objection-table-name)
[![Docs](https://img.shields.io/badge/docs-github-blue)](https://janejeon.github.io/objection-table-name)

> Enjoy objection-tablename? Check out my other objection plugins: [objection-hashid](https://github.com/JaneJeon/objection-hashid) and [objection-authorize](https://github.com/JaneJeon/objection-authorize)!

## What To Solve

```js
class NodeModule extends Model {
  static get tableName() {
    return 'nodeModules' // you type it on every model
  }
}
```

what about:

```js
class NodeModule extends Model {}
console.log(NodeModule.tableName)
// => nodeModules
```

## Installation

`$ npm install objection-table-name`

## Usage

```js
const { Model } = require('objection')
const tableName = require('objection-table-name')

// The common way is:
// - make this is as your base class

// BaseModel.js
class BaseModel extends tableName()(Model) {}

// TransactionDetail.js
class TransactionDetail extends BaseModel {}
console.log(TransactionDetail.tableName)
// => transactionDetails
```

You can define your own mapper

```js
function upperFirst([s, ...rest]) {
  return [s.toUpperCase(), ...rest].join('')
}

class BaseModel extends TableNamer({
  caseMapper: upperFirst
})(Model) {}

class foo_Bar extends BaseModel {}
console.log(foo_Bar.tableName)
// => Foo_Bar
```

[Lodash](https://lodash.com/docs/) provides some already defined caseMappers. You can use it too.

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