Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offer JSON access via database #410

Open
JornWildt opened this issue Mar 18, 2021 · 2 comments
Open

Offer JSON access via database #410

JornWildt opened this issue Mar 18, 2021 · 2 comments
Milestone

Comments

@JornWildt
Copy link

JornWildt commented Mar 18, 2021

Assume a custom entity booking like this:

public class BookingDataModel : ICustomEntityDataModel
{
  public DateTime ArrivalDate { get; set; }
}

The above serialized data can be ordered by the arrival data using the following SQL query (which lacks multi-version handling, but otherwise works for me and my tests - even on SQL Server Express):

select *
from Cofoundry.CustomEntity e
join Cofoundry.CustomEntityVersion v
  on v.CustomEntityId = e.CustomEntityId
where e.CustomEntityDefinitionCode = 'BOOKNG'
ORDER BY JSON_VALUE(v.SerializedData, '$.arrivalDate') desc

The same idea can of course be applied for WHERE filters, not just ORDER BY expressions. See for instance https://docs.microsoft.com/en-us/sql/relational-databases/json/json-data-sql-server?view=sql-server-ver15

I think it should be fairly straight forward to convert C# interface stuff to SQL expressions like above.

Today I can create a paged query like this:

public class SearchBookingSummariesQuery
    : SimplePageableQuery
    , IQuery<PagedQueryResult<BookingSummary>>
{
}

Maybe, if I also implemented something like ISortableQuery, I could get my return data sorted by a list of the model data fields:

interface ISortableQueryField<TDataModel, TField>
{
  Expression<Func<TDataModel, TField>> Reference { get; }
}

By inspection of the expression it would be possible to do what ASP.NET does with HTML helpers and calculate the referenced field and then create the needed JSON_VALUE SQL expression.

Other ways to express the request is of course also possible.

@JornWildt
Copy link
Author

Performance may not be fantastic for large data sets, but it seems like a better solution than to read everything into memory and then sort it.

@HeyJoel HeyJoel added this to the 0.11 milestone Mar 18, 2021
@HeyJoel
Copy link
Member

HeyJoel commented Mar 18, 2021

I'm interested in this. JSON querying has been mentioned before, but I can't seem to track down where (possibly lost in gitter). As you say, the performance might not be brilliant, but custom entities will always be a trade off between speed and convenience, and you can always build a custom index or progress to a bespoke domain model if necessary - I'm keen to make that easier too.

It's related to #12 and possible #31 so that needs to be considered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants