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?

Thanks!

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

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

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

...

{ TEntity }

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

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

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.