Serenity: data access layer in another project

Created on 1 Jul 2020  路  5Comments  路  Source: serenity-is/Serenity

I have some time-series data in an influxdB. for presentation, I should merge that data with the serenity SQL database.
I want to exclude the Data Access layer from the Serenity project. how I can do this?

Most helpful comment

Depending on exactly what you want to achieve, you may be able to do this be overriding the repository classes to populate non-mapped fields in your xyzRow entity, I don't know if this is the "official" way:

Create non-mapped field like this:

// In xyzRow.cs
[DisplayName("My External Field"), NotMapped]
public String MyExternalField
{
  get { return Fields.MyExternalField[this]; }
  set { Fields.MyExternalField[this] = value; }
}

// In fields definition section of xyzRow
public class RowFields : RowFieldsBase
{
  // Add this line >>
  public StringField MyExternalField;
}

// Then in xyzRepository.cs
private class MyRetrieveHandler : RetrieveRequestHandler<MyRow> 
{ 
  protected override void OnAfterExecuteQuery()
  {
    base.OnAfterExecuteQuery();

    // Your code to obtain data from external source here

    Row.MyExternalField = externalDataFieldValue; // Replace with whatever is holding your data.              
  }
}

You can also override methods in MyListHandler if you want the data to appear in grids and if you want to be able to update external data you can override methods in MySaveHandler.

Depending on your use case, you could create an xyz entity, for the external data and write custom repository handlers to get the data, you just can't use joins in the serenity db entities to get external data unless it is in a linked database that is queryable.

One final thing is if you want the data to be accessible in master-detail detail grids and editors, you would need to mark the repository handlers of your xyzRepository with the [DefaultHandler] attribute or else duplicate the custom code in your master xyzRepository.

Hope this helps.

All 5 comments

Depending on exactly what you want to achieve, you may be able to do this be overriding the repository classes to populate non-mapped fields in your xyzRow entity, I don't know if this is the "official" way:

Create non-mapped field like this:

// In xyzRow.cs
[DisplayName("My External Field"), NotMapped]
public String MyExternalField
{
  get { return Fields.MyExternalField[this]; }
  set { Fields.MyExternalField[this] = value; }
}

// In fields definition section of xyzRow
public class RowFields : RowFieldsBase
{
  // Add this line >>
  public StringField MyExternalField;
}

// Then in xyzRepository.cs
private class MyRetrieveHandler : RetrieveRequestHandler<MyRow> 
{ 
  protected override void OnAfterExecuteQuery()
  {
    base.OnAfterExecuteQuery();

    // Your code to obtain data from external source here

    Row.MyExternalField = externalDataFieldValue; // Replace with whatever is holding your data.              
  }
}

You can also override methods in MyListHandler if you want the data to appear in grids and if you want to be able to update external data you can override methods in MySaveHandler.

Depending on your use case, you could create an xyz entity, for the external data and write custom repository handlers to get the data, you just can't use joins in the serenity db entities to get external data unless it is in a linked database that is queryable.

One final thing is if you want the data to be accessible in master-detail detail grids and editors, you would need to mark the repository handlers of your xyzRepository with the [DefaultHandler] attribute or else duplicate the custom code in your master xyzRepository.

Hope this helps.

Yes what @sjcdtm sounds right. It all comes down to what you want to do with the data in the "presentation".

You won't be able to do a true database join between the two databases either. As much as I like the InfluxData project, I have found plain SQL to be a lot simpler to use after a number of different projects. I got TimescaleDB running with Serenity last week - it works well and might save headaches in the long run. It's practically like using Postgres and you get all the benefits of a SQL language.

Another option, have you considered getting tags from your SQL database when inserting data to Influx? That means that you can pull directly from Influx without needing to do a workaround "join".

Anyway, just my 5c, hope it is of some help.

https://github.com/volkanceylan/Serenity/issues/5091#issuecomment-652367174
this solution is helpful but I want to "exclude" the Data Access layer from the Serenity project". to be testable and be developed by other persons. and patterns like repository pattern implemented in it.

This isn't something that I have tried, but #5083 may have the information you need to split the project.

Closed due inactivity

Also check the issue guidelines.
If you still need help, you can ask this on stackoverflow with our new tag.
https://stackoverflow.com/tags/serenity-platform

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gfo2007 picture gfo2007  路  3Comments

StefanTheiner picture StefanTheiner  路  3Comments

stixoffire picture stixoffire  路  3Comments

kilroyFR picture kilroyFR  路  3Comments

stepankurdylo picture stepankurdylo  路  3Comments