Hello people who can create queries with XSDS properly!
I started using XSDS (so I'm in Hana SPS 09).. very interesting stuff.
Of course, I read all the few information sources on this topic:
Thomas Jung's - SAP HANA SPS 09: New Developer Features; XSDS (XS Data Services) and
Andreas Roth's - XS Data Services Series:
- XS Data Services: A Native CDS Client and Query Builder for XS JavaScript
- XS Data Services: Working With CDS Entities
- XS Data Services: Building CDS Queries
So I have a table similar to the one below:
@Catalog.tableType: #COLUMN Entity TAB001 { key id_a: ty_id_a; key field_b: Integer64; key field_c: LocalTime; key field_d: LocalTime; field_e: ty_id_e not null; // association with non CDS table field_f: LocalTime; field_g: LocalTime; field_h: Integer64; field_i: global_types.ty_log_criacao; };
Then, I created a query like the one below. It works fine.
function createEntity() { var constructor; constructor = XSDS.$getEntity('my.package::cds.TAB0001'); if (!constructor) { constructor = XSDS.$importEntity( "my.package", "cds.TAB001" ); } return constructor; } The function above is just a getter for the Entity constructor
function getDataUsingCDS(input){ var Agenda = createEntity(); var queryResult = Agenda .$query() .$project({ id_a: "id", field_b: "weekday", field_c: "inicio", field_d: "fim", field_e: "pausa_inicio", field_f: "pausa_fim" }) .$where(Agenda.id_profal.$eq(input.id)) .$execute({$flat: true}); // for (var int = 0; int < queryResult.length; int++) { // queryResult[int].id = agendasDoProfissional[int].id.toString(); // used to avoid id = {} // queryResult[int].dia_da_semana = queryResult[int].weekday.toString(); // used to avoid field_b = {} // } return { profissional: input, agendas: queryResult }; }
The code above is inside a xsjslib and I have a xsjs which calls this function and JSON.stringify its return.
My problem is: some attributes from the query result are actually objects and not simple values. Like the JSON below:
{
"profissional": {
"id": "2"
},
"agendas": [
{
"field_g": {},
"field_e": {},
"field_c": "0000-01-01T04:41:24.000Z",
"field_d": "0000-01-01T04:41:24.000Z",
"weekday": {},
"id": {}
},
{
"field_g": {},
"field_e": {},
"field_c": "0000-01-01T04:41:24.000Z",
"field_d": "0000-01-01T04:41:24.000Z",
"weekday": {},
"id": {}
},
For some unknown reasons, LocalTime fields don't have this problem. Inspecting these objects in the debugger it's possible to see they have methods like "toString()" which actually return DB column value but.. Do I have to do a conversion like the for statement above (commented)?
From my understanding $query() retrieves data and store on unmanaged (non persistent) objects.. reading all links above I would believe such objects would be simple key value pairs but it doesn't seems to be the case. Also, $select and $findAll methods have the very same problem.
Thanks!