# jsorm

> Javascript ORM

Latest version **1.3.22** (published 2018-11-30) · MIT license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.22 |
| Published | 2018-11-30 |
| First published | 2017-04-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 6 |
| Unpacked size | 1007.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Lee Richmond |
| Maintainers | richmolj, wadetandy |

## Links

- npm: https://www.npmjs.com/package/jsorm
- Homepage: https://github.com/jsonapi-suite/jsorm
- npm.io page: https://npm.io/package/jsorm

## Dependencies (6)

- [debug](https://npm.io/package/debug.md) ^4.0.0
- [tslib](https://npm.io/package/tslib.md) ^1.8.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.10
- [inflected](https://npm.io/package/inflected.md) ^2.0.3
- [lodash-es](https://npm.io/package/lodash-es.md) ^4.17.4
- [eventbusjs](https://npm.io/package/eventbusjs.md) ^0.2.0

## Recent versions

- 1.3.22 (latest) — 2018-11-30
- 1.0.0-beta5 (beta) — 2018-02-13
- 1.3.21 — 2018-09-19
- 1.3.20 — 2018-08-24
- 1.3.18 — 2018-08-23
- 1.3.17 — 2018-08-21
- 1.3.16 — 2018-08-21
- 1.3.15 — 2018-08-21
- 1.3.14 — 2018-08-13
- 1.3.10 — 2018-08-13
- 1.3.11 — 2018-08-06
- 0.5.8 — 2018-07-16
- 1.3.9 — 2018-06-27
- 1.3.8 — 2018-06-26
- 1.3.7 — 2018-06-13
- … 46 more at https://npm.io/package/jsorm/versions

## README

# jsorm

This library provides an interface to APIs following the JSONAPI spec. Though we're not striving for 1:1 compatibility with Active Record, you'll see it's the same basic usage, from scopes to error handling.

Written in [Typescript](https://www.typescriptlang.org) but works in plain old ES5 as well. This library is isomorphic - use it from the browser, or from the server with NodeJS.

[![Build Status](https://travis-ci.org/jsonapi-suite/jsorm.svg?branch=master)](https://travis-ci.org/jsonapi-suite/jsorm)

### Sample Usage

Please see [our documentation page](https://jsonapi-suite.github.io/jsonapi_suite/js/home) for full usage. Below is a Typescript sample:

```ts
import { JSORMBase, Model, Attr, HasMany } from "jsorm"

@Model()
class ApplicationRecord extends JSORMBase {
  static baseUrl = "http://localhost:3000"
  static apiNamespace = "/api/v1"
}

@Model()
class Person extends ApplicationRecord {
  static jsonapiType = "people"
    
  @Attr() firstName: string 
  @Attr() lastName: string
  
  @HasMany() pets: Pet[]
  
  get fullName() {
    return `${this.firstName} ${this.lastName}`
  }
}

@Model()
class Pet extends ApplicationRecord {
  static jsonapiType = "pets"
  
  @Attr() name: string
}

let { data } = await Person
  .where({ name: 'Joe' })
  .page(2).per(10)
  .sort('name')
  .includes("pets")
  .all()
  
let names = data.map((p) => { return p.fullName })
console.log(names) // ['Joe Blow', 'Joe DiMaggio', ...]

console.log(data[0].pets[0].name) // "Fido"
```

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