Porting from Sequelize to Aurelius / BIZ

Hello, I need to move apps from angular+nodejs+express+sequelize to TMS WebCore & TMS/BIZ technology - and keep the MySQL data correctly working and updated while changing tech under the hood...

All the current db tables contain the fields createdAt and updatedAt, which are directly managed by the Sequelize ORM, as explained here

Any suggestion on how to manage/update these fields in Aurelius?


You can implement that easily in Aurelius using abstract entities and events:

  {$RTTI EXPLICIT METHODS([vcProtected..vcPublic])}
  TEntity = class abstract
  strict private
    [Column('created_at', [TColumnProp.NoUpdate])]
    FCreatedAt: Nullable<TDateTime>;

    [Column('updated_at', [])]
    FUpdatedAt: Nullable<TDateTime>;
    procedure OnInserting;
    procedure OnUpdating(Args: TUpdatingArgs);
    property CreatedAt: Nullable<TDateTime> read FCreatedAt write FCreatedAt;
    property UpdatedAt: Nullable<TDateTime> read FUpdatedAt write FUpdatedAt;


{ TEntity }

procedure TEntity.OnInserting;
  if FCreatedAt.ValueOrDefault = 0 then
    FCreatedAt := TDateTime.NowUTC;
  if FUpdatedAt.ValueOrDefault = 0 then
    FUpdatedAt := FCreatedAt;

procedure TEntity.OnUpdating(Args: TUpdatingArgs);
  FUpdatedAt := TDateTime.NowUTC;
  if (FUpdatedAt < FCreatedAt)  then
    FUpdatedAt := FCreatedAt;
  Args.RecalculateState := True;

Then any entity you inherit from TEntity will have the CreatedAt and UpdatedAt fields updated accordingly.

Thank you very much, Wagner.
I will test it in the next days - after a first look at the code above I'm confident it will be possible to have different co-existing apps, either "old" developed in nodejs/express/sequelize or "new" based on BIZ, both accessing the database... that's great!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.