Skip to content
/ jarm Public

Jarm is JSON-API Relational Mapping -- an ORM layer for Node.js apps.

License

Notifications You must be signed in to change notification settings

twuni/jarm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

651b613 Β· Aug 27, 2019

History

40 Commits
Aug 27, 2019
Aug 27, 2019
Nov 12, 2018
Dec 10, 2018
Nov 12, 2018
Aug 27, 2019
Nov 12, 2018
Nov 14, 2018
Aug 27, 2019
Aug 27, 2019
Aug 27, 2019

Repository files navigation

Jarm is JSON-API Relational Mapping

CircleCI

Define a schema for your JSON API resources and your relational database... at the same time!

Pairs nicely with @twuni/pg.

Installing

NPM

$ npm install jarm

Yarn

$ yarn add jarm

Usage

import { Pool } from 'pg';
import PostgreSQL from '@twuni/pg';
import { Store } from 'jarm';

const schema = {
  columns: [
    {
      attribute: 'favoriteColor',
      column: 'favorite_color',
      type: 'text'
    }
  ],
  id: {
    column: 'id',
    type: 'text'
  },
  relationships: [
    {
      columns: [
        {
          attribute: 'id',
          column: 'related_id',
          type: 'text'
        },
        {
          attribute: 'type',
          column: 'related_type',
          type: 'text'
        }
      ],
      name: 'owner',
      table: 'r_widgets_owner'
    }
  ],
  resource: 'widget',
  table: 'widgets'
};

const store = new Store(schema);

new PostgreSQL(Pool).connect().then(({ disconnect, write }) => {
  write(async (query) => {
    await store.createSchema()(query);

    const resource = {
      attributes: {
        favoriteColor: 'blue'
      },
      id: 'Cba...987',
      relationships: {
        owner: {
          data: {
            id: 'Abc...789',
            type: 'user'
          }
        }
      },
      type: 'widget'
    };

    await store.createResource(resource)(query);
  });
});

About

Jarm is JSON-API Relational Mapping -- an ORM layer for Node.js apps.

Resources

License

Stars

Watchers

Forks

Packages

No packages published