Socket
Book a DemoInstallSign in
Socket

jarm

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jarm

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

latest
Source
npmnpm
Version
0.4.4
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

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);
  });
});

FAQs

Package last updated on 30 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts