-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Description
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
- Hooked ranges into
- Use postgres global
DataTypes.postgres.RANGE.oid_map - Use global
DataTypes.RANGE.subtypesforRANGE.prototype.toSql - Use global
DataTypes.RANGE.castTypesforRANGE.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
subtypesandcastTypeshave 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_mapof another instance?