-1

Is there any build in function for converting a struct of structs to cold-fusion query, i googled and all i can found is arrayofstructs, but i am working with an api which is returning me structs of structs and i can't figure out a way to deal with i am trying to use structkeylist, but looks like structkeylist does not like nested keys structure and it breaks in there

Any udf or inbuild functionality in lucee i can use to fix it

Appreciated

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
  • Please include an example of the structure you are dealing with. StructKeyList should work but you need to reference things correctly. An example of the data will help us to help you. – Miguel-F Aug 13 '20 at 20:26
  • i have like this https://prnt.sc/tz6yk4, i am not sure, if i add another column for 1,10 as like tableID which will bring that value too when converting – user13895102 Aug 13 '20 at 20:32
  • See this article about referencing structures - [About structures](https://helpx.adobe.com/coldfusion/developing-applications/the-cfml-programming-language/using-arrays-and-structures/about-structures.html) – Miguel-F Aug 13 '20 at 20:41
  • You should have a screenshot of what the incoming data looks like and what the results should look like. – James A Mohler Aug 13 '20 at 22:54

1 Answers1

0

Here is an example of how to access the values from a structure that contains structures. First part is just building a structure similar to yours.

<cfscript>
    struct = {};
    struct1 = {};
    struct10 = {};

    struct1.id = '1';
    struct1.name = 'test';
    struct1.uid = '1234567890';

    struct.1 = struct1;

    struct10.id = '2';
    struct10.name = 'test2';
    struct10.uid = '0987654321';

    struct.10 = struct10;
    
    writeDump(struct);
    writeOutput('<hr>');
    
    for (key in struct) {
        writeOutput('Struct #key# id = ' & struct[key].id & '<br>');
        writeOutput('Struct #key# name = ' & struct[key].name & '<br>');
        writeOutput('Struct #key# uid = ' & struct[key].uid & '<br>');
        writeOutput('<hr>');
    }

    // another way to access the structure values
    writeOutput('Struct 1 id = ' & struct.1.id & '<br>');
    writeOutput('Struct 1 name = ' & struct.1.name & '<br>');
    writeOutput('Struct 1 uid = ' & struct.1.uid & '<br>');
</cfscript>

I tried to save this as a gist for you on TryCF.com but it won't save for me. You can copy and paste that code in there and run it. Then play around with it.

The output looks like this:

enter image description here

Hopefully that's enough to get you started.

Miguel-F
  • 13,450
  • 6
  • 38
  • 63
  • Thanks for generating it as a structure, but i am trying to convert that to query, and hardcoding 1 and 10 will work in this case, i am thinking of using structcount and see if i can create a query for it, – user13895102 Aug 14 '20 at 12:39
  • My point is I don't think you need it as a query. You can loop over structures as well. _See the `for` loop in my example._ Why do you think you need a query? – Miguel-F Aug 14 '20 at 12:47
  • because i had to filter it down more to write additional logic to it, which will eventually help in writing that additional logic, like a qoq – user13895102 Aug 14 '20 at 13:51
  • Where is your data coming from (the structure data)? Can you change that to return a query object? AFAIK there is no built-in function to convert a structure to a query. So you would have to do it manually. And I would not recommend that. – Miguel-F Aug 14 '20 at 14:27
  • its a part of api, where i am getting the data, i already specified in my question – user13895102 Aug 14 '20 at 15:23