UNPKG

stream-chat-react-native-core

Version:

The official React Native and Expo components for Stream Chat, a service for building chat applications

22 lines 1.02 kB
Object.defineProperty(exports, "__esModule", { value: true }); exports.createUpsertQuery = void 0; var _schema = require("../schema"); var createUpsertQuery = (table, row, conflictCheckKeys) => { var filteredRow = {}; for (var key in row) { if (row[key] !== undefined) { filteredRow[key] = row[key]; } } var fields = Object.keys(filteredRow); var questionMarks = Array(Object.keys(fields).length).fill('?').join(','); var conflictKeys = conflictCheckKeys || _schema.tables[table].primaryKey || []; var conflictMatchersWithoutPK = fields.filter(f => !conflictKeys.includes(f)).map(f => `${f}=excluded.${f}`); var conflictConstraint = conflictKeys.length > 0 ? `ON CONFLICT(${conflictKeys.join(',')}) DO UPDATE SET ${conflictMatchersWithoutPK.join(',')}` : ''; return [`INSERT INTO ${table} (${fields.join(',')}) VALUES (${questionMarks}) ${conflictConstraint}`, Object.values(filteredRow)]; }; exports.createUpsertQuery = createUpsertQuery; //# sourceMappingURL=createUpsertQuery.js.map