Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove FLUSH from CF integration #736

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import crypto from 'crypto'
import Stream from 'stream'
import { performance } from 'perf_hooks'

import { stringify, handleValue, arrayParser, arraySerializer } from './types.js'
import { stringify, handleValue, arrayParser, arraySerializer, typesMapped } from './types.js'
import { Errors } from './errors.js'
import Result from './result.js'
import Queue from './queue.js'
Expand Down Expand Up @@ -183,13 +183,13 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose

return q.options.simple
? b().Q().str(q.statement.string + b.N).end()
: q.describeFirst
: q.describeFirst
? Buffer.concat([describe(q), Flush])
: q.prepare
? q.prepared
? prepared(q)
: Buffer.concat([describe(q), prepared(q)])
: unnamed(q)
: q.prepare
? q.prepared
? prepared(q)
: Buffer.concat([describe(q), prepared(q)])
: unnamed(q);
}

function describe(q) {
Expand Down Expand Up @@ -230,7 +230,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
q.onlyDescribe && (delete statements[q.signature])
q.parameters = q.parameters || parameters
q.prepared = q.prepare && q.signature in statements
q.describeFirst = q.onlyDescribe || (parameters.length && !q.prepared)
q.describeFirst = q.onlyDescribe || (!typesMapped(q.args, types) && !q.prepared);
q.statement = q.prepared
? statements[q.signature]
: { string, types, name: q.prepare ? statementId + statementCount++ : '' }
Expand Down Expand Up @@ -602,8 +602,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
!query.statement.types[i] && (query.statement.types[i] = x.readUInt32BE(7 + i * 4))

query.prepare && (statements[query.signature] = query.statement)
query.describeFirst && !query.onlyDescribe && (write(prepared(query)), query.describeFirst = false)
}
query.describeFirst && !query.onlyDescribe && write(prepared(query)), (query.describeFirst = false) }

function RowDescription(x) {
if (result.command) {
Expand Down Expand Up @@ -951,7 +950,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
function Execute(portal = '', rows = 0) {
return Buffer.concat([
b().E().str(portal + b.N).i32(rows).end(),
Flush
rows != 0 ? Flush : Sync
])
}

Expand Down
11 changes: 11 additions & 0 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ export function handleValue(x, parameters, types, options) {
))
}

export function typesMapped(args, types) {
if (types.length < args.length) return false;
for(let i = 0; i < args.length; i++) {
let val = args[i] instanceof Parameter ? args[i].value : args[i]
if (types[i] === 0 && typeof val !== 'number') {
return false;
}
}
return true;
}

const defaultHandlers = typeHandlers(types)

export function stringify(q, string, value, parameters, types, options) { // eslint-disable-line
Expand Down
2 changes: 1 addition & 1 deletion tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,7 @@ t('Error contains query string', async() => [
])

t('Error contains query serialized parameters', async() => [
1,
'1',
(await sql`selec ${ 1 }`.catch(err => err.parameters[0]))
])

Expand Down
Loading