synchronizing pouchDB with json data - json

I want to create a html page which synchronize JSON data with pouch Db.
The JSON data is a response from a web service.I have created a sample html file which can create a pouch Db database.I have created rest web service which gives certain data as response. can any one help me to synchronize these two.

PouchDB has a built in method for synchronizing with CouchDB using one- or two-way replication.
I understand that you want to sync with a datasource, which doesn't have a CouchDB compatible API. Then you'll have to write code to perform the synchronization with your specific JSON API.

There's a library now which makes it possible to import a JSON string (dump) as database into PouchDB.
It's called PouchDB-Load and is written by PouchDB author Nolan Lawson.
So in your case the code can be as simple as:
var db = new PouchDB('my-awesome-db');
db.load('http://example.com/my-dump-file.json').then(function () {
// done loading!
}).catch(function (err) {
// HTTP error or something like that
});

Related

how to effectively resolve PayloadTooLargeError: request entity too large in React Native Frontend?

So I have stored 800kb JSON data from API into async storage, but when I try to loop over that data I receive
PayloadTooLargeError: request entity too large
at readStream (C:\Users\Vartotojas\AppData\Roaming\npm\node_modules\expo-cli\node_modules\raw-body\index.js:155:17)
at getRawBody (C:\Users\Vartotojas\AppData\Roaming\npm\node_modules\expo-cli\node_modules\raw-body\index.js:108:12)
at read (C:\Users\Vartotojas\AppData\Roaming\npm\node_modules\expo-cli\node_modules\body-parser\lib\read.js:77:3)
at jsonParser (C:\Users\Vartotojas\AppData\Roaming\npm\node_modules\expo-cli\node_modules\body-parser\lib\types\json.js:135:5)
at call (C:\Users\Vartotojas\AppData\Roaming\npm\node_modules\expo-cli\node_modules\connect\index.js:239:7)
I don't want to use any database or backend though it seems not too large dataset. Since async storage can store 6mg, why did I receive this error in the first place? And shouldn't it just be truncated instead? Or it's just a warning for console.log and if so how to resolve it?

React: Store <Form> data from to MySQL

I have created a register page in reactjs, where I am taking firstName, lastName, password, email from a user.
In the backend, I have created the application using SpringBoot to handle the request from frontend.
Now, I am able to store (temporarily) the register form data in http://localhost:8080/forms .
When the user enters the data in register form at the front end, the data is stored temporarily in the spring boot application in the url mentioned in the axios.
So, when I enter this url (in the browser), am able to see the list of registered users with their credentials in JSON format like this :
[{"firstName":"Bhavya", "lastName":"Gupta", "email":"abcd#a", "password":"zaqxsw","id":100}]
But this data is temporarily stored, so when I restart the server the data is no longer there.
submitBook= event =>{
event.preventDefault();
const book = {
firstName: this.state.firstName,
lastName: this.state.lastName,
password: this.state.password,
email: this.state.email
};
axios.post("http://localhost:8080/forms",book).then(response => {
if(response.data!=null){
this.setState({"show":true});
setTimeout(() => this.setState({"show":false}),3000);
} else {
this.setState({"show":false});
}
});
this.setState(this.initialState);
}
The complete code is available here
I want to store the register form data from front-end (client-side) into a MySQL database, so that I can perform login authentication on the data stored.
I have created MySQL database with 4 columns - firstName, lastName, email, password. I searched on the internet and read several answers in SO Sending data to database in React, referred several blogs and articles, but I am not able to understand how to achieve this.
Can anyone please help me out in solving this issue?
In a typical/modern web application, you have well defined roles/purposes for each part of the system. From your question, it appears that you intend for the roles to be interchanged and that might the source of your troubles here.
Let;s look closely at your set-up:
Client-side/Front-end (JavaScript/React)
This is simply an enabler for a user to interact with your actual application. In your set-up, this should render the form and capture registration data.
Server-side/Back-end (Java/SpringBoot)
This is your application layer where most processing happens (business logic).
In your set-up, this is where your MVC happens. And essentially, after any required validation, this layer then communicates with the Database.
Database-layer (SQL or NoSQL)
This is the layer that you utilize to store and persist data within your app. In your set-up, you are using MySQL to handle your data.
Already your backend is already exposing endpoints which you are consuming at the front-end via axios. Therefore the direct answer to your question lies in getting SpringBoot to work with your MySQL in order to persist your data.
Here is an official tutorial on how to access data with MySQL from the spring team.
For Posting Form data from ReactJS to MySQL database via Spring Boot Application, I have written blogs, that gives a detailed explanation and a step by step method to connect front end part with backend .
Refer to these blogs :
Prerequisites to POST form data from ReactJS to an API endpoint : Part 1
Initial Setup for creating a basic React App: Part 2
Posting Form data from ReactJS to MySQL database via Spring Boot Application: Part 3

Can I share ~1k of dynamically updated data between HTML5/JS pages using only apache2?

I have an HTML5/Javascript web site. There is a form which updates JSON data. There are other pages which I would like to load that JSON data dynamically. I know how to do this via Tomcat/JSP but I'd like to keep this site solely apache2. Is there a way to persist and read the JSON data? It is ok if the data is temporal and is lost upon an apache2 bounce.
You may want to store the JSON data in localStorage/sessionStorage on the client side.
Store Item:
localStorage.setItem('storedItem', JSON.stringify(testObject));
Retrieve Item:
var json = JSON.parse(localStorage.getItem('storedItem'));
JavaScript Storage

Get JSON data from RavenDB

I have an Asp.Net MVC3 application that use embedded RavenDB to store data.
The view needs json data that is now created by the controller in this way:
public ContentResult Data()
{
var res = JsonConvert.SerializeObject(DocumentSession.Query<DataObject>());
return new ContentResult { Content = res, ContentType = "application/json" };
}
Everything works fine but to me it seems inefficient because data that are stored in DB in JSON format is serialized in POCO and then deserialized again.
Is there a more direct way to get json data directly from the embedded db?
It's not inefficient at all. Keep in mind that internally, raven actually uses BSON - so you would have to translate it anyway. Also there are metadata fields. If you were to return it directly through your controller, you would have no opportunity to shape the response of the data and strip off the unwanted fields.
If you must continue with this line of thinking, you have two options:
You could use the DocumentStore.DatabaseCommands.Get() and related operations to return RavenJObjects that you could then translate JSON from.
You could talk directly to the Raven database over HTTP without using the raven client.
Neither of these are straightforward, and you are throwing away a lot of goodness of the Raven Client API. IMHO, any performance gain you were to achieve would be unnoticeable. I would stick with your current approach.
Also - If you are just trying to avoid having to serialize here, consider returning a JsonResult instead of a ContentResult. If you want to use Json.Net instead (per your other recent post), Here is a cleaner way to do it: http://james.newtonking.com/archive/2008/10/16/asp-net-mvc-and-json-net.aspx

Generate PDF document with data on Titanium DB

I am creating a mobile app using Titanium. I am using the titanium db which is sqlite. This pdf needs to have boxes to structure the data and images that I am taking with the app as well.
I am assuming what I need to do is convert the data into json on titanium, upload it to a web server and insert into a mysql/phpmysql db and then use some sort of script that is out there will read the web db and create a pdf and send it back to the phone
is that right?
and if so...i need help with that whole process haha...any good tutorials on db upload to web db process?
Check the docs, HTTPClient is what you need to use, its a standard.
First steps would be to create a web service on your server that parses your JSON formatting. The bulk of the work you would have to do has nothing to do with Titanium, but here is the code for sending a JSON object to some web service with a POST from a Titanium App.
var xhr_getstep = Titanium.Network.createHTTPClient();
xhr_getstep.onload = function(e) {
// Do something with the response from the server
var responseBlob = this.responseText;
};
xhr_getstep.onerror = function() {
Ti.API.info('[ERROR] WebService failed.');
};
xhr_getstep.open("POST", 'http://yourwebsite.com/yourwebserviceentry.php');
xhr_getstep.setRequestHeader("Content-Type", "application/json");
// Create your object with info on how to create the PDF
var objSend = {title : 'Amazing Title'};
xhr_getstep.send(obj); // Send it all off