UNPKG

relax-orm

Version:
40 lines 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var table_1 = require("../decorator/table"); var oracle_bind_type_1 = require("../enum/oracle-bind.type"); var attribute_service_1 = require("../service/attribute.service"); var primary_key_service_1 = require("../service/primary-key.service"); // import { MapperObject } from '../interface/where.interface'; function parseSave(newValue, oldValue) { var entityRef = newValue.constructor.prototype.constructor; var table = table_1.getTableName(entityRef); var attrInfo = attribute_service_1.getAttributes(newValue); var binds = {}; var sets = ''; var columns = ''; var outBindMapping = ''; Object.keys(attrInfo.columsInfo).forEach(function (key) { outBindMapping += ":out$" + key + ", "; var dataType = oracle_bind_type_1.OrcleDataTypeConst[attrInfo.columsInfo[key].type]; binds["out$" + key] = { dir: oracle_bind_type_1.OracleBind.BIND_OUT, type: dataType }; var val = newValue[key]; if (!val) return; var bindKey = key + "$"; var targetCol = attrInfo.columsInfo[key].column; binds[bindKey] = val; sets += targetCol + " = :" + bindKey + ", "; columns += targetCol + ", "; }); sets = sets.slice(0, -2); columns = columns.slice(0, -2); outBindMapping = outBindMapping.slice(0, -2); var primaryKey = primary_key_service_1.getPrimaryKey(newValue); var primaryColumn = attrInfo.columsInfo[primaryKey].column; binds["key$" + primaryKey] = oldValue[primaryKey]; var query = "UPDATE " + table + " SET " + sets + " WHERE " + primaryColumn + " = :key$" + primaryKey; query += " RETURNING " + columns + " INTO " + outBindMapping; return [query, binds]; } exports.parseSave = parseSave; //# sourceMappingURL=save.parser.js.map