Skip to content

Support for custom range types (Automatic) #9863

@javiertury

Description

@javiertury

I want to add support for custom ranges. The only database that supports ranges is postgresql, so it is the only dialect I modify. The main challenge is that custom ranges oids are not consistent across database instances. I decided to hook postgres ranges on _refreshDynamicOIDs. Although this method works only on postgres versions above 8.3, it's not a problem. Support for ranges was added on 9.3.

My progress so far: https://github.com/javiertury/sequelize

  • Automatically detect all base ranges, array ranges and their basetypes.
    • Hooked ranges into _refreshDynamicOIDs
  • Use postgres global DataTypes.postgres.RANGE.oid_map
  • Use global DataTypes.RANGE.subtypes for RANGE.prototype.toSql
  • Use global DataTypes.RANGE.castTypes for RANGE.prototype.toCastType

Notice that while postgres range class creates a new property for oid_map, it overrides basetype range property subtypes and castTypes. The reason is that subtypes and castTypes are theoretically usable across dialects, other databases could decide to implement ranges.

After this, implementing custom ranges should be as easy as

function addTimerange(DataTypes) {
  DataTypes.RANGE.subtypes.custom = 'customrange';
  DataTypes.RANGE.castTypes.custom = 'custombasetype';
}

Doubts

  • Does overriding basetype range properties subtypes and castTypes have any side effect? I mean, can sequelize theoretically use more than one database dialect at the same time? Then those properties would get overriden and the system would be messed up.
  • The purpose of this code is to workaround different oids across database instances. Can sequelize connect to more than one instance at the same time and override oid_map of another instance?

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: in discussionFor issues and PRs. Community and maintainers are discussing the applicability of the issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions