0.0.12 • Published 5 years ago

oscrud v0.0.12

Weekly downloads
-
License
ISC
Repository
github
Last release
5 years ago

oscrud

CRUD Microservice using Cote & ORMs controlling all models access

Installation

Using npm:

$ npm i --save oscrud

In Server-Side:

const Oscrud = require('oscrud').CrudInitializer;
const responder = Oscrud({
    models,
    orm: 'sequelize',
    connection: 'postgresql://localhost:5432/oskang09',
    server: 'pg', // can be whatever name just dont repeat..
    timeout: 3000 // default timeout 3000
});
// Will return responder that already subsribe to crud action.

In Client-Side:

const Oscrud = require('oscrud').CrudRequester;
const requester = Oscrud({
    orm: 'sequelize',
    server: 'pg', // server's name
    client: 'req1', // can be whatever name.
});

Example Usage

const Sequelize = require('sequelize');
const connection = new Sequelize('postgres://localhost:5432/oskang09');

const item = connection.define('item', {
    id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
    },
    name: Sequelize.TEXT,
    createdAt: Sequelize.DATE,
    updatedAt: Sequelize.DATE,
});

const Oscrud = require('oscrud');
const responder = Oscrud.CrudInitializer({
    models,
    orm: 'sequelize',
    connection: 'postgresql://localhost:5432/oskang09',
    server: 'pg',
    timeout: 3000 
});
const query = Oscrud.CrudRequester({
    orm: 'sequelize',
    server: 'pg',
    client: 'Item Service',
});

const test = async (log) => {
    // Supported transaction.
    const trx = await query.startTransaction(); // Receive transaction id
    log(await query.create('item', { name: 'Testing Item' }, trx));
    log(await query.create('item', { name: 'Item2' }, trx));
    log(await query.readone('item', 1, trx));
    /* You can call without transaction by removing transaction id at last of the paramteres */
    log(await query.create('item', { name: 'Without transaction' }));
    /* Transaction must commit or rollback at the end if not will stop at there waiting for completed singal... */
    await query.commitTransaction(trx);   // Commit the transaction
    await query.rollbackTransaction(trx); // Rollback the transaction
};

test();

Output:
> Item { id: 1, name: 'Testing Item' }
> Item { id: 2, name: 'Item2' }
> Item { id: 1, name: 'Testing Item' }
> Item { id: 3, name: 'Without transaction' }

Todo

  • Support more ORMs
  • Fully documentation
  • Make FuncQ more dynamic
  • Expose CRUD Rest

Supported ORMs

Maintainers

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago