Search code examples
postgresqlloopbackjsloopback

Create model loopback with type tsrange


I am looking for a way to create a model in which there is a property with type tsrange in loopback 4 or is there a type that can replace tsrange ?


Solution

  • You can use the loopback datatype date and execute plain SQL.

    Example to check overlap between 2 ranges:

    SELECT  tsrange('2020-01-06 13:00', '2020-01-26 11:00', '[)')
        &&
            tsrange('2020-01-04 13:00', '2020-01-6 11:00', '[)')
    

    tsrange() is used to construct the range, using [ and ) to set the boundaries. && is the operator that checks for an overlap between the 2 ranges.