I have express api with mysql db.For some reason I am not able to print the value of sub array array coming from db, however if I console.log(menu) it's printing fine.
Error showing is "TypeError: Cannot read properties of null (reading 'monday')". Spent 2 hours but not getting any solution, thanks in advance.
Here is my code
let menu = JSON.parse(Item.personal_custom_menu);
console.log(menu.monday);
Value for Item.personal_custom_menu which is coming from db is this
{
"monday":[{"title":"Lasagna","id":45},{"title":"Khawsey Curry","id":42},{"title":"Khawsey Curry","id":42}],
"tuesday":[{"title":"Khawsey Curry","id":42},{"title":"Khawsey Curry","id":42},{"title":"Khawsey Curry","id":42}],
"wednesday":[{"title":"Khawsey Curry","id":42},{"title":"Khawsey Curry","id":42},{"title":"Khawsey Curry","id":42}],
"thursday":[{"title":"Khawsey Curry","id":42},{"title":"Khawsey Curry","id":42},{"title":"Khawsey Curry","id":42}],
"friday":[{"title":"Khawsey Curry","id":42},{"title":"Khawsey Curry","id":42},{"title":"Khawsey Curry","id":42}],
"saturday":[{"title":"Khawsey Curry","id":42},{"title":"Khawsey Curry","id":42},{"title":"Khawsey Curry","id":42}],
"sunday":[{"title":"Khawsey Curry","id":42},{"title":"Khawsey Curry","id":42},{"title":"Khawsey Curry","id":42}]}
Related
I'm working on my project with ASP.NET Core 3.1 and Entity Framework Core. I have a table with a column of Date datatype:
[Column(TypeName = "Date")]
[Required]
public DateTime Date { get; set; }
Recently when I insert data in this table, date is inserted like below:
It is marvelous that when I read data from this table to show in calendar plugin, date is correct format:
This is my code for save data in database:
var dtDate = Convert.ToDateTime(date);
_db.ImPossibleReserveDates.Add(new ImPossibleReserveDate
{
Date = dtDate.Date,
InsertTime = DateTime.Now,
IsRemoved = false
});
And this code for read data:
var list = _db.ImPossibleReserveDates.Where(x => !x.IsRemoved).Select(x => new
{
date = x.Date.ToString("yyyy-MM-dd"),
TITLE = "تعطیل"
});
No matter in server or local!
Why did this happen?
check your converted date in server before save it
its seem two convert in your date
I am using node-adodb in my electron app. I query mdb file but i get datetime in wrong timezone. How can i set timezone or Do i query using wrong method.
My date format in mdb file
USERID CHECKTIME
421 2/11/2019 11:54:19 AM
433 2/11/2019 11:54:18 AM
431 2/11/2019 11:54:17 AM
I am using node-adodb with electron
https://www.npmjs.com/package/node-adodb
I want to retrieve checktime and badgenumber from mdb file using lastupdatetime and save it in another table with lastupdatetime. After trying hard i am able to retrieve datetime from mdb file . Here is my code
var connection = this.adoDb.open('Provider=Microsoft.JET.OLEDB.4.0;Data Source=D:\\SIMS\\bio_att\\att2000.mdb');
let ab = '2019/02/11:11:10:00';
connection
.query("SELECT CHECKINOUT.CHECKTIME,USERINFO.Badgenumber FROM CHECKINOUT INNER JOIN USERINFO ON CHECKINOUT.USERID = USERINFO.USERID WHERE format(CHECKINOUT.CHECKTIME,'yyyy/mm/dd:HH:mm:ss') >= '"+ab+"'")
.then(data => {
console.log(JSON.stringify(data, null, 2));
})
.catch(error => {
console.error(error);
});
When i query datetime it returns correct data but in wrong timezone. Is there any way to get correct timezone?
return data is correct
but timezone is wrong
I found a solution. I changed
"SELECT CHECKINOUT.CHECKTIME"
to
"SELECT format(CHECKINOUT.CHECKTIME,'yyyy/mm/dd HH:mm:ss')"
and now it returns date in correct timezone.
I hope its helpful if someone is looking for that
let ab = '2019/02/11 11:10:00';
connection
.query("SELECT format(CHECKINOUT.CHECKTIME,'yyyy/mm/dd HH:mm:ss') ,USERINFO.Badgenumber FROM CHECKINOUT INNER JOIN USERINFO ON CHECKINOUT.USERID = USERINFO.USERID WHERE format(CHECKINOUT.CHECKTIME,'yyyy/mm/dd HH:mm:ss') >= '"+ab+"'")
.then(data => {
this.dData = data;
console.log(JSON.stringify(data, null, 2));
this.ldsRllrDisplay = 'none';
})
.catch(error => {
console.error(error);
});
I'm following the example given in https://cloud.google.com/bigquery/create-simple-app-api#bigquery-simple-app-java to obtain query results from BigQuery API.
TableResult result = queryJob.getQueryResults();
It returns the results in a TableResults type but I need to get the results in a json format.
TableResult{rows=[[FieldValue{attribute=PRIMITIVE, value=(...)},
FieldValue{attribute=PRIMITIVE, value=(...)},
FieldValue{attribute=PRIMITIVE, value=(...)},
FieldValue{attribute=PRIMITIVE, value=(...)},
FieldValue{attribute=PRIMITIVE, value=(...)},
FieldValue{attribute=PRIMITIVE, value=(...)},
FieldValue{attribute=PRIMITIVE, value=(...)}],(...)
How can I transform the results in TableResults type to json, or even csv?
To convert rows in a table to JSON you can use the function TO_JSON_STRING [1].
To get a JSON with formatting you need to pass the parameter “true” to the function.
The new query would look like this:
#standardSQL
“SELECT TO_JSON_STRING(t,true)"
+ "FROM (
SELECT CONCAT('https://stackoverflow.com/questions/', CAST(id as STRING)) as url, "
+ "view_count "
+ "FROM `bigquery-public-data.stackoverflow.posts_questions` "
+ "WHERE tags like '%google-bigquery%' "
+ "ORDER BY favorite_count DESC LIMIT 10) as t”
Output:
TableResult{rows=[[FieldValue{attribute=PRIMITIVE, value={
"url": "https://stackoverflow.com/questions/6607552",
"view_count": 24524
}}], [FieldValue{attribute=PRIMITIVE, value={
"url": "https://stackoverflow.com/questions/20349189",
"view_count": 4298
}}], [FieldValue{attribute=PRIMITIVE, value={
"url": "https://stackoverflow.com/questions/22734777",
"view_count": 7940
}}], [FieldValue{attribute=PRIMITIVE, value={
"url": "https://stackoverflow.com/questions/27537720",
"view_count": 2039
(...)
So I have a ouath web app that connects to youtube. I use the youtube analytics calls to get information like number of subscribers from my channel. But right now I try to make a top 10 videos from my channel with the views count for every video included in the response. I use this documentation:
Top videos for subscribed or unsubscribed viewers
My call looks like this:
$command = 'curl -H "Authorization: Bearer ' . $access_token . '" "https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3DMINE&start-date=' . date('Y-m-d', strtotime('-31 days')) . '&end-date=' . date('Y-m-d', strtotime('today')). '&metrics=views&dimensions=video&sort=views"';
But I get an error message as a response:
"The query is not supported. Check the documentation at https://developers.google.com/youtube/analytics/v1/available_reports for a list of supported queries."
I also tried this call with YoTube data API:
$videos_url = 'https://www.googleapis.com/youtube/v3/search?part=snippet&forMine=true&order=viewCount&type=video&access_token=' . $access_token;
But it provides this response:
["kind"]=>
string(26) "youtube#searchListResponse"
["etag"]=>
string(57) ""######""
["nextPageToken"]=>
string(112) "#######"
["pageInfo"]=>
object(stdClass)#267 (2) {
["totalResults"]=>
int(1)
["resultsPerPage"]=>
int(5)
}
["items"]=>
array(1) {
[0]=>
object(stdClass)#270 (4) {
["kind"]=>
string(20) "youtube#searchResult"
["etag"]=>
string(57) ""#####""
["id"]=>
object(stdClass)#269 (2) {
["kind"]=>
string(13) "youtube#video"
["videoId"]=>
string(11) "####"
}
["snippet"]=>
object(stdClass)#273 (6) {
["publishedAt"]=>
string(24) "2016-09-14T14:49:49.000Z"
["channelId"]=>
string(24) "#####"
["title"]=>
string(12) "My Slideshow"
["description"]=>
string(87) "I created this video with the YouTube Slideshow Creator (http://www.youtube.com/upload)"
This response provides no views count. I need for every video to get the views count as well.
Any ideas on how to accomplish this? Any help is welcomed! Thank you all for your time!
The issue with your youtube analytics api request is sort parameter. Try using value -views instead of views. You can double check the API link you provided. Also set the max-results
Example URL :
https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3Dmine&start-date=2016-05-01&end-date=2016-09-01&metrics=views&dimensions=video&max-results=10&sort=-views&key={YOUR_API_KEY}
There are 1 million entries in a mysql table [name VARCHAR, id bigint(20), category int(11)]
I use the following SELECT SQL in mybatis select xml
<select id="getIdNameMap" parameterType="String" resultType="java.util.HashMap">
select NAME , ID from PRODUCTS where CATEGORY = #{value}
</select>
I use the following java code
Reader reader = Resources.getResourceAsReader(SQL_MAP_CONFIG_FILE_PATH);
sqlMapClient = new SqlSessionFactoryBuilder().build(reader);
SqlSession sqlSession = sqlMapClient.openSession(true);
Map kvpList = sqlSession.selectMap("getIdNameMap", "1", "NAME");
It takes 6902 secs to pull data into the map
With the following code it takes 2368 Secs to pull the same data into a map
ResultSet rs = sqlSession.getConnection().createStatement().executeQuery("select NAME , ID from PRODUCTS where CATEGORY = 1");
while (rs.next()){
map.put(rs.getString(1), Long.parseLong(rs.getString(2)));
}
System.out.println(map.size());
rs.close();
Any suggestions?