Skip to content

Latest commit

 

History

History
96 lines (81 loc) · 2.85 KB

README.md

File metadata and controls

96 lines (81 loc) · 2.85 KB

Frontier

Frontier

Simple Node.js ODM inspired by Mongoose and Ottoman but database agnostic

Overview

Frontier is a simple, somewhat opinionated, Mongoose/Ottoman-inspired ODM.

const Frontier = require('frontier');
const Adapter = require('frontier/adapters/InMemoryAdapter');

class Address extends Frontier.Model {
  static schema() {
    return {
      number: 'number',
      street: 'string',
      suburb: 'string',
      city: 'string',
      country: 'string',
    };
  }
}

class User extends Frontier.Model {
  static schema() {
    return {
      email: 'string',
      name: 'string',
      address: { type: Address },
    };
  }
}

const frontier = new Frontier({ models: [Address, User] });
const store = new Frontier.Datastore({ Adapter });
const repo = frontier.createRepository(store);

(async () => {
  const user = new repo.models.User({
    name: 'James Bond',
    email: '[email protected]',
    address: new repo.models.Address({
      number: 85,
      street: 'Albert Embankment',
      suburb: 'Vauxhall',
      city: 'London',
      country: 'UK',
    }),
  });
  await user.save();
  const dbUser = await repo.models.User.find({ address: { city: 'London' } });
  console.log({ user, dbUser });
})();

Features

  • ES6 Classes for Models
  • ES6 Async/Await support
  • Generate GraphQL types and default resolvers
  • Pass through cache for repositories (Dataloader)
  • Model Metadata (e.g. meta.demoId)

Possible Features

Credits

API interface inspired by Ottoman. Icon made by Those Icons from www.flaticon.com is licensed by CC 3.0 BY