# ormur

> A simple, sane and modern ORM library for Node.js

Latest version **0.2.0** (published 2016-03-28) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2016-03-28 |
| First published | 2016-03-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| Author | Haukur Páll Hallvarðsson |
| Maintainers | haukur |
| Keywords | ORM, model, query, database, Postgres, Knex |

## Links

- npm: https://www.npmjs.com/package/ormur
- Repository: https://github.com/hph/ormur
- Homepage: https://github.com/hph/ormur#readme
- Issues: https://github.com/hph/ormur/issues
- npm.io page: https://npm.io/package/ormur

## Dependencies (4)

- [knex](https://npm.io/package/knex.md) ^0.10.0
- [lodash](https://npm.io/package/lodash.md) ^4.6.1
- [bluebird](https://npm.io/package/bluebird.md) ^3.3.4
- [inflection](https://npm.io/package/inflection.md) ^1.8.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2016-03-28
- 0.1.0 — 2016-03-26

## README

# Ormur

[![Package Version](https://img.shields.io/npm/v/ormur.svg)](https://www.npmjs.com/package/ormur) [![Build Status](https://travis-ci.org/hph/ormur.svg?branch=master)](https://travis-ci.org/hph/ormur) [![Test Coverage](https://img.shields.io/codecov/c/github/hph/ormur.svg)](https://codecov.io/github/hph/ormur?branch=master) [![License](https://img.shields.io/npm/l/ormur.svg)](https://tldrlegal.com/license/mit-license)

> A simple, sane & modern ORM library for Node.js

## Features

- High extensibility and behaviour customization via inheritance.
- Schema validation and custom field validations.
- High-level query interface along with a [Knex](http://knexjs.org/) instance for custom queries.
- Use promises instead of callbacks to interact with the database.
- Default values and value transformations before creating records.
- Automatic `snake_case` (for the database) and `camelCase` (for JavaScript) handling.
- Safe JSON serialization by omitting private fields.

And much more - see the example below to get an idea.

## Install

Requires Node.js v4.0.0 or higher.

    npm install ormur

## Examples

Check out the [basic example](https://github.com/hph/ormur/tree/master/example/basic)
for an example of a minimal base model and an example model inheriting from it.

For an example of how you may share schema between models, check the [advanced
example](https://github.com/hph/ormur/tree/master/example/advanced).

The `User` model defined in the above examples could be used like this,
assuming that the relevant database table exists:

```javascript
const User = require('./example/basic/user');

// Create an instance
const user = new User({ name: 'Hawk', email: 'test@example.com', password: 'password' });

// Persist it to the database
user.save().then(user => {
  console.log(`User ${user.name} with id ${user.id} saved.`);
});

// Find users with the name "Hawk"
User.where({ name: 'Hawk' }).then(users => {
  // Array of User instances.
  console.log(users);
});

// Find a user by its primary key and remove it from the database
User.find(1).then(user => user.destroy());

// Or, maybe more succintly
User.destroy(1);
```

## API

Documentation pending.

### Static methods

- `Ormur.find` - Find row by primary key.
- `Ormur.where` - Find rows by attributes.
- `Ormur.create` - Create row with attributes.
- `Ormur.destroy` - Remove row by primary key.

### Instance methods

- `Ormur#validate` - Validate attributes.
- `Ormur#save` - Insert row into database with attributes from instance.
- `Ormur#update` - Update existing row in database with attributes from instance.
- `Ormur#destroy` - Remove row from database by primary key of instance.
- `Ormur#setDefaults` - Set default values to instance attributes.
- `Ormur#merge` - Merge two objects (inheritance helper).

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