You are not logged in.
Pages: 1
Hello ab,
is it somehow possible to read names for columns and tables out of a config file?
I want to move code to mormot, but current code reads sql table and column names out of a config file and prepare the query based on this input.
DbBirthdayRecord = class(TOrmNoCase)
private
DbCountry: RawUTF8;
DbBirthdayDate: TDateTime;
DBirthdayDateExtraInfo: RawUTF8;
DbData: DbDataRecord;
published
property DbCountry: RawUTF8 read FDbCountry write FDbCountry;
property IMDbReleaseDate: TDateTime read FDbBirthdayDate write FDbBirthdayDate;
property DBirthdayDateExtraInfo: RawUTF8 read FDBirthdayDateExtraInfo write FDBirthdayDateExtraInfo;
property DbData: TDbDataRecordRecord read FDbDataRecord write FDbDataRecord;
end;
So, DbBirthday will be read from somewhere and maybe changed to DbBirthdayCelebration.
Thank you for giving me a hint.
Best regards
Moe
Offline
Yes, mORMot2 supports reading table/column names from config files using OrmMapExternal + MapField.
Key Mechanism
1. Define ORM class with internal property names (compile-time):
TDbBirthdayRecord = class(TOrmNoCase)
published
property DbCountry: RawUtf8 ...;
property DbBirthdayDate: TDateTime ...;
end;
2. Load mapping from config (runtime):
{
"tableName": "BirthdayCelebration",
"columns": {
"DbCountry": "country_code",
"DbBirthdayDate": "celebration_date"
}
}
3. Apply mapping:
// Map table name
Mapping := OrmMapExternal(Model, TDbBirthdayRecord, ExternalDB, TableName);
// Map column names
Mapping^.MapField('DbCountry', 'country_code');
Mapping^.MapField('DbBirthdayDate', 'celebration_date');
Complete demo: https://gist.github.com/zen010101/713cf … 44f277c1ee
Offline
zen010101 and his AI tools knows mORMot better than I do.
I am so happy I did write so many AI-friendly comments, even before AI was a real thing, just because I am lazy and want to keep my memory clean.![]()
Offline
Hah, that's only because your AI-friendly comments are so well-written that even the AI can "get" mORMot quickly -- it's like you left a super clear treasure map, and my AI tools just followed the lines faster than I could read them myself. ![]()
Offline
great stuff!
I didn't expect this ![]()
Thank you for this hint!
Offline
I created a working demo for this: https://github.com/zen010101/Claude_Mor … pping-demo
It loads table/column mappings from mapping_config.json and applies them via OrmMapExternal + MapField at runtime - no recompilation needed.
Offline
great! thanks alot!
From my perspective i use claude, too and need to use it more for this stuff.
Mormot2 is really good documented, but you really need to be an expert to understand all those stuff.
i'm not a professional coder, but understand some things about coding.
It would be really great to have some more examples like this!
What is best practice to connect with mysql/sqlite?
How to use the orm with this?
Example for sql queries written in orm.
This would be really great!
I also look for what i can deliver ![]()
Offline
Pages: 1