0.2.1 • Published 4 years ago

@or-change/duck-datahub v0.2.1

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

Datahub is an early project. It comes to be a data middle layer solution or data-typed micro service framework. In duck to use datahub can get a more easier coding experience in ORM like realms. Developer can ignore something about data persistence for focus on product features when developing. In practice, the cost of development can be reduced so much.

Usage

Recommanded practice,

const Duck = require('@or-change/duck');

// Can be from other files.
function Account(adapter, injection, context) {
  return {
    schemas: {
      type: 'object',
      properties: {
        id: { type: 'string' },
        name: { type: 'string' },
        email: { type: 'string' },
      }
    },
    methods: {
      query(accountId) {
        return adaptor.getAccountById(accountId);
      },
      ...
    }
  };
}

Duck({
  id: 'com.oc.duck.test',
  components: [
    Duck.Datahub([
      {
        id: 'com.foo.bar.baz',
        models: {
          Account
        }
      }
    ])
  ],
  installed({ Datahub, injection }) {
    // Getting a datahub instance with an adapter object.
    // Put it on injection for using in anywhere.
    injection.Model = Datahub('com.foo.bar.baz', { foo: 'bar' }).model;
  }
}, ({ Model }) => {
  // Using `Model` like this type in somewhere can accessing injection.
  const account = Model.Account.query('1');
  // => { id: 1, name: '...', email: '...' }
});

API Reference

Options

Dependence

Instant

About adapter

0.2.1

4 years ago

0.2.0

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago