fnorm

0.0.1 • Public • Published

fnORM - a functional ORM

Let's face it: Node's ORMs are crap. Mostly at least. But JavaScript is an awesome language. So why. Because we did it wrong. To much class-ish stuff like backbone.

We want to fix this. This is the first idea for the API:

Initialisation

var fnORM = require('fnorm');
 
var store = fnORM({
  //db config goes here
});

Creating Models/Collections/Whatever-you-call-them

... , we call it store.

var userStore = store('user') // 'user' is the tablename

Fetch array of things

userStore.where(where).map(fn).filter(fn).then(function(users) {
  // Array of POJOs containing user data
});

We will support most of the lodash collections stuff. But lazy!

Fetch one thing

userStore.get(id).then(function(user) {
  // POJO containing user data
});

Create one thing

userStore.save(data).then(function(user) {
  // POJO containing user data
});

Update one thing

userStore.save(id, data).then(function(user) {
  // POJO containing user data
});

Relations

postStore = store('post', {
  relations: {
    user: function(post) {
      return userStore.get(post.userId);
    },
    comments: function(post) {
      return commentStore.where({
        postId: post.id
      });
    }
  }
})
 
postStore.get(123).with('user', 'comments').then(function(post) {
  // post = {
  //   titel: 'hurray'
  //   user: {
  //     name: 'Mister T'
  //   },
  //   comments: [
  //     { text: 'awesome' },
  //     { text: '+1' }
  //   ]
  // };
});

Hope you like it.

If you have any ideas, feel free to create a PR/Issue.

Readme

Keywords

Package Sidebar

Install

npm i fnorm

Weekly Downloads

2

Version

0.0.1

License

MIT

Last publish

Collaborators

  • stephan.hoyer