Skip to content

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

License

Notifications You must be signed in to change notification settings

Keepsite/frontier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


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: '007@mi6.gov.uk',
    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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published