issue with Knex query output when integrated with Express.js

Below is the Knex raw SQL query that I have written.

knex.raw("select group_concat(details_odishagovtjobdetails.more_info) as more_info,\
        scrap_odishagovtjobs.start_date,scrap_odishagovtjobs.last_date,scrap_odishagovtjobs.post_name,\
        scrap_odishagovtjobs.education,scrap_odishagovtjobs.requirement_board,scrap_odishagovtjobs.type \
        from scrap_odishagovtjobs inner join details_odishagovtjobdetails\
        on scrap_odishagovtjobs.join_id=details_odishagovtjobdetails.join_id\
         where scrap_odishagovtjobs.type=2 group by scrap_odishagovtjobs.post_name\
    ")

Knex way of writing the query:

let columns = [
'scrap_odishagovtjobs.last_date',
'scrap_odishagovtjobs.start_date',
'scrap_odishagovtjobs.post_name',
'scrap_odishagovtjobs.education',
'scrap_odishagovtjobs.requirement_board',
'scrap_odishagovtjobs.type',
'scrap_odishagovtjobs.join_id',
'details_odishagovtjobdetails.more_info'
];

db.select((db.raw('group_concat(details_odishagovtjobdetails.more_info) as details')),columns).from('scrap_odishagovtjobs').
innerJoin('details_odishagovtjobdetails', 'scrap_odishagovtjobs.join_id', 'details_odishagovtjobdetails.join_id')
.where('scrap_odishagovtjobs.type', 2).groupBy('scrap_odishagovtjobs.post_name')

Response received:

{
    "0": "24-11-2018",
    "1": "12/10/2018",
    "2": "Assistant Professor  – 107 Posts",
    "3": "M.Ch, MD/ MS, M.Sc, DM",
    "4": "OPSC",
    "5": 2,
    "6": 193457,
    "7": "{'Link': 'http://opsconline.gov.in/', 'Title': ' Apply Online'}",
    "details": "{'Link': 'http://opsconline.gov.in/', 'Title': ' Apply Online'},{'Link': 'http://www.opsc.gov.in/Admin/ContAttach/101819.pdf', 'Title': 'Notification '},{'Link': 'http://www.opsc.gov.in/', 'Title': ' Official Website'}"
}

Although I attempted to write the above query in a Knex format with Express.js, I encountered an issue where I am receiving serial numbers for each column instead of actual column names.

I appreciate any assistance provided in reviewing my code.

Answer №1

If you want to make a modification, consider changing

.select((db.raw('group_concat(details_odishagovtjobdetails.more_info) as details')),columns)

to

.select((db.raw('group_concat(details_odishagovtjobdetails.more_info) as details')), ...columns)

To avoid passing both individual values and an array to the select method .select(string, array).

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

Angular-ui typeahead feature allows users to search through a predefined

I recently developed a typeahead feature using the angular-ui library. Here is the current HTML for my typeahead: <input name="customers" id="customers" type="text" placeholder="enter a customer" ng-model="selectedCustomer" uib-typeahead="customer.fir ...

instructions on invoking a function within the knockout $.getJSON() operation

I am currently experimenting with a basic knockout script (still in the learning process). $.getJSON(clientUrl + "/list/" + 1, function (data) { var viewModel = { clients: ko.observableArray(data) }; ko.applyBindings(viewModel); }); The initial arg ...

Icons in React are used to visually represent various actions

I am facing an issue with the React icons I imported on my personal website. They are not displaying at all. Despite reinstalling React Icons multiple times, with and without --save, the problem persists. I have thoroughly checked both the node_modules dir ...

After being redrawn, the line on the canvas vanishes

After updating the angle value, the line is quickly redrawn correctly but then disappears. It seems like the input value may be getting refreshed and set to undefined again. How can I ensure that the line retains the correct angle? <script language=" ...

Error message "ag-grid: Unable to perform the key.forEach function in the console when resizing columns"

Within the application I am working on, I have implemented the ag-grid view. To address the issue related to the last empty pseudo column, I decided to resize the last displayed column using the 'autoSizeColumns' method of ag-grid. While this sol ...

What is the process for including parameters in a javascript/jquery function?

This unique script enables you to click on a specific element without any consequences, but as soon as you click anywhere else, it triggers a fade-out effect on something else. Within the following code snippet, you can interact with elements inside $(&apo ...

Tips for managing numerous HTTP requests in Angular 6

I have a method that is trying to chain together 3 requests like this: showProfileDetails() { this.getUserInfo(this.currentUser.id).pipe( mergeMap(e => this.getAccounts(this.currentUser.id) ), mergeMap(e => this.getPayments ...

You are required to select one of the two radio buttons in order to proceed with the validation process

To prevent the user from proceeding to the next page, validation is necessary. They are required to select one of the radio buttons, etc. <div class=""> <div class="radiho" style="display: block"> <input type="checkbox" name="sp ...

Vue.js isn't triggering the 'created' method as expected

I have a main component called App.vue. Within this component, I have defined the created method in my methods object. However, I am noticing that this method is never being executed. <template> <div id="app"> <Header /> <Ad ...

How can we verify that console.log has been called with a specific subset of expected values using Jest?

I am currently experimenting with a function that adds logging and timing functionality to any function passed to it. However, I am facing a challenge when trying to test the timing aspect of it. Here are my functions: //utils.js export const util_sum = ( ...

Is there a way I can set a variable as global in a jade template?

I am trying to pass a global object to a jade template so that I can use it for various purposes later on. For instance: app.get("/", function(req, res){ var options = { myGlobal : {// This is the object I want to be global "prop ...

How can I update the state with the value of a grouped TextField in React?

Currently working on a website using React, I have created a component with grouped Textfields. However, I am facing difficulty in setting the value of these Textfields to the state object. The required format for the state should be: state:{products:[{},{ ...

Extract information from a Web Service using Javascript

As a novice in web app development, I am currently working on creating a login page and retrieving user data from a local database using JavaScript. Despite my efforts, I seem to have made an error somewhere in my code. Below is the snippet of my JavaScrip ...

Experimenting with NGXS selectors: A comprehensive guide

Hey there, I am currently utilizing the NGXS state management library in my application. I have a selector set up like this and everything seems to be functioning correctly. However, while testing the app, I encountered the following error message: "PrintI ...

The module 'Express' does not have a public member named 'SessionData' available for export

I am encountering an issue while working on my TypeScript project. I am not sure where the error is originating from, especially since nothing has been changed since the last time I worked on it. node_modules/connect-mongo/src/types.d.ts:113:66 - error TS ...

Preventing JQuery from interrupting asynchronous initialization

I am currently developing an AngularJS service for a SignalR hub. Below is the factory code for my service: .factory('gameManager', [function () { $.connection.hub.start(); var manager = $.connection.gameManager; return ...

Challenges with 'this' reference in a requireif causing Vuelidate complications

     Need help with vuejs component using vuelidate and validations:     validations: {      invoice: {          dueDate: {              required,          },          tax: {              require ...

I need help with customizing the progress bar in HTML and CSS

How can I create a progress bar like the one shown below: https://i.sstatic.net/BFv87.png .detail-load { height: 42px; border: 1px solid #A2B2C5; padding: 1px; border-radius: 10px; } .detail-load > .detail-loading { ...

Saving videos for offline viewing in a Vue Progressive Web App with Vue.js 3

I'm having a bit of an issue with my Vue 3 and Typescript setup. I've created a PWA where I display videos, which works perfectly online. However, when I try to access them offline, the videos don't load properly. I have stored the videos in ...

Unable to reset the input value to an empty string

I have created a table with a search bar feature that filters the data when the search button is clicked and resets the filter to show unfiltered data when the clear button is clicked. However, the current input value is not clearing from the display even ...