Fetch data from two table in nodejs from mysql in rest Api - mysql

js Developers
I am trying to create Rest api in node.js . I want to get data from two table in mysql database. First table is USERS which contain {id, name, email} and Second table is USERINFO which contain {id, mobile , address, user_id} here user_id is work as foreign key that is associate with USERS table. In USERINFO table more than one information.
First table Look like this
Second Table look like this
I got this type of output
[
{
"id": 1,
"name": "abc",
"email": "abc#xxx.com",
"mobile": "11111",
"address": "qqq",
"user_id": 1
},
{
"id": 2,
"name": "XYZ",
"email": "xyz#xxx.com",
"mobile": "22222",
"address": "wwwww",
"user_id": 2
},
{
"id": 3,
"name": "abc",
"email": "abc#xxx.com",
"mobile": "3333333",
"address": "ssssss",
"user_id": 1
},
{
"id": 4,
"name": "XYZ",
"email": "xyz#xxx.com",
"mobile": "444444",
"address": "nnnnn",
"user_id": 2
}]
But i want this type output
[
{
"id": 1,
"name": "abc",
"email": "abc#xxx.com",
"info": [
{
"mobile": "11111",
"address": "qqq",
},
{
"mobile": "3333333",
"address": "ssssss",
}
],
"user_id": 1
},
{
"id": 2,
"name": "XYZ",
"email": "xyz#xxx.com",
"info": [
{
"mobile": "22222",
"address": "wwwww",
},
{
"mobile": "444444",
"address": "nnnnn",
}
],
"user_id": 2
}]
Thanks in Advance

Related

How to name child nodes when importing from Exel to Firebase?

I want to import data from Exel to Firebase. The import works fine, but I cannot figure out how to name the child nodes?
When I try this:
I get this in Firebase:
And when I add some numbers to the first cell for naming the child nodes like this:
The formatting gets all messed up like this:
The formatting gets all messed up like this:
[
{
"Name": 123123,
"Company": "Name1",
"Email": "Company1",
"Phonenumber": "Email1",
"": 123,
"__1": ""
},
{
"Name": 123123,
"Company": "Name2",
"Email": "Company2",
"Phonenumber": "Email2",
"": 456,
"__1": ""
},
{
"Name": 123123,
"Company": "Name3",
"Email": "Company3",
"Phonenumber": "Email3",
"": 789,
"__1": ""
},
{
"Name": 2312312,
"Company": "Name4",
"Email": "Company4",
"Phonenumber": "Email4",
"": 101,
"__1": ""
},
{
"Name": 123123,
"Company": "Name5",
"Email": "Company5",
"Phonenumber": "Email5",
"": 123,
"__1": ""
}
]
Ideally I would like to get autoID on each child node, but I can also go with my own ID input.

Find a record in json Object if the record has specific key in python

I have a JSON object which has 100000 records. I want a select a record which has specific value to the one of the key
Eg:
[{
"name": "bindu",
"age": "24",
"qualification": "b.tech"
},
{
"name": "naveen",
"age": "23",
"qualification": "b.tech"
},
{
"name": "parvathi",
"age": "23",
"qualification": "m.tech"
},
{
"name": "bindu s",
"status": "married"
},
{
"name": "naveen k",
"status": "unmarried"
}]
now I want to combine the records which are having the name with 'bindu' and 'bindu s. We can achieve this by iterating on the JSON object but since the size is more it is taking more time. Is there any way to make this easy.
I want the output like
[{
"name": "bindu",
"age": "24",
"qualification": "b.tech",
"status": "married"
},
{
"name": "naveen",
"age": "23",
"qualification": "b.tech",
"status": "unmarried"
},
{
"name": "parvathi",
"age": "23",
"qualification": "m.tech"
"status": ""
},
This will rename and merge your objects by first name.
jq 'map(.name |= split(" ")[0]) | group_by(.name) | map(add)'

Building a Klipfolio klip. How do I count all child nodes in a JSON stream?

I wish to count members that has status='active' the JSON stream. This will equal the sum of our members.
I'm able to select all members by #/name, but I'm not able to filter on only those who are active.
According to Klipfolios documentation, it should be possible to count single elements:
[
{
"_id": "58aabc92e846502357fc0f69",
"email": "mail#me.com",
"name": "John Doe",
"office": "1122",
"phone": "555-555",
"status": "active",
},
{
"_id": "58aabc92e846502357fc0f69",
"email": "mail#me.com",
"name": "John Doe",
"office": "1122",
"phone": "555-555",
"status": "active",
},
{
"_id": "58aabc92e846502357fc0f69",
"email": "mail#me.com",
"name": "John Doe",
"office": "1122",
"phone": "555-555",
},
{
"_id": "58aabc92e846502357fc0f69",
"email": "mail#me.com",
"name": "John Doe",
"office": "1122",
"phone": "555-555",
}
]
COUNT(#/name;) counts all occurrences of name in the JSON stream.
How do I only count active members? Eg. where status = 'active'
How about this?
COUNT(#/name[status='active'];)

angularJS JSON parsing

I am new to angularJS and trying to parse the data and display it on a page.
{
"count": 13,
"status": 200,
"statusMessage": "OK",
"userContact": [
{
"user": {
"id": 1,
"firstName": "test",
"lastName": "test",
"universityId": 1,
"email": "test#harbingergroup.com",
"password": "",
"phoneNo": "1234567890",
"gender": "M",
"userType": 1,
"medicalComments": "",
"dob": "2015-02-22",
"universityAffiliation": 1,
"cityId": "1"
},
"userContactList": {
"count": 2,
"status": 200,
"statusMessage": "OK",
"contact": [
{
"id": 2,
"userId": 1,
"firstName": "test",
"lastName": "user",
"phoneNo": "9876543210",
"email": "test#example.com"
},
{
"id": 24,
"userId": 1,
"firstName": "first1",
"lastName": "last1",
"phoneNo": "9876543210",
"email": "test#example.com"
}
]
}
}]
}
this is my JSON data.What i am trying is :
<tr ng-repeat="studentDetails in studentProfileData">
studentDetails.status for getting status and studentDetails.userContacts.firstName for first name
but I am not getting the data. What is wrong here?
Assuming that studentProfileData contains a list of users (userContact):
studentDetails.user.firstName
will contain "test"

ACS review condition failure

I'm working in an android app using Titanium appcelerator.
Now i'm trying out ACS REVIEWS .. I'm getting the whole db result , i need to filter by id. For that i tried to put Where condition ..But it doesn't working..
My Json
{
"id": "52ea3eba08a3e5704b330c2a2a",
"rating": 3,
"created_at": "2014-01-30T11:59:54+0000",
"updated_at": "2014-01-30T11:59:54+0000",
"user": {
"id": "52e5f3881356b440b4b09c805",
"created_at": "2014-01-27T05:50:00+0000",
"updated_at": "2014-01-29T04:29:49+0000",
"external_accounts": [
],
"confirmed_at": "2014-01-27T05:50:00+0000",
"username": "Gk",
"role": "j",
"admin": "false",
"custom_fields": {
"phone": "91959454651",
"usertype": "0",
"status": "1",
"ios_deviceid": "",
"country_code": "IN",
"verify_code": "4574",
"verified": "1",
"contact_sms": "1",
"contact_message": "1",
"contact_email": "1",
"contact_phone": "0",
"android_gcmid": "APA91bE0mcScNlXbCENZ2D_9jylgwdwOJ6vYTqnI_Kzqx2lqLWblnn6mT4PJ6iZRNxUGA66Ke7RJ0CKC44DL3mturNs_w3QT7KhTVIWbQE2tJgBHU7gpzB2GG4sFGXL6LiayJ5zEn_AGhxBlw"
}
},
"reviewed_object": {
"type": "Post",
"id": "52e7800313556440b4b0aa134"
},
"custom_fields": {
}
},
{
"id": "52ea3e9d4430d0b1e0c1c16",
"rating": 3,
"created_at": "2014-01-30T11:59:25+0000",
"updated_at": "2014-01-30T11:59:25+0000",
"user": {
"id": "52e8fe464643d0b130b85f5",
"first_name": "Ganesh",
"last_name": "test",
"created_at": "2014-01-29T13:12:38+0000",
"updated_at": "2014-01-29T13:12:38+0000",
"external_accounts": [
],
"confirmed_at": "2014-01-29T13:12:38+0000",
"username": "john",
"role": "r",
"admin": "false"
},
"reviewed_object": {
"type": "Post",
"id": "52e7800343556b4dsfsdfh3434"
},
"custom_fields": {
}
},
]
I want to filter using this id..
"reviewed_object": {
"type": "Post",
"id": "52e7800343556b4dsfsdfh3434"
}
What should i write in my WHERE Condition..
Cloud.Reviews.query({
page : 1,
per_page : 20,
where : {
rating : {
'$gt' : 1.0
},
},
order : "-created_at"
}
i have added my post id condition without where statement ..It worked perfectly..
My Code:
Cloud.Reviews.query({
page :1,
per_page : 20,
post_id : Your Post id
}, function(e) {
if (e.success) {