UNPKG

@lantsang/nestjs-tdengine

Version:

NestJS TDengine 驱动

45 lines (44 loc) 1.75 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.IricUtil = void 0; const common_1 = require("@nestjs/common"); let IricUtil = class IricUtil { /** * 将错误信息转换为可存储字符串 * @param error 错误信息 */ parseError(error) { return typeof error === 'string' || error instanceof String ? `${error}` : JSON.stringify(error) === '{}' ? error.toString() : JSON.stringify(error); } /** * 将JS值转换为SQL值 * @param value JS 值类型 * @returns SQL值类型 */ convertJSValue(value) { if (value === null || value === undefined) return 'null'; return typeof value === 'string' ? `'${this.sqlValueFormat(value)}'` : value; } /** * SQl值转义 * @param value 原始字符串 * @returns 转以后的字符串 */ sqlValueFormat(value) { return value .split('') .map((i, index, array) => (i === "'" && array[index - 1] !== '\\' ? "\\'" : i)) .join(''); } }; IricUtil = __decorate([ common_1.Injectable() ], IricUtil); exports.IricUtil = IricUtil;