what's the order of data when I try to get data from supabase? [closed] - javascript

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 12 hours ago.
Improve this question
I'm using supabase database to store my data, here is one table:
myTable, then I try to use fetch method in JavaScript to get data back, the code are as follows:
const res = await fetch('-', {headers: {apikey: '-',authorization: 'Bearer -',}}); fieldVal = await res.json();
(I have omitted the link)
Then I got the data back, but the order of the data confused me,
data
So, why the data of id equals 5 is the last data? Shouldn't be after the data of id equals 4?
This is my first time to use supabase, and I have scanned the docs and API, but it's a lot of other stuffs, I can't precisely locate the information I need.

You can order your query using supabase-js: https://supabase.com/docs/reference/javascript/order
const { data, error } = await supabase
.from('countries')
.select('id', 'name')
.order('id', { ascending: false })

Related

How can I get data from the url and parse it for getting hobbies or names? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
This post was edited and submitted for review 1 year ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I tried so many things and I researched lots of sites. But I can't find that how to parse this data without using modules. I am using node.js for this. My problem is I can't get the data from url to parse it. I hope my question is clear now. Thanks for answers.
const https = require("https");
https.get("https://coderbyte.com/api/challenges/json/rest-get-simple", (resp) => {
}
);
The documentation of the https.get function provides you with an example. Does that help you?
const https = require('https');
https.get("https://coderbyte.com/api/challenges/json/rest-get-simple", (res) => {
res.on('data', (d) => {
obj = JSON.parse(d.toString());
console.log("Hobbies",obj.hobbies);
});
}).on('error', (e) => {
console.error(e);
});
So within the get callback you need a listener on if some data was received.

How to write API with multiple parameter in express.js [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm a bit new to Node.js and writing some GET REST APIs in Express.js. For one of my API, I need to pass 2 parameters to get the data from the database. I have achieved it using a single parameter but not more than 2. anyone help me, please?
Here my function
getByNPPTahunBulan(req,res){
console.log(req.param.tahun_bulan)
Iuran_Dapen.findAll({
where: {
tahun_bulan: req.params.tahun_bulan,
npp: req.param.npp
}
}).then((data) => {
return res.send(data);
}).catch((err) => {
res.status(500).send({
message: err.message || 'Some error occurred while retrieving data.',
});
})
},
and the url router.get('/iuranterakhir/:tahun_bulan/:npp', iuranDapen.getByNPPTahunBulan);
req.params contains a parameter object with its respective value with the following url /:id/:name
ej.
{
'id': 1,
'name': 'foo'
}
and you can do something like this:
const params = req.params;
and access as follows
params.id or params.name
the keys of the objects depends on the name of the parameters that you have given in the definition of your endpoint

handle data in LocalStorage [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
If I work with tables (using react-tabele in my case), which store lot of pages of content.

When I first open first page and put that data in localStorage, then open second page and put that data to localStorage, then open third and store data in localStorage.

How should I handle it in reverse?

When I go back to second page, should I try to get data from localStorage() without sending request for those data?

Just bring it back from localStorage and render it?
If someone can give me example of using it in example similar like my case.
I saw mdn example, but they just wanted to show when you close tab you can inherit your old setup.
If I understand correctly, it's something related to caching your data in localStorage.
You can save timestamp together when you save the data to localStorage.
And when you arrive at that page again, you could check the timestamp and decide if you will send request or reuse the data in localStorage.
For example:
// when you save the data to localStorage
localStorage.setItem(KEY, JSON.stringify({
data: YOUR_DATA,
ts: Date.now()
}));
...
// when you read the data from localStorage
// here try/catch is used because JSON.parse will be error
// when the localStorage item is nothing or incorrect json string
try {
const { data, ts } = JSON.parse(localStorage.getItem(KEY));
if (Date.now() - +ts < SOME_SPECIFIC_TIMESTAMP) {
// use data
} else {
// send api
}
} catch (err) {
// send api
}
However it depends on why you save the data to localStorage.

how can I retrieve data from Firebase in web using javascript? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
How can I retrieve data from Firebase and add to html page?
and, How can I open new html pages automatically to add the data I was retrieving it?
example:
I have this course from firbase:
this key I was pushing it .
and I want my website like this course :
When I click this courses I want to see all data about this course like this :
Can anyone help me ?!
I won't like this style just I want to know how can i retrieve data and add it in new html pages in the same style in all courses .
You can retrieve data from a firebase realtime database like so:
// Import Admin SDK
var admin = require("firebase-admin");
// Get a database reference to our posts
var db = admin.database();
var ref = db.ref("path/of/your/information");
// Attach an asynchronous callback to read the data at our posts reference
ref.on("value", function(snapshot) {
console.log(snapshot.val());
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
See Official Documentation here
Note: requires Node.js / npm

How to call Zillow API with JavaScript? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm new to APIs and am trying to figure out how to make a Zillow call with JavaScript, specifically the "getsearchresults".
Thanks
You'll need to use Javascript on the server-side using Node. It won't be possible to call the API on the front-end with Javascript. See this answer.
For using Node to call the Zillow API, check out the node-zillow package. Here's an example of how to use it with the GetSearchResults API call:
const Zillow = require("node-zillow")
const zillow = new Zillow('your key here')
const parameters = {
address: "2114 Bigelow Ave",
citystatezip: "Seattle, WA",
rentzestimate: false
}
zillow.get('GetSearchResults', parameters)
.then(results => {
console.log(results)
return results
})
Make sure you signup for ZWSID here: https://www.zillow.com/webservice/Registration.htm. You'll use this unique id when making the request to the API. It'll look something like this: X2-Ijdjkxlujnkd_jske2. Keep it secret, keep it safe!

Categories