snowflake with sorting and paging
araneta opened this issue · comments
Is it possible to create a snowflake with sorting and paging? please give me some examples
Thanks
You can define default snowflake sort order using order by, e.g: https://github.com/ngs-doo/revenj/blob/master/java/test/src/test/resources/model.dsl#L54
But I'm not sure what you mean by paging. Repositories have limit/offset params for paging: https://github.com/ngs-doo/revenj/blob/master/java/revenj-core/src/main/java/org/revenj/patterns/SearchableRepository.java#L13 or https://github.com/ngs-doo/revenj/blob/master/java/revenj-core/src/main/java/org/revenj/patterns/DataContext.java#L26
i want the order by is using parameter is it possible?
Query API can be used for custom sorting. https://github.com/ngs-doo/revenj/blob/master/java/test/src/test/java/org/revenj/TestQuery.java#L388
Cube also has it's own (simpler) sorting
i want to put sorting and paging inside specification filterSearch, because search usually have sort and paging. is it possible?
Thanks
snowflake CourseOfferedList from CourseOffered{
ID;
University.ID as UniversityID;
Program.ID as ProgramID;
code;
name;
credit;
CourseType.ID as CourseTypeID;
CourseType.name as CourseType;
specification filterSearch 'it =>
it.UniversityID == univId &&
it.ProgramID == programId && (
filter == null ||
filter == "" ||
it.code.ToLower().Contains(filter.ToLower()) ||
it.name.ToLower().Contains(filter.ToLower()))' {
int univId;
int programId;
String? filter;
}
}
Specification is just a predicate. If you wish to have filter + sort + paging you will have to provide additional parameters alongside specification.
If you want such definition inside DSL then you can write report, eg: https://github.com/ngs-doo/revenj/blob/master/java/test/src/test/resources/model.dsl#L121
You can use params for limit/offset
ok i will try it. Thanks
snowflake CourseOfferedList from CourseOffered{
ID;
University.ID as UniversityID;
Program.ID as ProgramID;
code;
name;
credit;
CourseType.ID as CourseTypeID;
CourseType.name as CourseType;
specification findByUniversity 'it => it.UniversityID == univId'
{
int univId;
}
specification findByProgram 'it => it.UniversityID == univId && it.ProgramID == programId'
{
int univId;
int programId;
}
specification findByCourseType 'it => it.UniversityID == univId && it.CourseTypeID == courseTypeId'
{
int univId;
int courseTypeId;
}
specification filterSearch 'it =>
it.UniversityID == univId &&
it.ProgramID == programId && (
filter == null ||
filter == "" ||
it.code.ToLower().Contains(filter.ToLower()) ||
it.name.ToLower().Contains(filter.ToLower()))' {
int univId;
int programId;
String? filter;
}
order by code asc;
}
why this order by code asc; does not work?
it generates this view
CREATE OR REPLACE VIEW university."CourseOfferedList" AS
SELECT _entity."ID"::text AS "URI",
_entity."ID",
"_entity_University"."ID" AS "UniversityID",
"_entity_Program"."ID" AS "ProgramID",
_entity.code,
_entity.name,
_entity.credit,
"_entity_CourseType"."ID" AS "CourseTypeID",
"_entity_CourseType".name AS "CourseType"
FROM university."CourseOffered_entity" _entity
JOIN university."University_entity" "_entity_University" ON "_entity_University"."ID" = _entity."UniversityID"
JOIN university."Program_entity" "_entity_Program" ON "_entity_Program"."ID" = _entity."ProgramID"
JOIN university."CourseType_entity" "_entity_CourseType" ON "_entity_CourseType"."ID" = _entity."CourseTypeID";
ALTER TABLE university."CourseOfferedList"
OWNER TO postgres;
COMMENT ON VIEW university."CourseOfferedList"
IS 'NGS volatile';
It works, but it's not in the view.
so i have to use report instead of snowflake to use sorting and paging?
no? you can use query api to get that also. see link above to query test
ok i will use query