How to get BreezeJS to talk to MySQL DB with Angular + Node?

≯℡__Kan透↙ 提交于 2019-12-25 07:29:53

问题


Stack: MySQL + Express + Angular + Node and node-mysql to talk to the DB.

EDIT: I'm connectiong to a local DB and the connection works. I can't get Breeze to communicate with it.

I'm trying to get the Breeze Todo app to work with this setup but I'm getting a localhost:3000/ToDos? 404 (Not Found) when Breeze goes out to get the data.

Do I need to create the API for Breeze to talk to? I've tried this:

angular.module('mysql', ['ngResource']).
factory('ToDos', function($resource) {
    var ToDos = $resource('/ToDos', {}, {update:{method:'PUT'}});

    return ToDos
});

And then injecting it into the datacontext service here:

angular.module('mainApp').factory('datacontext', 
['$http', 'logger', 'breeze', 'ToDos', datacontext]);

function datacontext($http, logger) {

    var dataService = new breeze.DataService({
        serviceName: '/ToDos',
        hasServerMetadata: false
    });

    var manager = new breeze.EntityManager({
        dataService: dataService
    });
...
}

I'm pretty lost as to what I'm doing wrong. Any help would be appreciated.

EDIT: The comments informed me that the backend API needs to be created. I'm working on that but could use some help converting the breeze-mongodb module.

In Breeze's zza example in repository.js there are calls to this module's MongoQuery() and MongoSaveHandler() functions. Would it be as simple as converting them to MySQL connection.query? And any help in the conversion would be much appreciated!


回答1:


I'm very curious about your progress on this. It's quite ambitious.

Ultimately I believe you'll be writing something like the "breeze-mongodb" npm module which will have a query and save implementation attuned to MySQL.

It could be tricky without an ORM. If you choose to go with an ORM in Node for MySQL (node-orm???), you can learn a lot about what to do from the Breeze source code for ContextProvider, ContextProvider.EF and ContextProvider.NH in the "breeze.net.server" repo on github. You don't have to be a C# person to glean transferable insights from that code base.



来源:https://stackoverflow.com/questions/23638600/how-to-get-breezejs-to-talk-to-mysql-db-with-angular-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!