Skip to content
This repository was archived by the owner on Mar 7, 2024. It is now read-only.

Catch errors when executing query #9

Closed
wants to merge 2 commits into from
Closed
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
27 changes: 13 additions & 14 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,13 @@ export const insertBatchIntoPostgres = async (payload: UploadJobPayload, { globa
const { uuid, eventName, properties, elements, set, set_once, distinct_id, team_id, ip, site_url, timestamp } =
payload.batch[i]


// Creates format: ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11), ($12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22)
valuesString += ' ('
for (let j = 1; j <= 11; ++j) {
valuesString += `$${11 * i + j}${j === 11 ? '' : ', '}`
}
valuesString += `)${i === payload.batch.length - 1 ? '' : ','}`

values = values.concat([
uuid || generateUuid(),
eventName,
Expand Down Expand Up @@ -243,24 +242,24 @@ const executeQuery = async (query: string, values: any[], config: PostgresMeta['
database: config.dbName,
port: parseInt(config.port),
}
const pgClient = new Client({
...basicConnectionOptions,
ssl: {
rejectUnauthorized: config.hasSelfSignedCert === 'No',
},
})

await pgClient.connect()

let error: Error | null = null

let pgClient: Client | null = null
try {
await pgClient.query(query, values)
pgClient = new Client({
...basicConnectionOptions,
ssl: {
rejectUnauthorized: config.hasSelfSignedCert === 'No',
},
})
await pgClient.connect()
//await pgClient.query(query, values)
} catch (err) {
error = err as Error
} finally {
await pgClient?.end()
}

await pgClient.end()

return error
}

Expand Down