How to do Projection in "GraphQL.Net"? - asp.net-core

I have problem with using GraphQL.Net, and that is what I need.
I specify four fields in aType Class, when I try to fetch only two fields with a query on GraphQL, the executing query on database contains all four fields that defined in Type class but I expect query to be something look like this :
Select field1,field2 from someEntity
How to do this projection ?!
I'm using GraphQL.Net version 7.2.2

Related

Using SilverStripe's SQLQuery object without selecting * fields

Looking at the documentation, there are fairly good instructions on how to build up a SQL query.
My code looks like this:
$sqlQuery = new SQLQuery();
$sqlQuery->setFrom('PropertyPage')->selectField('PropertyType')->setDistinct(true);
I'm aiming to get the following SQL:
SELECT DISTINCT PropertyType FROM PropertyPage
but instead I'm getting back this:
SELECT DISTINCT *, PropertyType FROM PropertyPage
Even their own example seems to give back a 'SELECT DISTINCT *. How can I avoid this?
Why do you use SQLQuery directly?
With pure ORM it should go like this:
$result = PropertyPage::get()->setQueriedColumns(array('PropertyType'))->distinct();
which returns a DataList you can loop over.
See setQueriedColumns() and distinct()
What version of SS framework are you using? Distinct was added in 3.1.7 iirc.
Just to add to #wmk's answer as well as directly address how to do it with SQLQuery, your call to selectField is the reason why that query happened. The documentation to selectField shows that it adds an additional field to select, not restrict the list to just that field.
The reason why their examples (A and B) also had the issue is that the first parameter for the constructor for SQLQuery is a default value of "*" for select statement.
To still use your code as a base, replace your use of selectField with setSelect. Your query will then look like this:
SELECT DISTINCT PropertyType FROM PropertyPage
It isn't bad to directly query the database using SQLQuery especially if you really just want the raw data of a particular column or the result itself cannot be expressed against a DataObject (eg. using column aliases). You would also have a small performance improvement that PHP would not have to instantiate a DataObject.
While saying that, it can be far more useful having a DataObject and the various functions that it exposes per record.

How to select similar data using SQL in JCR/jackrabbit?

how do we write query in JCR/Jackrabbit to select data using:
"where title like '%News%".
here is my structure in repository
/rootNode and under root node I have many child nodes and under those child nodes i have data in which I want to search if a string matches the name or is similar to that name.
please pardon me if i am not able to explain. I m new to JCR/jackrabbit.
I know how to do in database example
(SELECT * FROM Customers
WHERE City LIKE 'anystring%';)
i want to accomplish similar thing in JCR.
Thanks
If you are planning to use XPATH query syntax, then the jcr:like function can be used to achieve your requirements.
/jcr:root//*[jcr:like(#jcr:title, '%News%')]
For SQL grammar, the LIKE operator can be used for the same.
select * from nt:base where jcr:title like '%News%'
For SQL2, the LIKE operator can be used again.
SELECT * FROM [nt:base] AS s WHERE s.[jcr:title] LIKE '%News%'
All the above queries are for reference only, they would run on the entire repository. But when using them for achieving the desired functionality, kindly restrict them to query within the required subtree and not the entire repo.

Spring JDBCDaoSupport - dealing with multiple selects

Does Spring have any features which allow for a batch select? I basically have n number of selects to execute depending on the number of records in a list. At the moment because the size of the list is always changing i have to dynamically build the SQL which will be executed. The end product looks something like this
select * from record_details t WHERE id IN ((?),(?),(?))
However the code to generate this SQL on the fly is messy and I'm wondering if there is a nicer approach for this type of problem?
The NamedParameterJdbcTemplate (and according support class) does have that support.
public void someRepoMethod(List ids) {
String query = "select * from record_details where id in (:ids)";
getNamedParameterJdbcTemplate().query(query, Collections.singletonMap("ids", ids), new YourRowMapper());
}
If you don't want to generate SQL yourself you have to use some existing framework. From what i know myBatis, is more lightweight than hibernate so it can suit you more, but there may be other more suitable.

How to read a class parameter using Caché SQL?

How do I read a class parameter using Caché SQL?
select * from table does not list any class parameters.
Parameters are specific to the class definition, not specific to the object or row. Therefore, you cannot find them by querying the class table. Rather, you need to query the Class Definition tables. These reside in the %Dictionary classes.
For this particular query, you can use
SELECT * FROM %Dictionary.ParameterDefinition WHERE parent='Sample.Person'
In the SAMPLES namespace, this should yield results for all Parameters that are a part of Sample.Person - in this case, only EXTENTQUERYSPEC.

Yii CSqlDataProvider confusion

I am having some trouble understanding CSqlDataProvider and how it works.
When I am using CActiveDataProvider, the results can be accessed as follows:
$data->userProfile['first_name'];
However, when I use CSqlDataProvider, I understand that the results are returned as an array not an object. However, the structure of the array is flat. In other words, I am seeing the following array:
$data['first_name']
instead of
$data['userProfile']['first_name']
But the problem here is what if I have another joined table (let's call it 'author') in my sql code that also contains a first_name field? With CActiveDataProvider, the two fields are disambiguated, so I can do the following to access the two fields:
$data->userProfile['first_name'];
$data->author['first_name'];
But with CSqlDataProvider, there doesn't seem to be anyway I can access the data as follows:
$data['userProfile']['first_name'];
$data['author']['first_name'];
So, outside of assigning a unique name to those fields directly inside my SQL, by doing something like this:
select author.first_name as author_first_name, userProfile.first_name as user_first_name
And then referring to them like this:
$data['author_first_name'];
$data['user_first_name']
is there anyway to get CSqlDataProvider to automatically structure the arrays so they are nested in the same way that CActiveDataProvider objects are? So that I can call them by using $data['userProfile']['first_name']
Or is there another class I should be using to obtain these kinds of nested arrays?
Many thanks!
As far as I can tell, no Yii DB methods break out JOIN query results in to 2D arrays like you are looking for. I think you will need to - as you suggest - alias the column names in your select statement.
MySql returns a single row of data when you JOIN tables in a query, and CSqlDataProvider returns exactly what MySql does: single tabular array representation indexed/keyed by the column names, just like your query returns.
If you want to break apart your results into a multi-dimensional array I would either alias the columns, or use a regular CActiveDataProvider (which you can still pass complex queries and joins in via CDbCritiera).