ORM in Freshdesk Serverless

I’m trying to use prisma ORM for manage a relational database (postgres) in freshdesk serverless, but it didn’t work.

Is there any possible ORM to use in serverless fdk or should I not use ORM in fdk?

Prisma should work quite nicely.

The issue is not as much with ORMs as much as connecting to external relational databases in a serverless function. You will have to create a connection pool outside event handler functions to make sure they can be shared with other calls. Else, every invocation of a serverless function will attempt to create a connection to the database.

2 Likes

Hi @kaustavdm, thanks for reply!

sorry about the topic, but I’m newbie with prisma.

I was following the prima quick start and made the following code in server.js, just to debug the error.

const { PrismaClient } = require("@prisma/client");

exports = {
  onTicketCreateHandler: async function (args) {
    try {
      const prisma = new PrismaClient();
      console.log(prisma);
    } catch (err) {
      console.log(err);
    }
  },
};

This is the schema.prisma file:

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = "postgresql://postgres:postgres@localhost:5432/prisma_test"
}

// models

The error I had was:
Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.

I had already run this command and didn’t work.
If I put the new PrismaClient() outside the function, the fdk output is just undefined.

I have no idea how to fix it.

1 Like

I haven’t tried Prisma myself. Let me try writing an example to reproduce this.

1 Like

Hi @kaustavdm, thanks :grinning_face_with_smiling_eyes:!

@Matozinho I spoke too soon. This may be way more complicated than I thought.

The issue seems to be around running prisma command-line tools. Prisma currently has no support to programmatically run migrate or generate commands.

There are no build steps that you can perform as part of app install events that need calling another command because child_process is not allowed in the app sandbox environment.

This means, you will have to introduce a middleware for now at least. Have an HTTP API that uses Prisma to make DB calls, and is hosted externally. Then, communicate with that HTTP API from the Freshdesk app.

2 Likes

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.