S
S
seth28102014-09-29 21:45:50
ORM
seth2810, 2014-09-29 21:45:50

Are there any ORMs that can run on top of HTTP on Node.js?

Good afternoon, dear guests of the resource. Recently, there was a need to transfer data storage to a server with an API, interaction with which should be carried out from a Node.js application via HTTP requests, according to the following scheme: Front (client) -> Node.js (app) -> API (database). And therefore, because the server and the client (Node.js application) will manipulate similar types of objects, it became necessary to make something like an ORM that will map its requests to remote requests to the server, through the HTTP client. In this regard, I would like to ask the community if anyone has come across tools with similar functionality, is it desirable that the implementation has built-in mechanisms for validating model fields?
Interested in something like this https://www.npmjs.org/package/symbiosis.js

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
seth2810, 2015-07-16
@seth2810

loopback

P
Philipp, 2014-09-29
@zoonman

meteor ?

S
Sergey, 2014-09-29
Protko @Fesor

mongodb and some other databases have a REST API. there is also mongolabs: docs.mongolab.com/restapi
respectively ORM for it https://www.npmjs.org/package/mongolab-provider

A
Alexander Keith, 2014-09-29
@tenbits

If you choose mongo, here is an example for [Class]( https://github.com/atmajs/classjs). True, the http service needs to be written separately, but basically it is already necessary, because it is rarely possible to get by with CRUD methods, usually the logic of behavior is more complicated.

// entity/user.js
var User = Class('User', {
    Base: Class.Serializable({
        activity: Date
    }),
    Validate: {
        activity (date) {
            if (date.getFullYear() !== new Date().getFullYear()) 
                return 'Current year expected';
        }
    },
    _id: null,
    activity: null,
    points: 0,
});
// client/user.js
Class.patch('User', {
    Store: Class.Remote('/rest/user/:_id')
})
// server/user.js
Class.patch('User', {
    Store: Class.MongoStore.Single('users', {
        indexes: [ { date: 1} ]
    })
});

// Browser OR NodeJS
var user = new User({
    _id: 'foo',
    activity: new Date
});
user.save().done(() => {});
//
user
    .patch({
        $inc: {
            points: 2
        }
    })
    .done(() => {})
//
User.fetch({ _id: 'foo' }).done(user => {});
User.fetch({ points: '>10' }).done(user => {});

// Server, http endpoint sample
module.exports = atma.server.Service({
    '$post /' (req) {
        var user = new User(req.body),
            error = Class.validate(user);
        if (error) 
            return this.reject(error);
        
        user.save().pipe(this);
    }
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question