I am trying to work out for a small ember application. What I want is to do is list all the items from a table of the MySQL DB. I am able to retrive and display the data from the localStorage of the ember store but I do not know how can I implement same thing using MySQL Database.
Any kind of help will be appriciated.
There are a few ways to do it, but basically you need some sort of server-side API to handle actually querying the MySQL database and returning data. This is usually done these days with a REST API using the interchange format JSON.
Whether you use PHP, Node, or another server technology, there are a couple of ways you can pull the data into Ember. Let's assume your have a server-side method called search, which returns a JSON array of blog posts, something like:
[
{"title": "blog post 1", "body": "this is a blog post"},
{"title": "blog post 2", "body": "this is another post"}
]
The easiest way to pull this data into Ember would be a simple ajax call:
var IndexRoute = Ember.Route.extend({
model: function()
{
return $.getJSON("http://apiurl.com/search");
}
});
In the above Ember route definition, the model is set to a function which returns the promise object returned by the JQuery getJSON method.
The template might look something like this:
<script type="text/x-handlebars" data-template-name="index">
{{#each}}
{{title}}<br/>
{{description}}
{{/each}}
</script>
Many Ember users choose to use EmberData instead of a ajax calls, however, that part of Ember is still under development and I found I had an easier time building my application without EmberData. Check out this article from one of the co-founders of Discourse:
http://eviltrout.com/2013/03/23/ember-without-data.html
The Ember Guides are pretty good place to start:
http://emberjs.com/guides/
http://emberjs.com/guides/routing/specifying-a-routes-model/
You can try Dreamfactory It's a SaaS REST API that will connect to a variety of SQL and NoSQL backends. I use it with SQL Server running on an RDS instance and haven't had any issues. I have written a super-basic, WIP Ember-Data adapter for it. It still needs a TON of work but is mostly functional.
Related
I am trying to get a clean JSON response for nodes in Drupal 8 like:
{
"title":"big news happens somethere",
"body":"a lot of description here",
"tag":[
"news",
"story"
]
}
I know one way is to use the views rest display, where I can specify the column name alias. But with that, I will get a JSON array with count being 1 for that single node.
How can I get exactly n JSON object with a clean schema structure for that?
RESTful Web Services and RESTui can deliver what you need.
The other option is to make a custom module with a custom page and deliver content the way you want.
I recommend using the RESTful Web Services module that's included with Drupal 8. Check out the following articles:
http://enzolutions.com/articles/2014/12/16/how-to-create-a-rest-resource-in-drupal-8/
https://www.mediacurrent.com/blog/eight-insights-and-useful-snippets-d8-rest-module
We have been using breeze for the past year in our project and are quite happy with it. Previously our server was a asp.net application with entity framework. Now we are moving toward node.js and mysql. We have installed breeze-sequelize package and everything is working fine.
The documentation breeze Node server w/sequelize, says that the result of a query is a promise with the resolved result formatted so that it can be directly returned to the breeze client. And this is effectively what happens: the result of a query is just a plain old json object with values from the database, not entities the way breeze understand entities.
My question is this: I have a scenario where a heavy server process is instantiated by the client. No data is expected in the client. The process will run entirely on the server, make queries, modify data and then save them, all in the server. How can I transform those plain old json objects into entities during my process, I would like to know for example what object has been modified, what have been deleted and send appropriate message to the client.
Of course I could create myself a kind of mechanism that will track changes in my objects but I would rather rely on the breeze manager for that.
Should I create a breeze manager in the server?
var manager = new breeze.EntityManager(...)
A second concern is: with breeze-sequelize I do we handle transactions? start-transaction, complte-transaction and rollback-transaction?
Thank you for your input
To turn JSON with the attribute values of a Sequelize instance into an actual Instance use:
Model.build({ /* attributes-hash */ }, { isNewRecord: false })
For an example demonstrating this see here. The Sequelize Instance documentation (here, see especially the function changed) might also be helpful. I am not familiar with Breeze and might have misunderstood your question here, does this help?
I feel like this answer to this question is trivial, but I am having a difficult time figuring out how to do this the 'Ember way'.
Quick problem background: I am creating a recipe app with Ember frontend and a Rails API backend. I am implementing a search feature to find recipes based on ingredients. I have already configured my Rails API endpoint which sends back the correct records as JSON.
Ember.$.get('/recipes_query', {query: query})
.then(function(reponse) {
// Do something here
});
Now all I need to do is display these. What I am confused about is how to handle the data when it is retrieved (or in other words, how to push these to the store, and then ONLY show the most recently retrieved results). I could push these results to the store and then use a filter to display the correct results, but this seems like an extra step - the JSON response already contains everything I need to display. What is the Ember convention for performing this simple task?
It would be trivial answer if you would use query instead of jQuery.get, so if possible, refactor to:
this.store.query('recipe', {query: query})
.then(records => {
// you have everything you need as records
});
First of all I'm very confused with this "JSON" thing, I can't completely get all the concepts but what I actually want to do is some kind of recipes Mobile Phonegap/kendo-UI(or whatever framework) App which should load data from JSON object. But I don't have a website where I could store data. So, what would be options to save and load data from JSON to my app? I mean it's very confusing to ask this, because I actually can't get the JSON, so I'am ready to get a lot of Dislikes but I want to know how to do a thing like that. I don;t know what URL to write and other stuff.
Hope someone will get what I acutally want and if this idea for loading data from JSON is not what I need, hope someone would like to offer other possibilities. Thank you.
Yes, you can technically save JSON files locally to your app, then retrieve that data locally. At the end of the day, it's not much different than getting it from a web service (other than the fact that it's going to be static data).
Not to get into too much detail here (This site has plenty of info), but JSON is a lightweight flavor of XML for passing data back and forth, very suitable for web services. All it is is key-value pairs. So, in your case, it'll be something like:
{ ["RecipeID" : 1,
"RecipeName" : "PB&J",
"RecipeIngredients" : ["Peanut butter", "Jelly", "Bread" ],
"RecipeDirections" : "If you really have to look this up on an app..."],
["RecipeID" : 2,
// ...
]
}
As you can see, it reads pretty clean and is easy to parse. So, in PhoneGap, you'd probably use jQuery and do something like,
$.getJSON("URLorLocationOfJSONfile", null, function(recipes) {
$.each(recipes, function(i,r) {
alert("Today, I'd like to eat... " + r.RecipeName);
)};
)};
And thus iterate through the JSON contents. Put them in a list or something. Whatever you'd like at that point. I build all my PhoneGap apps with JSON on the backend, so you're going in the right direction with that.
You can host the JSON file somewhere out there if you don't want to build an API for it, too. Just replace it when you get new recipes.
Hope that's a start.
I am developing a java web program that can manage distant ldap entries,
we have to select person and i want to do this with auto-complete text-area functionality
I have Java function to return the entire list, to find by name or just by the begin of the name (wildcard search, spring ldap).
My idea was to use the jQuery ui autocomplete plugin, but I don't know how to catch remote source.
I think that must be by json object return by a servlet
Anyone know how can I do that?
I hope that's not to hard to implement
thank in advance for help
So I assume you are successfully getting the data retrieved from the LDAP using spring security.
All you need to do is to convert the data into JSON. If you are not using any json library already, you can use json.org for simplicity (or any other jsob-library).
Create a servlet that accepts request param term. call your LDAP Search based on this term. Create a json array of the result and print that that on response in doGet(). Map the servlet to desired path
$( "#your-element" ).autocomplete({
source: "/servlet/path",
minLength: 2
});