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

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!

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.

Related

Ember could not find module 'mysql' in components directory

I lately started experiencing this issue where I can not import the 'mysql' module in my component.js
export default Component.extend({
actions: {
createPost: function (newPost) {
var mysql = require('mysql');
}
}
});
This code is followed by this error:
There was an error running your app in fastboot. More info about the error:
Error: Could not find module `mysql` imported from `dummy/components/create-new-post/component`
So the file is present in api-directory/tests/dummy/app/components/create-new-post/component.js
However, I have such function present in: api-directory/server/mocks/posts.js and it seems to be working fine there when I use the same 'var mysql = require('mysql');'
I simply cannot get my head over this issue and surfed everywhere for a solution. Can anyone please assist and enlighten me on this most possibly easy solution? Thanks.
Nevermind, I'm a bloody idiot who didn't realize the difference between back-end and front-end. I injected the store service into the component and used createRecord function along with save to pass the record to the back-end where I successfully could execute the query.

Is there a way to run es6 components, specifically promises and generators, in aws lambda functions

ES6 usage requires --harmony flag in node v0.12.3.
Is there a way to do so for an aws lambda function?
You can use babel to transform es6/es7 to be compatible with node 0.10.x:
http://www.rricard.me/es6/aws/lambda/nodejs/2015/11/29/es6-on-aws-lambda.html
EDIT:
There is also a really cool AWS lambda deployer called Apex with that you can transform and deploy es6/es7 code easily! Examples: https://github.com/apex/apex/tree/master/_examples/babel-webpack
EDIT2:
There is an other AWS lambda deployer called Gordon which also helps you integrate lambda with other services such as:
APIGateway
Scheduled CloudWatch Events (cron)
CloudWatch Events
Dynamodb Streams
Kinesis Streams
S3
They also have a lot of useful examples
AWS Lambda use v0.10.36, but anyway I think we can try in this way
var spawn = require("child_process").spawn;
var child = spawn('node', [ "--harmony", "es6.js" ], {
cwd: __dirname
});
These answers are a bit out of date. AWS announced support for Node.js 4.3.2 runtime in April 2016. 4.3.2 supports ES6. It is also completely backwards compatible. More details available here:
https://aws.amazon.com/blogs/compute/node-js-4-3-2-runtime-now-available-on-lambda/
Simple, use bluebird
. Any file that requires to make use of promises, get bluebird in scope.
var Promise = require('bluebird');
Promise.aPromise()
.then(function () {
console.log('ftw!');
})
.catch(function(err) {
console.log(err, 'do not forget to catch errors. ever!');
})
As far as generators are concerned, we are out of luck. bluebird requires minimum v0.12+ and at the time of writing lambda is still stuck in node v0.10.36

General approach to visualize SQL CE data using Flot.js in ASP.NET MVC 4?

I'm very new to SQL Server, Flot.js, working with databases in general. I'm working on a project in ASP.NET MVC 4 (using VS 2012) which has a Microsoft SQL Server Compact 4.0 database filled with data, and I would like to visually display this data using flot.js.
I haven't been able to find any information on the general steps one would take to manipulate the data. Starting with the DB entries in the SQL CE database, and ending with a JSON file (or a CSV - anything flot.js could use as input), what would be the most common approach that a web developer could tak, using ASP.NET MVC 4?
Hi your question is quite broad so I apologise if answer is quite vague in places. As you have an existing database it would make sense to use Entity Framework Database First to map your database to a meaningful context which can then be manipulated in your code. Once you have created an edmx model you can then use it in your controllers to manipulate data:
public class YourController : Controller
{
private DatabaseEntities db = new DatabaseEntities();
//.... Your controller actions
Database First allows you to reverse engineer a model from an existing database. The model is stored in an EDMX file (.edmx extension) and can be viewed and edited in the Entity Framework Designer. The classes that you interact with in your application are automatically generated from the EDMX file.
Flot takes data in the following format:
[[1,2],[3,4],[5,5]] // x, y coordinates
[[1,"a"],[2,"b"],[3,"c"]] // Categories
See the Flot documentation for further details. So using Json will not work with flot directly. You will have to create a controller action that returns the data you require in the correct format:
public string GetData()
{
var query = db.Table.Where(... // linq query for desired data
var builder = new StringBuilder();
builder.Append("[");
foreach (var item in query)
builder.AppendFormat("[{0}, {1}], ", item.x, item.y);
var result = builder.ToString();
return result;
}
Now on the client side you can make a call from jQuery to get the data and draw the chart:
$(function () {
$.getJSON("../controller/action", function (data) {
$.plot("#placeholder", [data], {
// your chart
Just one way of doing it, but think its a good way using MVC. Hopefully this will give you a good overview and you should have enough info from this to get started at least.

Can BreezeJS work with MySQL + NodeJS + AngularJS?

I'd like to use breeze but I can't find out if it will work with a MySQL + Express + Angular + Node stack. The docs say it will work with MongoDB, but what about MySQL?
Any standard SQL database like Oracle, MySQL, MariaDB, SQLServer, etc is supported out of the box as long as there is an Entity Framework Provider for it (and almost all of them do).
Source
You can integrate the Nodejs backend with Mysql using, for example node-mysql, and to integrate with Angularjs, you can do something like this:
<!-- Angular template -->
<li data-ng-repeat="emp in employees">
<label>{{emp.FirstName}}</label>
<label>{{emp.LastName}}</label>
</li>
// bound to employees from query
manager.executeQuery(breeze.EntityQuery.from("Employees"))
.then(function(data) { $scope.employees = data.results; });
#danilodeveloper I'm having to take back your answer because it isn't that simple.
There currently is no out-of-the-box support for Breeze + Node + MySQL. Simply using node-mysql to interface with the DB isn't enough. As per Ward's answer here not using an ORM would be tricky and a ton of code would need to be written along the lines of the breeze-mongodb npm module.

SPRING-DATA-REST Backend with AngularJS frontend

Is there any frontend application sample that consumes RESTful services of Spring-data-rest backend which is written with angularJS.
My prefer for rest api for angularjs is RESTANGULAR module...
In the site you can see many examples that how they deal with Rest calls and really good documentation and good community as well...
In this example which is from spring example SPRING.IO they uses $http, but I should say that Restangular uses $http as well, so basically you can say that Restangular is extended version of $http...
and for the last you can look for $resource...
I will update my answer If I will find something new...
Here are some links to AngularJS apps consuming Spring RESTful services
https://github.com/spinner0815/spring-data-rest-angularjs
At the moment, I think that angular-hal is the best library to consume Spring Data Rest output and stay with its philosophy of discovering url through relations.
The home page: https://github.com/LuvDaSun/angular-hal
and some examples :
https://github.com/LuvDaSun/angular-hal/tree/master/demo (by the dev)
https://www.jiwhiz.com/blogs/Consume_RESTful_API_With_Angular_HAL
https://github.com/paulcwarren/gs-rolebased-ui-with-hypermedia
here has a nice lib spring-data-rest-js can help you.
It's a easy to use and lightweight javascript lib can run in both node.js and browser. After use this lib you can manage entity like this way:
let springRest = require('spring-data-rest-js');
let Student = springRest.entity.extend('students');
let student = new Student();
student.set('name', 'Tom');
//create entity
student.save().then(()=> {
//update entity
student.set('name', 'Physics');
retuen student.save();
}).then(()=> {
//delete entity
retuen student.delete();
}).catch(err=> {
done(err);
})
base on fetch API and Promise,inspired by Parse.
It can be work with lib like AngularJS React Vue...