Answer the question
In order to leave comments, you need to log in
How to fix an error when accessing the database?
Hello!
There is a project with a git on a node with slonik (a library for interacting with the database), I launched it, I see how it works. I send requests to him from Postman - if it's just on api - the request works, there are no problems. If interaction with the database is required, then an error occurs:
TypeError: slonik_1.sql.raw is not a function.
earlier I downgraded slonik because in the same places (with sql.raw) another error came out: Property 'raw' does not exist on type. There, the library was placed in a strange way and no reference was made to the raw interface.
i googled the error "TypeError: slonik_1.sql.raw is not a function." - there is a similar solution here, but this is either not my case or I do not have enough knowledge and experience to bring it to my case. There db.query is suggested to replace db.serialize.query. I tried instead of:
slonik_1.sql.raw
to do:
slonik_1.sql.serialize.raw
but it didn't help - my code doesn't know serialize type for sql.
Question: what can I try to do to fix the error?
Additional information to the question:
1) About what I do:
- The project is a backend for a mobile application: it processes requests/receives/sends data. I want to understand how the back-end works. To do this, I deployed it on the local host and connected it to the Postgresql database also on the local server (although I have no exact confidence that the connection to the database has been established, but there are no errors when determining the database url). Because I don't have a mobile application, I use Postman as a client.
- The backend has an Api file where requests are processed. First, I checked the GET request by simply inserting the request processing right away with the data into the Api file (so as not to touch the database) and sent the request to the port with the application with Postman. Everything is OK, the request has returned, the data has been brought.
- Now I want to go deeper and get to the database: make a Post request in Postman so that the backend writes it to the database. But I get an "internal" error in response to a data write request in Postman, and an error in visual studio code: TypeError: slonik_1.sql.raw is not a function.
2) Error in more detail:
In more detail, the error looks like this (the application does not crash):
TypeError: slonik_1.sql.raw is not a function
at Object.getToken (C:\Users\user\Desktop\backend\dist\db.js:87:32)
at C:\Users\user\Desktop\backend\dist\api.js:336:32
at C:\Users\user\Desktop\backend\dist\api.js:278:30
at Layer.handle [as handle_request] (C:\Users\user\Desktop\backend\node_modules\express\lib\router\layer.js:95:5)
at next (C:Users\user\Desktop\backend\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\user\Desktop\backend\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\user\Desktop\backend\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\user\Desktop\backend\node_modules\express\lib\router\index.js:281:22
at Function.process_params (C:\Users\user\Desktop\backend\node_modules\express\lib\router\index.js:335:12)
at next (C:\Users\user\Desktop\backend\node_modules\express\lib\router\index.js:275:10)
at C:\Users\user\Desktop\backend\dist\api.js:68:5
at Layer.handle [as handle_request] (C:\Users\user\Desktop\backend\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (C:\Users\user\Desktop\backend\node_modules\express\lib\router\index.js:317:13)
at C:\Users\user\Desktop\backend\node_modules\express\lib\router\index.js:284:7
at Function.process_params (C:\Users\user\Desktop\backend\node_modules\express\lib\router\index.js:335:12)
at next (C:\Users\user\Desktop\backend\node_modules\express\lib\router\index.js:275:10)
const escapeNames = (names: string[]) => sql.raw(names.map(x => escapeName(x).sql).join(', ')); //(raw - подчеркивается)
const svalue = value => sql.valueList([value]); //(valueList- подчеркивается)
function _insert(obj) {
const schema = Schema.get(obj);
const keys = schema.cols.map(x => x[0]).filter(x => !schema.serials.includes(x));
return sql`
INSERT INTO ${escapeName(schema.name)} (${escapeNames(keys)})
VALUES ${sql.tuple(keys.map(x => obj[x]))}
`;//(.tuple - подчеркивается)
}
Answer the question
In order to leave comments, you need to log in
I found a solution: I read about slonik and its versions, found out that they replaced the expressions in which I had an error as indicated here:
sql.raw
This question is not about Postgresql, there is nothing to even cling to. Slonik is a command shell for Slony-I from what I know. Here, apparently, another elephant of some kind.
And here Postman, api, who is db.query/db.serialize.query - is unknown.
Describe the stack of tools you use, the sequence of actions, show the code.
And put the tags (if it's a fucking sequelize put Node.js)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question