Error occurred when calling the create() method with Prisma

Despite encountering an environment variable not found error, I have a similar code example where the database connection works fine. Here is the function and model:

model sdk_error {
  view_id   String   @id
  message   String
  timestamp DateTime
}


const errorIngestionHandler = async (req: Request, res: Response) => {
  const time = new Date('November 8, 2022, 12:00:00');
  const errorModel = await prisma.sdk_error.create({
    data: {
      view_id: '1234',
      message: 'this is a test',
      timestamp: time,
    },
  });

  const ret = await prisma.sdk_error.findUnique({
    where: {
      view_id: errorModel.view_id,
    },
  });

  res.send(ret);
};

I am attempting to test my request handler by creating a test input for comparison. The issue arises with the create function resulting in the following error:
Invalid prisma.sdk_error.create() invocation in C:\Users\cmb\vlly\vlly-api\src\v1\ingestion\error.ts:6:45

  3 //Errors
  4 const errorIngestionHandler = async (req: Request, res: Response) => {
  5   const time = new Date('November 8, 2022, 12:00:00');
→ 6   const errorModel = await prisma.sdk_error.create(
error: Environment variable not found: DATABASE_URL.
  -->  schema.prisma:12
   |
11 |   provider = "mysql"
12 |   url      = env("DATABASE_URL")

Validation Error Count: 1

  4 | const errorIngestionHandler = async (req: Request, res: Response) => {
  5 |   const time = new Date('November 8, 2022, 12:00:00');
> 6 |   const errorModel = await prisma.sdk_error.create({
    |                      ^
  7 |     data: {
  8 |       view_id: '1234',
  9 |       message: 'this is a test',

  at RequestHandler.handleRequestError (node_modules/@prisma/client/runtime/index.js:34316:13)
  at node_modules/@prisma/client/runtime/index.js:34737:25
  at PrismaClient._executeRequest (node_modules/@prisma/client/runtime/index.js:35301:22)
  at PrismaClient._request (node_modules/@prisma/client/runtime/index.js:35273:16)
  at errorIngestionHandler (src/v1/ingestion/error.ts:6:22)

● API Endpoint test › creates new row in error table

Invalid `prisma.sdk_error.create()` invocation in C:\Users\cmb\vlly\vlly-api\src\v1\ingestion\error.ts:6:45

  3 //Errors
  4 const errorIngestionHandler = async (req: Request, res: Response) => {
  5   const time = new Date('November 8, 2022, 12:00:00');
→ 6   const errorModel = await prisma.sdk_error.create(
error: Environment variable not found: DATABASE_URL.
  -->  schema.prisma:12
   |
11 |   provider = "mysql"
12 |   url      = env("DATABASE_URL")
   |

Validation Error Count: 1

  4 | const errorIngestionHandler = async (req: Request, res: Response) => {
  5 |   const time = new Date('November 8, 2022, 12:00:00');
> 6 |   const errorModel = await prisma.sdk_error.create({
    |                      ^
  7 |     data: {
  8 |       view_id: '1234',
  9 |       message: 'this is a test',

  at RequestHandler.handleRequestError (node_modules/@prisma/client/runtime/index.js:34316:13)
  at node_modules/@prisma/client/runtime/index.js:34737:25
  at PrismaClient._executeRequest (node_modules/@prisma/client/runtime/index.js:35301:22)
  at PrismaClient._request (node_modules/@prisma/client/runtime/index.js:35273:16)
  at errorIngestionHandler (src/v1/ingestion/error.ts:6:22)

● API Endpoint test › creates new row in error table

thrown: "Exceeded timeout of 5000 ms for a test.
Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."

  20 |       .expect('Not implemented');
  21 |   });
> 22 |   it('creates new row in error table', async () => {
     |   ^
  23 |     const time =  new Date('November 8, 2022, 12:00:00');
  24 |     const expected = {
  25 |       view_id: '1234',

  at src/v1/ingestion/error.test.ts:22:3
  at Object.<anonymous> (src/v1/ingestion/error.test.ts:8:1)

Edit: added entire error stack trace for more context

Answer №1

To resolve the issue, it was necessary to update the model name from sdk_error to sdkError. It appears that using an underscore in the model name caused a problem.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Obtain the characteristics of a property from an object

Can we extract the type type Values = [number, boolean, string] from the given object? const o = { fst: 1, snd: true, trd: '', } I attempted this approach, but I am looking for types in an array format rather than a union type. type O = t ...

Is it possible to utilize a variable for binding, incorporate it in a condition, and then return the variable, all while

There are times when I bind a variable, use it to check a condition, and then return it based on the result. const val = getAttribute(svgEl, "fill"); if (val) { return convertColorToTgml(val); } const ancestorVal = svgAncestorValue(svgEl, "fill"); if (a ...

What is the best way to enforce input requirements in Typescript?

I am currently facing an issue with two required inputs that need to be filled in order to enable the "Add" button functionality. I have considered using *ngIf to control the visibility of the button based on input values, but it seems to not be working. ...

Can a single global variable be shared between a JavaScript file and a TypeScript file within an Angular project?

In my Angular 5 project, I am implementing a javascript library. If I create a global variable in my .js file, how can I access that variable from my .ts file? ...

Declaration of Typescript index.d.ts for a heavily nested function within an npm module

Regrettably, it appears that @types/rickshaw is lacking content, prompting me to create my own declaration file. The current one I have looks like this: declare module 'rickshaw' { export class Graph { constructor(obj: any); ...

Is it considered acceptable to invoke an asynchronous function that retrieves initial data within the constructor of a JavaScript class?

Currently, I am working on a sample application using Mobx and Mobx React Lite to gain a better understanding of this state management tool. When a user accesses the page, the app should load questions. I have some doubts regarding whether it is advisable ...

Error encountered while compiling an Asp.Net Core project due to exceeding the maximum allowable path length in the

Encountering a critical error during the build process with Visual Studio 2016 update 3 Asp.Net Core. The build is interrupted with the following message: Severity Code Description Project File Line Suppression State Error MSB4018 The "FindC ...

I received an eslint error message instructing me to "Delete the `CD`"

Just started learning Nestjs and I hit a roadblock when attempting to create my first .ts file. I encountered an error message that I'm struggling to comprehend. https://i.sstatic.net/pzhyn.png https://i.sstatic.net/VDH9o.png ...

"An error occurs when attempting to access "this" in a static method as it

Just diving into the world of React and Typescript and currently exploring React hooks. Encountered a problem that's leaving me scratching my head. Here's the hook I'm using to fetch data: export const useFetch = <T>( fetchFunc: ( ...

Tips for displaying the string value of an elementFinder when encountering an error in protractor

I have the following code snippet: export async function waitTillClickable(e: ElementFinder): Promise<ElementFinder> { const conditions = EC.visibilityOf(e); await browser.wait(conditions, DEFAULT_TIMEOUT, `Element did not return ...

Using TypeScript to specify data types in the Vue data object

I am currently utilizing Vue.js with Typescript in a webpack project. Following the guidelines provided in the Recommended Configuration in my tsconfig.json, I have set: "strict": true, Within one of my components, I have: declare interface P ...

What is the best way to bring in an array from a local file for utilization in a Vue 3 TypeScript project?

Encountering a TS7016 error 'Could not find a declaration file for module '../composables/httpResponses'. '/Users/username/project/src/composables/httpResponses.js' implicitly has an 'any' type.' while attempting to ...

Utilize cypress to analyze the loading time of a webpage

My current challenge involves using cypress to carry out website tests. I am looking for a reliable method to measure the duration it takes for certain cypress commands to load or execute. As an example: //var startTime = SomeStopwatchFunction(); cy.visit( ...

The `@ViewChild` reference cannot be found

My main challenge is toggling a @ViewChild element using an *ngIf, followed by invoking a native event. This snippet shows my HTML element, tagged with #audioPlayer for extracting it through @ViewChild. <audio #audioPlayer *ngIf="convers ...

Performing an Axios POST request in a React Native and React app using JSON.stringify and Blob functionality

I am currently developing an application where I have encountered an issue when calling an API endpoint in react native. Interestingly, the web app (built with React) does not encounter any errors. Here is the code for the web app using React with TypeScri ...

The C# private property is inaccessible during a TypeScript callback as it is not contained within the

I'm encountering an issue with TypeScript where the callback function is only returning _proto in the response's .data property when I set private properties in C# and instantiate an object filled with constructed properties. Strangely, if the pr ...

Access network path through browser using Angular

I'm having trouble opening a network path from my browser using the code below. The browser keeps throwing an error saying it's unable to load local resources. Can you please provide some advice on this issue? public openUrl() { window.o ...

Retrieve user roles from core in Angular prior to implementing a guard

Hey, I'm facing an issue with my app.module setup. I have implemented lazy loading to load the core module and store roles in the core component. Everything works fine when I navigate from one page to another with the role guard applied. However, when ...

Steps for importing jQuery typings into TypeScript:1. First, install the jQuery

I've searched for similar questions, but haven't found one that matches my issue. Can someone help me figure out what to do next? In my Visual Studio project, I used package.json to download jquery typings into the node_modules folder: { "ver ...

Adding a click functionality to a dynamically generated anchor tag in angular.js

Recently, I encountered a requirement that involved converting a part of plain text into a clickable link and then adding a click handler to it. The goal was to display some details in a popup when the link is clicked. In order to convert the normal strin ...