Remove Fields when query at sails js - sails.js

i have a question. How can i solve to remove field packet when i query in sails js? OUTPUTThis is my codeCODE

sendNativeQuery will return object with 2 properties, rows (data) and fields (selected fields). Use return res.json(result.rows)

Related

Laravel in controller return new collection of results from a foreach loop through records

This seems like it should be obvious, but everything I find relates to returning a collection extracted from records, rather then returning a collection of new results derived from calculations on the records.
For instance, say I have records of property in my database. I can extract a collection of a subset (or the entire set) of the records. But I want to loop through this collection, calculate new values for each line item, (like marketValue-debt=netValue) and return a new collection of just those results to my view. I'm trying to keep my (much more complicated than this example) calculation in my controller and out of my view, but I'm not getting the way to stuff new values into a new collection of results for return to display in the view.
I could derive my results and stuff them into an array, but how do I pass this as a new collection for looping through in my view to show those results? Seems like there should be an Eloquent way to do this.
My project is in Laravel 6 running on Apache/Laragon, PHP 7 with MariaDb
Thanks in advance for helping me out.
Take a look at this. Hope it will be of some help.
If you want a new collection, use the map method.
$new_collection = $old_collection->map(function ($item) {
return $item->marketValue - $item->debtValue;
});

How to fetch distinct list from SpringData without using query annotation?

I am using 2 different properties to fetch distinct list eg
findDistinctBy<propertyName>And<propertyName>In(List<String> list).
My actual Spring jpa statement is
List<PojoClass> findAllByTpIdInAndDistinctMobile(List<String> edgeIds);
where TpId & Mobile are 2 different properties in PojoClass. I need to implement this without using Query annotation. Any suggestions of queryDsl will also do.
The question needs to be more clear.What exactly do you intend to achieve when the input is a list of Ids?
There is no option to provide a list to findAll unless it is an Id.
A simple way would be to loop the the input list in service and append the result to a result list.
for(String edgeId:edgeIds){
resultList.addAll(findByEdgeId(edgeId));
}
Updated code after #Tejas comment
for(Pojo pojo:Pojos){
resultList.addAll(findDistinctPojoByPropert1OrPropert2(String pojo.getProperty1(),String pojo.getProperty2());
}

Dynamic Sorting according to populated value?

There is a table named house which has many-to-many association with location table. Have to sort the list by the value of the location.street. Is there a way to sort the result of the query according to the value of the populated field?
I tried:
House.populateAll().sort("location.street ASC").exec(console.log);
Neither waterline (0.10.22) or sailsjs (v0.11) currently support this.
You would need to process your return variable to reorder the data.
There is a ticket for this at https://github.com/balderdashy/waterline/issues/334

How to have additional fields in SQLFORM that are not in table in web2py?

I have a form for creating new records in a table generated using SQLFORM. One of the fields of the table will not be directly exposed to the user but instead created based on the values of a few other input elements which themselves are not part of the table.
How do I add additional fields to an SQLFORM that are not part of the table and do not need to be part of the database insert? And where would be the place to calculate the non-exposed field before inserting into the database?
(A hypothetical example would be having latitude and longitude coordinate fields in the table but no address field. In this example, would need address field on create form that could be used to geocode and store coordinates in lat/lng fields)
The way I solved this was by using SQLFORM.factory instead of SQLFORM.
1. I extracted the fields defined on my table
fields = [field for field in db.customer]
2. appended the new fields I wanted
fields += [
Field('customer_type','string', label=T('Customer Type'),
requires=IS_IN_SET(customer_types, zero=None, sort=False)),
Field('another_field','string', label=T('Another Field')),
]
3. used SQLFORM.factory to generate the form
form = SQLFORM.factory(
*fields,
formstyle='bootstrap',
_class='customer form-horizontal',
table_name='customer'
)
* note the asterisk before fields is necessary
4. still used form.process().accepted but then calculated what I needed to and then manually handled the database insert
if form.process().accepted:
...
form.vars.some_nonwritable_field = calculate_complicated_value()
db.customer.insert(**db.customer._filter_fields(form.vars))
...
_filter_fields prevents the dynamically added fields from being part of the insert.
This way I could add additional field to the form that were validated but not part of the insert.
In recent versions of web2py you can do it shorter:
form = SQLFORM.factory(
db.table,
Field('my_field_1'),
Field('my_field_2'),
)

Grails data binding hidden form fields

On my update action i'm submitting a form with hidden fields.
I want to avoid the automatic data binding on the hidden fields (delete the values from the domain object). How can i achieve this in grails?
Thanks
You need to use exclude as describes in documentation. Thanks Aram Arabyan.
bindData(target, params, [exclude: ['firstName', 'lastName']], "author")