How do I perform a SQL update on a list inside one of my table rows? - sql

I have a table with parameters as shown below.
{
id: 1,
title: 'waccos',
description: 'Making an operating system in wacc',
est_duration: 420,
exp_req: 'any',
langs: [ 1 ],
owner: 1,
members: [ 1, 2 ]
},
I want to use SQL to add a new member into the member list, but I do not know how to. The table is called testprojects. I've tried using
(update testprojects
set members = members || $1
where title is $2;', [name, title])
but I think that is wrong. Could anyone help me please?
This is the table of members so far.
[
{ id: 1, name: 'A' },
{ id: 2, name: 'K' },
{ id: 3, name: 'S' },
{ id: 5, name: 'd' },
{ id: 6, name: 'J' },
{ id: 7, name: 'E' },
{ id: 8, name: 'a' }
]

Related

How do I search in redis json

I'm currently new to ioredis and I was wondering how o I can search all the json object that has a key value of something.
Example
rooms:{
roomId1: {
name: "room1",
users: [{userId: 1, name: "bob"}, {userId: 2, name: "joe}]
},
roomId2: {
name: "room2",
users: [{userId: 1, name: "jill"}, {userId: 2, name: "joe}]
},
roomId3: {
name: "room3",
users: [{userId: 6, name: "hoi"}, {userId: 1, name: "bob}]
}
}
and I want find all the rooms that has the user "bob" so I want the output to be
[roomId1: {
name: "room1",
users: [{userId: 1, name: "bob"}, {userId: 2, name: "joe}]
}, roomId3: {
name: "room3",
users: [{userId: 6, name: "hoi"}, {userId: 1, name: "bob}]
}]
How cna i achievee this? I guess I can do something like this
const redis = new Redis();
const roomStates = await redis.get("rooms");
//for loop and inner for loop to find the users name bob
but I was wondeirng if theres a faster way of doing it using the redis built in functions

How to generate json from two SQL queries?

Tell me who knows how to make a json response of the desired format from two sql requests.
Base (client groups) #1 clients_groups has id_clients and name columns.
id_clients here are client IDs through whom from the clients database.
name is the name of the section.
Base (List of clients) No. 2 clients has data about users.
How to make json. Example as needed:
`
{
id: '',
text: 'Department №1',
children: [ // Here at the bottom you need to get a list of users by ID from department No. 1
{ id: 'User ID', text: 'Username' },
{ id: 'User ID', text: 'Username' }
]
},
{
id: '',
text: 'Department №2',
children: [ // Here at the bottom you need to get a list of users by ID from department No. 2
{ id: 'User ID', text: 'Username' },
{ id: 'User ID', text: 'Username' }
]
}
`
I tried to link data from an attachment through a loop. Nothing helped.
query("SELECT id, id_clients, name FROM clients_groups", (error, results) => {
console.log(results);
})
[
RowDataPacket { id: 1, id_clients: '2', name: 'Manager' },
RowDataPacket { id: 2, id_clients: '2, 3', name: 'Support' }
]

Apex Line Area chart is not getting displayed on the page in Vuejs

I am stuck on a page where i am not able to display the charts on the page.
To make it simplify what I have done is, here is the code sandbox:
I see there an error in console about the data, I am not sure about it.
https://codesandbox.io/s/compassionate-snyder-bckoq
I want to display the chart like this (as an example), but I am not able to display on the code sandbox
Please help.
The format of series is not aligned with ApexCharts.
You need to transform the data to match with ApexChart format.
Please see the changes in the codesandbox.
https://codesandbox.io/s/small-dew-eztod?file=/src/components/HelloWorld.vue
options: {
// X axis labels
xaxis: {
type: 'date',
categories: ["2021-05-04", "2021-05-05", "2021-05-07"]
},
},
series: [
{
name: "total",
data: [2, 2, 1],
},
{
name: "pending",
data: [0, 1, 0],
},
{
name: "approved",
data: [2, 1, 1],
},
{
name: "rejected",
data: [0, 0, 0],
},
],
Transform data to fit ApexChart
const data = {
"2021-05-04": {
total: 2,
pending: 0,
approved: 2,
rejected: 0,
},
"2021-05-05": {
total: 2,
pending: 1,
approved: 1,
rejected: 0,
},
"2021-05-07": {
total: 1,
pending: 0,
approved: 1,
rejected: 0,
},
};
const xaxis = {
type: "date",
categories: Object.keys(data).map((key) => key), // ['2021-05-04', '2021-05-05', '2021-05-07']
};
let statusObj = [];
for (const dataValue of Object.values(data)) { // get the values from keys '2021-05-04', '2021-05-05' ...
// loop the values, e.g. 1st loop: { total: 2, pending: 0, approved: 2, rejected: 0, }
for (const [key, value] of Object.entries(dataValue)) {
// take 'total' as example, find if statusObj already has { name: 'total', data: [x] }, e.g. statusObj = { name: 'total', data: [1] }
const existingStatusIndex = Object.keys(statusObj).find(
(sKey) => statusObj[sKey].name === key
);
// if yes, return the index of it
if (existingStatusIndex) {
// add new data value to existing data object. e.g. { name: 'total', data: [1, 2] }
statusObj[existingStatusIndex].data.push(value);
continue;
}
// if no, create a new object and add it to statusObj
statusObj.push({
name: key,
data: [value],
});
}
}
Output:
xaxis {
type: 'date',
categories: [ '2021-05-04', '2021-05-05', '2021-05-07' ]
}
statusObj [
{ name: 'total', data: [ 2, 2, 1 ] },
{ name: 'pending', data: [ 0, 1, 0 ] },
{ name: 'approved', data: [ 2, 1, 1 ] },
{ name: 'rejected', data: [ 0, 0, 0 ] }
]

How to compare two arrays in Standard SQL (BigQuery)?

I have two tables with the exact same schema, one of the fields is a record and I try to compare this field between the two tables.
For example:
Table A:
{ Name: 'Mary',
DOB: '06.06.1970',
Children:[
{ Name: John, Age: 6 },
{ Name: Agatha, Age: 10}
]
},
{ Name: 'Bob',
DOB: '30.03.1982',
Children:[
{ Name: Anthony, Age: 9 },
{ Name: William, Age: 4 },
{ Name: Rose, Age: 2 }
]
},
{ Name: 'Adam',
DOB: '312.10.1980',
Children:[
{ Name: Andrew, Age: 9 },
{ Name: Kate, Age: 4 }
]
}
Table B:
{ Name: 'Mary',
DOB: '06.06.1970',
Children:[
{ Name: John, Age: 6 },
{ Name: Agatha, Age: 10}
]
},
{ Name: 'Bob',
DOB: '30.03.1982',
Children:[
{ Name: Anthony, Age: 9 },
{ Name: George, Age: 4 },
{ Name: Frank, Age: 2 }
]
},
{ Name: 'Adam',
DOB: '312.10.1980',
Children:[
{ Name: Andrew, Age: 9 },
{ Name: Kate, Age: 4 },
{ Name: Jonathan, Age: 2 }
]
}
The output I'd like to get is:
Name
----------
Bob
Adam
Since the Children details are not the same for Bob or Adam in table A and table B (whenever it's the size of the record (num of children) or the details (children names etc...))
I tried to use SELECT UNION DISTINCT but it doesn't work on an array, I also tried != and <> but it doesn't work on arrays...
It would be ideal to compare two arrays like you can compare two lists in Python (comparing the structure and the content).
Is there a way to implement something similar ?
Thank you
select name
from `project.dataset.tableA` a
join `project.dataset.tableB` b
using(name)
where a.dob != b.dob
or (select string_agg(format('%t', s) order by name) from a.children s)
!= (select string_agg(format('%t', s) order by name) from b.children s)

Deep assertion on JSON array with contains in Karate

Scenario:
Given def cat =
"""
{
name: 'Billie',
kittens: [
{ id: 23, name: 'Bob', age: 35 },
{ id: 42, name: 'Wild', age: 25 }
]
}
"""
Then match cat.kittens contains [{ id: 42, name: 'Wild' }, { id: 23, name: 'Bob' }]
As seen in the example, I am not worried about 'age'. I understand that I can use '#ignore'. Is there any other way, if I have lot of such nodes that I have to ignore.
I am just thinking, can it work with JSON arrays as it does with JSON Objects. asserting only specified nodes.
error:
assert.feature:24 - path: $.kittens[*], actual: [{"id":23,"name":"Bob","age":35},{"id":42,"name":"Wild","age":25}], expected: {id=42, name=Wild}, reason: actual value does not contain expected
EDIT:
I tried something suggested in Karate - how to check if array contains values?
but that did not help me. I am not looking for schema-validation instead I am looking for functional validation where every object may have different values for keys.
Below one fails
Scenario:
Given def cat =
"""
{
name: 'Billie',
kittens: [
{ id: 23, name: 'Bob', age: 35 },
{ id: 42, name: 'Wild', age: 25 }
]
}
"""
* def expected = [{ id: 42, name: 'Wild' }, { id: 23, name: 'Bob' }]
Then match cat.kittens contains '#(^expected)'
This one works fine but this is not helping me.
Scenario:
Given def cat =
"""
{
name: 'Billie',
kittens: [
{ id: 23, name: 'Bob', age: 35 },
{ id: 42, name: 'Wild', age: 25 }
]
}
"""
* def expected = { id: 42, name: 'Wild' }
Then match cat.kittens contains '#(^expected)'
Currently, I am reading arrays separately and asserting them with loop.
Just adding the word deep works in 0.9.6.RC4
Then match cat.kittens contains deep [{ id: 42, name: 'Wild' }, { id: 23, name: 'Bob' }]
I don't understand why the linked answer when I closed your first question did not help you. Maybe I don't understand, and someone else can provide a better answer.