Using Strapi to run basic raw SQL queries with MySQL

Trying to execute this query in my test but struggling with the correct syntax.

return strapi.connections.default.raw(`
            delete from nurses;
            delete from users_permissions_user;`);
    });

Since this is not using PostgreSQL and MySQL does not support hyphens in table names, are there any suggestions on how to proceed?

Answer №1

Avoid using prohibited characters as it simplifies life greatly.

The inclusion of backticks around the String eliminates the need for escaping single and double quotes.

When working with MySQL, you can utilize double quotes but remember to only use single quotes for strings in your SQL code.

return strapi.connections.default.raw("
            delete from nurses;
            delete from `users-permissions_user`;");
    });

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

Utilize Bootstrap modal to input information into the DataTables library

I am trying to use a bootstrap modal to insert data, but I am encountering an error on the action index. As a result, the button that I added is not functioning correctly. Can someone please review my code to see if there are any mistakes? User Action Con ...

Is it possible to search for multiple attributes within a JSON object array simultaneously?

In my database, there is a column containing a JSON array with a structure similar to this example - { "id": "123abc", "Y/N": "Y", "Color": "Purple", "arr": [ { "time": 1210.55, "person": "Sean", "action": "yes" //Only 'yes', 'n ...

Create an input box with a designated class

When I click the button in my HTML and JavaScript code below, I am able to dynamically add a text field and radio button. This functionality is working properly. However, I also want the newly generated text field to have the same font size and appearance ...

Update a JSON value using an MUI Switch element

I am currently developing a feature that involves toggling the state of an MUI switch based on API responses. The status of the Switch is determined by the Active field in the API response. If the JSON field is 1, the switch is turned on, and if it's ...

Passing JSON data from an ASP.NET controller to a view

My issue arises when a web page is loaded and triggers a controller action to retrieve data based on user selection. I am trying to return this data as a JSON object, but it appears as a single string within the HTML page. The basic structure of the contro ...

Tips for streamlining the process of integrating SQL Server with Python

I am currently tackling a project where data is generated in SQL server and will require processing within Python to complete the task. I am considering a few different options for how to approach this: (1) Execute the SQL code directly from Python and ma ...

Convenient ways to connect data between a database and Firebase authentication system

After beginning a basic app using Firebase 3 and Angular 1, I implemented an authentication system through Firebase for user registration and login. Currently, I am storing message data in the Firebase database. My main question is: how can I connect user ...

What is the best way to modify the state of a particular element in an array when using useState in React?

In my Next.js application, I am using a useState hook to manage state. Here is how my initial state looks like: const [sampleData, setSampleData] = useState({ value1: '', value2: '', value3: [] }); To update the state ...

Render doesn't wait for the componentWillMount lifecycle method

I'm currently working on implementing a redirection to the home page for logged-in users. I'm using ping to fetch login information, setting a state based on the response, and then checking that state in the render method for redirection. However ...

The Server Components render encountered a glitch

Screenshot of the errorI am encountering a strange error only in the production environment. The lack of additional information leads me to believe it may be due to security measures put in place for production. Unfortunately, I have been unable to repli ...

Revamp List Model through Ajax Integration in ASP .NET MVC5

Could someone please provide a hint on how to update the Model list in the view page after calling the Action Result with an Ajax request? Specifically, how can I refresh the current list model with the result of the Ajax call back? Here is the code for m ...

What is the best approach to including files in addition to other data fields when calling a webmethod in asp.net using a jquery ajax request?

My webform contains a variable number of textboxes and dropdowns. To send data to the server-side webmethod, I am utilizing the following code: $.ajax({ type: "POST", url: "SupplierMaster.aspx/RegisterSupplier", data: JSON.stringify({ ...

Is it possible to send variables within an ajax request?

I'm currently in the process of building my own website, and I have a specific requirement where I need to display different queries based on which button is clicked. Can this be achieved using the following code? Here's the HTML snippet: <d ...

What is the mechanism behind JQuery Ajax?

Currently, I am attempting to utilize JQuery Ajax to send data to a Generic Handler for calculation and result retrieval. Within my JQuery script, the Ajax request is contained within a for loop. The structure of the code resembles the following: function ...

Adjust the header image as you scroll

Currently, I have a static image in the header of the page. I'm looking to have the image change to a different one when half the page has been scrolled. Do I need to utilize JavaScript for this functionality or is it achievable with CSS alone? bo ...

How can I prevent mouse movement hover effects from activating in a media query?

I have implemented a custom image hover effect for links in my text using mousemove. However, I want to disable this feature when a specific media query is reached and have the images simply serve as clickable links without the hover effect. I attempted ...

Redux: Double rendering issue in mapStateToProps

I've recently delved into learning Redux, and I've encountered an issue that's been on my mind. import React, { useEffect } from "react"; import { connect, useDispatch } from "react-redux"; import Modal from "../Moda ...

Integrate a scrollbar seamlessly while maintaining the website's responsiveness

I encountered an issue where I couldn't add a scrollbar while maintaining a responsive page layout. In order to include a scrollbar in my datatables, I found the code snippet: "scrollY": "200px" However, this code sets the table size to 200 pixels r ...

What is the correct way to use fitBounds and getBounds functions in react-leaflet?

I'm struggling with calling the fitBounds() function on my Leaflet map. My goal is to show multiple markers on the map and adjust the view accordingly (zoom in, zoom out, fly to, etc.). I came across an example on How do you call fitBounds() when usi ...

Stripping quotation marks from CSV information using Javascript

After performing a fetch request using JavaScript, I have converted JSON data into CSV format. datetime","open","high","low","close","volume" "2020-01-28","312.48999","318.39999","312.19000","317.69000","31027981" "2020-01-27","309.89999","311.76001","30 ...