UNPKG

@lorefnon/ts-pg-migrate

Version:

Type-safe Postgresql database migration management tool for node.js

31 lines (30 loc) 1.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.dropCast = dropCast; exports.createCast = createCast; function dropCast(_mOptions) { const _drop = (_fromType, _toType, options = {}) => { const ifExists = options.ifExists ? ' IF EXISTS' : ''; return `DROP CAST${ifExists} (${_fromType} AS ${_toType});`; }; return _drop; } function createCast(mOptions) { const _create = (_fromType, _toType, options = {}) => { let conversion = ''; if (options.functionName) { const args = options.argumentTypes || [_fromType]; conversion = ` WITH FUNCTION ${options.functionName}(${args.join(', ')})`; } else if (options.inout) { conversion = ' WITH INOUT'; } else { conversion = ' WITHOUT FUNCTION'; } const implicit = options.as ? ` AS ${options.as}` : ''; return `CREATE CAST (${_fromType} AS ${_toType})${conversion}${implicit};`; }; _create.reverse = dropCast(mOptions); return _create; }