couchbase query returning empty answer - nosql

hello im trying to get query from couchbase and getting a blank answer
this is my data :
this is my data and its keep going like that
i cant get any tagnames and im kinda lost so i would be glad to get any help
i tryed
:
SELECT b.*
FROM mekorot[0] b
WHERE node.kind = 2
and im still getting :
{
"results": []
}

I don't think IN is doing what you think it should be doing. IN is meant for queries like SELECT * FROM foo WHERE x IN ['array0','array1']. I'm not sure why this query isn't giving you parsing errors, but try this instead:
SELECT b.*
FROM backetname b
WHERE b.node.kind = 2
Here's some screenshots showing it in action:

Related

getting the relation data from where clause in view

I have the following query
$partner = DeliveryPartner::with(['deliveryPartnerImage' => function($q) {
$q->where('image_type', '=', 'logo');
}])
->find($id);
this works. for a partner with a logo it shows a relation with 1 item like so
and when i change the where clause to something non existent for example $q->where('image_type', '=', 'testtesttest');
it shows a empty array like this
so i know my query works but how to get this data in the view?
i did $partner->deliveryPartnerImage()->first() But for some reason this always shows data? also when i change the query... so im guessing im doing this wrong but i can not find another way to do this?
Use this:
$partner->deliveryPartnerImage
$partner->deliveryPartnerImage()->first() executes a new query without the where() constraint.

Not able to pass complete datetime(Y-m-d H:i:s) in DB::raw in eloquent

$shop=DB::table('shops')
->leftJoin('orderbookings',function($join)
{
$join->on('shops.id','=','orderbookings.shop_id');
$join->on('orderbookings.created_at','>=',DB::raw(date("Y-m-d",strtotime("now"))));
})
->select('shops.*')
->selectRaw('COUNT(orderbookings.id) as totalorder, SUM(orderbookings.grand_total) as gtotal')
->orderBy('shops.shop_name', 'asc')
->groupby('shops.id')
->paginate(10);
Above code working fine(But not giving total order and amount correct) and also gives result almost close to what I want,
But I am not able to give date format (Y-m-d H:i:s), it shows syntax error. I am using Laravel 5.2 version
Note: I want to give time as well with date to rectify result,
On giving [example: 2017-03-08 11:15:00] shows syntax error
working query in mysql
SELECT COUNT(orderbookings.id), SUM(orderbookings.grand_total), shops.shop_name FROMshopsLEFT JOIN orderbookings on orderbookings.shop_id = shops.id and orderbookings.created_at BETWEEN "2015-10-22 17:02:02" AND "2017-03-07 17:02:02" GROUP BY shops.id
But not able to to convert in eloquent
You should be able to do the following:
$join->on('orderbookings.created_at', '>=', date("Y-m-d"));
You don't need to use DB::raw, and leaving the second parameter null for date, assumes "now".
If this doesn't solve your issue, please post the exact error you're seeing.

SQL Response to JSON for non-trivial query

I have this query that works in studio, which for a given worker, returns those other workers that recommend them.
[Worker:V] -> [RecommendedBy:E] -> [Worker:V]
Im constructing SQL to return some selected data from the E and the V that is recommending. So below works
SELECT out('RecommendedBy').firstName as recommendedByFirstName,
out('RecommendedBy').lastName as recommendedByLastName,
out('RecommendedBy').#rid as recommendedByRID,
outE('RecommendedBy').recommendationHeadline as headline
FROM Worker WHERE userName = 'paulw';
How can I convert the response to the above adhoc query to a single JSON object using #this.toJSON? I can get something like below to work Ok:
SELECT #this.toJson('rid,version,fetchPlan:in_RecommendedBy:1') FROM Worker WHERE userName = 'paulw';
but not for the first SQL. Any help appreciated thanks!
I'm not sure I understand what you need, is this useful?
SELECT #this.toJson() FROM (
SELECT out('RecommendedBy').firstName as recommendedByFirstName,
out('RecommendedBy').lastName as recommendedByLastName,
out('RecommendedBy').#rid as recommendedByRID,
outE('RecommendedBy').recommendationHeadline as headline
FROM Worker WHERE userName = 'paulw')

Sailsjs-Waterline : How to filtering after populate?

I'm using sailjs + waterline, how to filtering data after populate models? here i try my code and doesn't work :
Approductbranch
.find({deleted:1})
.populate("mproduct_id",{where:{deleted:1}})
.paginate({page:currpage,limit:utils.RowPerPage})
.exec(callback)
in my code above, i want to execute sql like this :
select * from approductbranch a
inner join mproduct a
on a.id = a.mproduct_id
where a.deleted = 1
and b.deleted = 1
how to do this? thank! :)
Good question.
There currently isn't a way to do this directly, but there is an outstanding feature request in the Waterline repository that you can share your thoughts in.
I think you can do like this:
Approductbranch
.find({deleted:1})
.populate("mproduct_id",{deleted:1, skip:currpage * utils.RowPerPage, limit:utils.RowPerPage})
.exec(callback)
it will be OK!
You can filter a set of values before you populate. This is more performant since you're not getting more values than you need: https://github.com/balderdashy/sails-docs/blob/master/reference/waterline/queries/populate.md

Connect to Access database from matlab

I was trying to connect to a Access database from matlab, by following the example given in matlab documentation
1 setdbprefs('DataReturnFormat','cellarray')
2 url = [['jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DSN='';DBQ='] dbpath];
3 con = database('','','','sun.jdbc.odbc.JdbcOdbcDriver', url);
4 sql = ['select * from ' table_name] ;
5 cursor = exec(con,sql);
6 cursor = fetch(cursor);
7 data.data = cursor.data;
I got the following error when I was requesting data from table A, at line 6, the error message was:
Error using cell
Size inputs must be integers.
Error in cursor/fetch (line 329)
outCursor.Data =
cell(rowLimit,
numberOfColumns);
I tried fetch data from other tables in the same database, it went without problem. What might be the issue?
Please refer to the documentation. fetch must be called with two parameters, connection and query and it returns the result, not a cursor.
Ok, I still hadn't got to the bottom of this yet, but retrieving the data incrementally worked for me, by setting the preference:
setdbprefs('FetchInBatches', 'yes');
setdbprefs('FetchBatchSize', '2');
#Daniel's answer also works fine, but it is difficult to get the column headers that way (let me know if you know how, I tried using another sql query but if did not work for me)...