We are developping a Nodejs app for a client that demanded that we use migration scripts to facilitate update the production database. Since i'm new to MySQL , i can't wrap my head around something, which is, how am i supposed to update tables content with only MySQL when i need to do some API calls to get the updated information, compare it to the current one and then update what needs to be updated.
What i did so far is, saving the new data in a JSON file. Is it possible to read a JSON with MySQL and import its content. This is what i want to do :
// read json file and star a loop
UPDATE table SET column = data WHERE id = json_id
// data and json_id are information from the JSON file
Is that possible ? if so how can i achieve that ?
Create a migration script. You can create a .sql file with scripts for create, update, and whatever you need for tables, stores procedures etc. Now when you want to deploy your app in production environment you can execute this script in the production instace and this will recreate your tables, sp's and even data if you want. You don't need an api endpoint for that.
Related
I prepare to perform a simple project and I don’t know what I should use to accomplish this. I need to receive a data entered by a user (via a webpage) and store them somewhere. I need them to be able to search and returned on the user request. I’m a little old-fashioned so I assumed that should be a file on ftp managed by some python or JS script? I really don’t know where to start so please advise.
project
Have you considered storing data in a database?
You can use MySQL. It's quite simple after you understand how a database table works.
Data are stored in a table. Table is a part of a database with other tables.
Each table has columns you create. Data are added to the table in rows.
For example, let's say a user sends you their name 'Brian'.
You can have a table called 'users'. In that table, you can create a column 'id' of the user (read about it later, including auto incrementing), and 'name'.
You insert the data into that table. Brian is now in a table with his own ID, like this:
id Name
----------------
1 Brian
Check this out:
SQL tutorial
Possible solution i would recommend:
create a mysql server
create a backend (links for Java)
rest-service https://spring.io/guides/gs/rest-service/
access DB https://docs.spring.io/spring-data/jpa/docs/1.5.0.RELEASE/reference/html/repositories.html
put the parts together
get/save the data on your webpage with xhr2.
I have an MVC.NET app which using Knockout.js (+ knockout.mapping) to deal with some cascading dropdowns. The data for these comes from a WebAPI call to an external service. As it happens this service requires an authentication token which expires after 2 hours, so I have the MVC app put the data from the service in a System.Web.Caching.Cache and return it from there unless the token has expired where it will grab it again from the service.
This is working fine.
However when I need to get this to the View, I am currently using the following method, which is to have a property of the ViewModel that I assign the service/Cache data to and then do this in the view:
var model = new ViewModel(#Html.Raw(Json.Encode(Model.ReferenceData)))
ko.applyBindings(model);
where Model.ReferenceData is the data from the service.
again this is working fine, but... the thing is with this, that the page then has all that Json data dumped in it on each request.
I would like to use an external JS file for the ReferenceData as then at least it can be cached by the browser and lessen the weight of the page on future requests.
However, I imagine that the overhead of generating a JS file is not that small, along with – what I really need is it to generate a link to that file that changes in much the same way that the built in MVC bundling of js files works – generating a link with a querystring.
My question is: is there an easy way of doing this?
For sure I can, when the cache is filled that first time, generate a js file and reference that from the View, but as I say getting that to change its link each time it is refreshed – or at least working out whether the data in it has changed and updating it only then is where the problem lies.
Any insight to this would be of great help
Thanks
Nat
Version the JS file (you can keep a GUID in the file it-self).
In Application_Start() get this version ID to a static variable.
In your controller pass this static variable data to ViewBag.
Ref your script with this ID
When you regenerate the file, update the version in file as well as your static variable. Next request from the client get the new version with new key.
Now if you want to update clients on the new version you have to use bi-directional protocol like web sockets or long-polling.
I am creating a simple ember app which will retrieve data from Laravel backend server restfully. I can display edit create and delete these records from ember successfully, however when i do any of the crud operation from ember instead of edit, the template doesnt update itself.
Like when i edit the record from ember, ember tempate displays the edited content in realtime, but when i create a new record or delete the one existing, the ember list displays the old record list.
What should i do to make the app update its model data when any changes happen.
Here is my code:
http://jsbin.com/iSEmONuV/
the code in jsbin is non functional .. i just uploaded in jsbin as it is much easier in jsbin than in stackoverflow.. to paste code.. i am using local server to load data.. ihavent uploaded it in real server yet
The problem is createRecord/deleteRecord in ember model doesn't modify any current collections (Ember Data does). So if you create/delete a record that you believe should live on some collection (hasMany or what not) you'll need to manually add/remove it to/from the collection.
I'm developing a simple(!) 2 page application.
Page1: Takes basic details from the user about the program is creating for his trip - name of the trip, dates etc.
After clicking Save, a entry is created on MongoDB using controllers in Lithium PHP for the program. A id is generated and passed on to page 2 as a parameter in URL like so:
$this->redirect('/iplans/save/' . $program_id . '/' . $program_name);
Page 2: is a single page application using many Backbone scripts (hosted in individual js files) and allows the user to add datewise details of his program. No js script is in-line.
I want the backbone collection to be saved on the server side when Finish is pressed but need to send in the program_id with this collection so that the right program is updated in MongoDB.
Questions:
How does one ensure that the program_id from lithium/php server side is picked up by backbone javascripts that are in their own js files (not inline)
What other options are available besides Controller::redirect to forward the control from page1 to page2?
What other options can be used to pass-on the program_id and any other values that may be needed to backbone/JS layer. Is there a standard-way of passing such items?
There are a couple of options:
Parse out program_id from window.location.href
Dynamicly create a bit of javascript in your lithium view. it could be as simple as:
"<script> myvars = " . json_encode(array(...)) . "<script>"
and then you can read the variables from the javascript.
Create the onDomRady function dynamically from lithium
That is a good way. That is, one page show form and receive data from the form, and one page that show some data. They are not related to each other, and it will make the code easy to understand.
You could use AJAX/JSON to send/receive data to/from the server. Also see answer 1b,1c
If it's just a variable being written to the session that you need to access in a single-page app, just make a controller (i.e. SessionsController) that returns the current session information, and turn content negotiation on.
Then you can get whatever keys you need any time.
I think in this case I need to write a client side script that onpageload/onchange gets options from server & builds a list dynamically. & stores new options to server via some JavaScript script. I will prefer to save user input in a file on server. I will be very thankful for any help.
Here is the stack we use for our web app and that works more or less the way you describe:
the user load an HTML page
the page make an ajax call and get the options as a JSON(either it exists already in the database, or a new option set is generated)
the json is rendered using a JS templating engine (PURE in our case)
the user change something
the same JSON is modified and sent by a POST to the server
the server read that JSON and store it in the database(you would write the data to your file). And then go back to the step 4, to wait for another user change.