Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
debug('pgmongo:rows')(rows)
const data = { values: rows, ok: 1 }
socket.write(build(reqId, data, {}))
return true
}
if (commandName === 'find') {
const filter = doc.filter
const where = safeWhereConversion(filter, rawCollectionName)
let select = mongoToPostgres.convertSelect('data', doc.projection)
let query = `SELECT ${select} FROM ${collectionName}`
if (where !== 'TRUE') {
query += ` WHERE ${where}`
}
if (doc.sort) {
query += ' ORDER BY ' + mongoToPostgres.convertSort('data', doc.sort, doc.collation && doc.collation.numericOrdering)
}
if (doc.limit) {
query += ' LIMIT ' + Math.abs(doc.limit)
}
if (doc.skip) {
if (doc.skip < 0) {
socket.write(build(reqId, { ok: 0, errmsg: 'negative skip not allowed' }, {}))
return true
}
query += ' OFFSET ' + doc.skip
}
let res
try {
res = await tryOrCreateTable(async () => await doQuery(databaseName, query), databaseName, collectionName)
} catch (e) {
console.error(e)