"use strict";
/**
 * sql模块
 * @date 2022-03
 * @author 何华东
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.SqlUtils = exports.generateReplaceSql = exports.generateInsertSql = void 0;
/**
 * `sql`工具类
 */
var SqlUtils = /** @class */ (function () {
    function SqlUtils() {
    }
    /**
     * 生成`insert into` sql语句
     */
    SqlUtils.generateInsertSql = function (tableName, entity) {
        var keys = Reflect.ownKeys(entity).filter(function (s) { return entity[s] !== undefined && entity[s] !== null; });
        return "INSERT INTO " + tableName + "(" + keys.join(',') + ") VALUES (" + keys.map(function (s) {
            return typeof entity[s] === 'number' ? entity[s] : "'" + entity[s] + "'";
        }).join(',') + ")";
    };
    /**
     * 生成`replace into` sql语句，固定排除字段`syncTime`
     */
    SqlUtils.generateReplaceSql = function (tableName, entity, excludeFields) {
        var keys = Reflect.ownKeys(entity).filter(function (s) { return entity[s] !== undefined && entity[s] !== null && s !== 'syncTime' && !(excludeFields === null || excludeFields === void 0 ? void 0 : excludeFields.includes(s.toString())); });
        return "REPLACE INTO " + tableName + "(" + keys.join(',') + ") VALUES (" + keys.map(function (s) {
            return typeof entity[s] === 'number' ? entity[s] : "'" + entity[s] + "'";
        }).join(',') + ")";
    };
    return SqlUtils;
}());
exports.SqlUtils = SqlUtils;
exports.default = SqlUtils;
/**
  * 生成`insert into` sql语句
  */
function generateInsertSql(tableName, entity) {
    return SqlUtils.generateInsertSql(tableName, entity);
}
exports.generateInsertSql = generateInsertSql;
/**
 * 生成`replace into` sql语句，固定排除字段`syncTime`
 */
function generateReplaceSql(tableName, entity, excludeFields) {
    return SqlUtils.generateReplaceSql(tableName, entity, excludeFields);
}
exports.generateReplaceSql = generateReplaceSql;
//# sourceMappingURL=SqlUtils.js.map