www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Converting a list of words or array of values to variables at compile

reply Louie F <forondalouie gmail.com> writes:
I found out that compile time optimization is quite useful 
specially for database queries, instead of it being generated at 
every call, it can be generated like I typed it using compile 
time optimizations... so I thought,

Is it possible to convert an array of values or a list from a 
file to variables or struct at compile time?

So basically I have a database, instead of writing a struct, I 
would like to query the database for the list of tables and their 
column information then parse that as a struct or variables for 
parsing so that I could use it, so that if I delete or add 
columns I then only need to recompile the code and not worry 
about editing files...

class Users
{
       /*
             query the database and create fields at compile time 
and use the variables below
       */

       void create(){
             this.name = "Louie";
        }

}

or  something like this...

foreach(table_names, key; table){
         /*
               generate struct using table and informations
        */
}
Nov 25 2015
parent drug <drug2004 bk.ru> writes:
On 26.11.2015 09:33, Louie F wrote:
 I found out that compile time optimization is quite useful specially for
 database queries, instead of it being generated at every call, it can be
 generated like I typed it using compile time optimizations... so I thought,

 Is it possible to convert an array of values or a list from a file to
 variables or struct at compile time?

 So basically I have a database, instead of writing a struct, I would
 like to query the database for the list of tables and their column
 information then parse that as a struct or variables for parsing so that
 I could use it, so that if I delete or add columns I then only need to
 recompile the code and not worry about editing files...

 class Users
 {
        /*
              query the database and create fields at compile time and
 use the variables below
        */

        void create(){
              this.name = "Louie";
         }

 }

 or  something like this...

 foreach(table_names, key; table){
          /*
                generate struct using table and informations
         */
 }
you can do something like: auto createColumnDescription(Description...)() { string s; foreach(description; Description){ s ~= description[0] ~ " " ~ description[1] ~ ";\n"); return s; } struct Table(ColumnDescription) { // pragma(msg, createColumn!ColumnDescription); // uncomment this to see what will be mixed mixin(createColumn!ColumnDescription); } the table contains a range of tuples of column type and name and should be available at compile-time But it isn't tested and I'm not sure it's the best way.
Nov 25 2015