Skip to content

Commit

Permalink
fix: decimal type for neon driver (#1663)
Browse files Browse the repository at this point in the history
  • Loading branch information
davenewza authored Nov 3, 2024
1 parent b7bae88 commit 3b5b924
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions packages/functions-runtime/src/database.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { Kysely, PostgresDialect, CamelCasePlugin } = require("kysely");
const neonserverless = require("@neondatabase/serverless");
const types = require("@neondatabase/serverless");
const { AsyncLocalStorage } = require("async_hooks");
const { AuditContextPlugin } = require("./auditing");
const pg = require("pg");
Expand Down Expand Up @@ -140,15 +141,15 @@ class InstrumentedClient extends pg.Client {
}

function getDialect() {
// Adding a custom type parser for numeric fields: see https://kysely.dev/docs/recipes/data-types#configuring-runtime-javascript-types
// 1700 = type for NUMERIC
pg.types.setTypeParser(1700, function (val) {
return parseFloat(val);
});

const dbConnType = process.env["KEEL_DB_CONN_TYPE"];
switch (dbConnType) {
case "pg":
// Adding a custom type parser for numeric fields: see https://kysely.dev/docs/recipes/data-types#configuring-runtime-javascript-types
// 1700 = type for NUMERIC
pg.types.setTypeParser(1700, function (val) {
return parseFloat(val);
});

return new PostgresDialect({
pool: new InstrumentedPool({
Client: InstrumentedClient,
Expand All @@ -169,6 +170,12 @@ function getDialect() {
}),
});
case "neon":
// Adding a custom type parser for numeric fields: see https://kysely.dev/docs/recipes/data-types#configuring-runtime-javascript-types
// 1700 = type for NUMERIC
types.setTypeParser(1700, function (val) {
return parseFloat(val);
});

neonserverless.neonConfig.webSocketConstructor = ws;

const pool = new InstrumentedNeonServerlessPool({
Expand Down

0 comments on commit 3b5b924

Please sign in to comment.