整合微风和帆/水线

时间:2015-09-08 20:50:10

标签: sails.js breeze waterline

我有一个等于 Node / Express 应用程序的开始,该应用程序正在使用breeze来执行其CRUD操作。目前我正在使用Node / Sequelize - > Postgres的。作为NodeJS的新手,我刚刚遇到了SailJS。它看起来很酷,我想考虑使用我的应用程序。但是,我很清楚Breeze如何与Sails / Waterline整合。

具体来说,breeze提供了一个微风续集适配器,然后它与续集的redderick中的sequelize进行通信。

我想知道这两者有多难:

  1. 微风与水线沟通,就像它的续集一样

  2. 使用带风帆的风帆代替水线

  3. 我遇到过涉及此主题的帖子,但我未能找到涵盖此问题的深入帖子。

    提前致谢。

    编辑 - 微风在行动的例子(请记住,为简单起见,这是篡改):

    客户端:

        (function(angular) {
            'use strict';
    
            angular.module('dataAccess')
                        .factory('Repository', ['breeze', '$rootScope', 'ListHelper', factory]);
    
            function factory(breeze, $rootScope) {
                return function (entityManagerProvider, resourceName) {
    
                    this.getByKey = getByKey;
                    this.buildAll = buildAll;
                    this.all = all;
                    this.buildQuery = buildQuery;
                    this.query = query;
                    this.executeQuery = executeQuery;
                    this.findInCache = findInCache;
                    var test = getMetastore();
                    var entityTypeName = getMetastore().getEntityTypeNameForResourceName(resourceName);
                    var entityType = getMetastore().getEntityType(entityTypeName);
    
                    //activate();
    
                    ////////
    
                    function activate () {
                        if (entityTypeName) {
                            //getMetastore().setEntityTypeForResourceName(resourceName, entityTypeName);
                        }
                    }
    
                    function buildAll () {
                        return breeze.EntityQuery
                            .from(resourceName);
                    }
    
                    function all (options) {
                        return executeQuery(this.buildAll(), options || {});
                    }
    
                    function query (predicate, options) {
                        return executeQuery(this.buildQuery(predicate), options || {});
                    }
    
                    function buildQuery (predicate) {
                        return predicate ? this.buildAll().where(predicate) : this.buildAll();
                    }
    
                    function executeQuery(query, options) {
                        return entityManagerProvider.manager()
                            .executeQuery(query.using(options && options.fetchStrategy ? options.fetchStrategy : breeze.FetchStrategy.FromServer));
                    }
    
                    function getMetastore() {
                        return manager().metadataStore;
                    }
    
                    function
    
     manager() {
                    return entityManagerProvider.manager();
                }
            };
        }
    
    })(window.angular);
    

    服务器:

        var fs = require('fs'),
            breezeSequelize = require('breeze-sequelize'),
            config = require('./config');
    
        var SequelizeManager = breezeSequelize.SequelizeManager;
        var SequelizeQuery = breezeSequelize.SequelizeQuery;
        var SequelizeSaveHandler = breezeSequelize.SequelizeSaveHandler;
    
        var manager = createSequelizeManager();
    
        var breeze = breezeSequelize.breeze;
    
        function createSequelizeManager() {
            var metadata = readMetadata();
            var sm = new SequelizeManager(config.db.dbConfig, config.db.options);
            sm.importMetadata(metadata);
            return sm;
        }
    
        function readMetadata() {
            var filename = "MetaData.json";
            if (!fs.existsSync(filename)) {
                throw new Error("Unable to locate file: " + filename);
            }
            return fs.readFileSync(filename, 'utf8');
        }
    
    //controller method, handles all breeze get requests
            function get (req, res, next) {
                var resourceName = req.params.entity;
                var entityQuery = entityQuery.fromUrl(req.url, resourceName);
                executeEntityQuery(entityQuery)
                    .then(function (r) {
                        res.json(r);
                }).catch(next);
            }
    
        function executeEntityQuery(entityQuery) {
            var query = new SequelizeQuery(manager, entityQuery);
            return query.execute();
        }
    

0 个答案:

没有答案