UNPKG

relax-orm

Version:
42 lines 1.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var oracle_bind_type_1 = require("../enum/oracle-bind.type"); var option_service_1 = require("../service/option.service"); function parseCreate(table, newValues, cols, entityInstance) { var entityProps = Object.keys(cols.columsInfo); var binds = {}; var columns = ''; var bindMapping = ''; var outBindMapping = ''; entityProps.forEach(function (prop) { var colOptions = option_service_1.getOptions(entityInstance, prop); var entityValue = newValues[prop]; if (!entityValue && !colOptions.sequence) { return; } var columnInfo = cols.columsInfo[prop]; columns += columnInfo.column + ", "; var _a = bundKey(entityValue, binds, prop, colOptions, columnInfo), inBind = _a[0], outBind = _a[1]; bindMapping += inBind; outBindMapping += outBind; }); columns = columns.slice(0, -2); bindMapping = bindMapping.slice(0, -2); outBindMapping = outBindMapping.slice(0, -2); var query = "INSERT INTO " + table + " ( " + columns + " ) VALUES ( " + bindMapping + " ) RETURNING " + columns + " INTO " + outBindMapping; return [query, binds]; } exports.parseCreate = parseCreate; function bundKey(entityValue, binds, prop, colOptions, colInfo) { var outBindKey = "out$" + prop; var outBind = ":" + outBindKey + ", "; binds[outBindKey] = { dir: oracle_bind_type_1.OracleBind.BIND_OUT, type: oracle_bind_type_1.OrcleDataTypeConst[colInfo.type] }; // If colunm has SEQUENCE as priority if (colOptions.sequence) { return [colOptions.sequence + ".NEXTVAL, ", outBind]; } var bindKey = prop + "$"; binds[bindKey] = entityValue; return [":" + bindKey + ", ", outBind]; } //# sourceMappingURL=create.parser.js.map