How to push a js object to a json array using postgreSQL? - javascript

Im using supabase. i have a json array column in a table. it is a little difficult to push an object to it. i should get that json array, push an object to it and update that column. i should send two requests and its not what i want because it makes some problem in my web app.
I was looking for answer and i found postgreSQL. I can create my custom query and i can for example write a query that takes an object and push that to a column. And thankfully i can use it in supabase. But i have a lot of problem in using this. Can you please tell me how can i write a query that gets an object and push that object to a column in supabase?
I tested some queries. I found some json methodes in postgreSQL document and i tested them but i got error. Thanks for helping

Related

Mongo db update a object in a array, just first object is updated

I am using the node.js framework from this tutorial: https://www.w3schools.com/nodejs/nodejs_mongodb.asp
I have a strange problem which i dont understand, i have make a picture for better understanding:
picture from my database and nodejs code
If i just try to update another object in this array it does not work, but if i update the first object it does work, so please does somebody know why, is the mongo client which i use not good or does my query have a error?
First off, code examples shouldn't be shared via an external picture. This should be provided as a code snippet in your question.
Now as to the reason why it isn't working. You don't have an array of objects, you have an array of array of objects.
If you look at the first one in the array of questions, it is an object, but if you look at the second one, you can see that it is an array that includes 1 object in it. You will need to make sure your questions array is an array of objects and not an array of arrays with objects. Then your query will work. See below from your given example.

Alpha anywhere: How to get all the data from the list so that I can access them using Javascript

Using alpha anywhere. I have a list, say 'roles' and 'companies' filtered by user_code. I am using it offline so I need everything to be pre-populated while connection available. When Offline, I need to filter the list by company so that I can get the 'roles' based on the current company_session. Can anybody point me to the right way? Or at least can anyone teach me how to get the data from the A5W list and bring them to javascript accessible like javascript array, or JSON format?
I figured it out. too long on a computer. Alpha Anywhere actually have simplified this. In UX component method I found getListData method. It done exactly what I need!! at least I am one step ahead.
var data = {dialog.Object}.getListData('USERROLESLIST');
var dataJSON = JSON.stringify(data);
Then, the JSON.stringify give me the visual of the actual data in the list.

How to do full-text search in a MySQL table using Fuse.js and Redis?

I have a table with a thousand records in it and I want to do a google like search full-text/fuzzy search.
I read about MySQL v8's Full-Text search and let's say we don't have that functionality yet.
There is this JavaScript library called Fuse.js that do fuzzy-search which is what I need.
I can combine it by creating a API that returns the table data in JSON format and then pass it to Fuse.js to do a fuzzy-search.
Now, I think it's not recommended to load all data from table every time someone wants to search.
I read about Redis, and the first thing that came in my mind is to save all table data in Redis using JSON.stringify and just call it every time instead of querying the database. Then whenever a data is added in the table, I will also update the contents of the data in Redis.
Is there a better way to do this?
That is a very common caching pattern.
If you need a more efficient way to store and retrieve your JSON to/from Redis you might want to consider one of the available Redis Modules.
e.g.
RedisJSON allows you to efficiently store, retrieve, project (jsonpath) and update in place.
RediSearch allows you to have full text search over Redis Hash and efficiently retrieve data according to the user's query.
Last
RedisJSON2 (aka RedisDoc) combines both modules above, meaning efficient JSON store and retrieve with Full Text support

Ajax data management

I'm not really comfortable working with Ajax as I just started using it.
My question is as follows:
What is the best way to manage data fetched using Ajax?
I have a script that fetches data from a database and displays it in different ways depending on the users filters and order criterias. So far, I query the database for every requests and was thinking if it could be better to fetch all data at once, store it in an array of objects and run queries like ordering and category filtering locally using Javascript.
Any gains in termms of speed and/or performance?
Thank you.
Show an example first. An example of the data that is fetched from database and the required way to arrange them. You can use XML or JSON or straight JavaScript object. the question is which one do you like to work with? I would choose the returned data from database to be in XML format. Show us an example of code where you don't know what to do.

Mustache.js and YQL jSON

I am not really sure how to get data out of this nested object with Mustache.js. I am using the YQL multi query that brings back my data objects nested https://gist.github.com/866247. My problem comes when I am trying to access the nested objects
The data comes back like this where 0 and 1 are part of an array with objects in them. Here is a picture of the tree http://cl.ly/1e1b3O3U233e2I0d3g2f.
query
results
results
0
1
I have tried the template below and I don't get anything back. I believe the problem is that that second "results key" comes back with the array and mustache doesn't know what to do.
"{{#query}}
{{#results}}
{{#results}}
{{#photo}}
{{farm}}
{{#photo}}
{{/results}}
{{/results}}
{{/query}}"
If this makes sense to anyone, how do I access the nested objects in the array if there is no key to them?
I think you should flatten your data into a simpler format to write a template that makes sense, but you can get pretty close to what you want with it as-is.
The one insurmountable issue I saw was that 'results' is inside 'results' resulting in a tag closure mismatch. Doing something like this solves that problem:
data.query.flattened = data.query.results.results;
A functional sample is here.
You can find some more mustache tricks in this article.
This is one of the types of issues with Moustache that Handlebars attempts to address - traversing through objects in the template:
http://handlebars.strobeapp.com/#paths
Where you access it directly as if it's a directory structure. I know this isn't an answer to your question, per-se, but aside from flattening the data it's an alternative solution.

Categories