[OT] Idea to get all columns from multiple tables in DB

Steven Schveighoffer schveiguy at gmail.com
Fri Jan 10 21:04:35 UTC 2020


On 1/10/20 3:32 PM, Jacob Carlborg wrote:
> On 2020-01-09 00:03, Steven Schveighoffer wrote:
> 
>> Yeah, this is generally the case when generating SQL from types. I 
>> like to write queries to make them the most efficient I can, without 
>> having to deal with quirks between ORM requirements and the data in 
>> the table (I'm dealing with an existing data layout, which does not 
>> lend itself always to ORM usage).
> 
> Sure, but you don't need an ORM to do what I suggested. Something like 
> this:
> 
> connection.query("SELECT " ~ fieldsToSQL!User ~ " FROM user").byItem!User;
> 
> Where "fieldsToSQL!User" would expand to:
> 
> "user.first_name, user.last_name, user.age"
> 
> Or whatever naming convention you have in the table.
> 
> I'm sure you can come up with a better API.
> 

That's not the issue. The issue is they will come back as "first_name", 
"last_name", etc. If you have multiple tables with common column names, 
then you have an ambiguity, and cannot determine where each column goes.

-Steve


More information about the Digitalmars-d mailing list