Comments (6)
The right way to do it is to have a transformer that will map the internal DB type to a type that is useful in your frontend. You don't want this to be coupled in this way at all.
If I wanted to do this (which isn't how I'd approach it, I'd just use the native JS types in the frontend, no need for the backend to dictate types), I'd use a translation layer to map the internal DB types to a type the frontend will understand (ie: your API schema). A simple switch statement would do.
const colTypes = result.columns[0].map((col) => {
switch (col.type) {
case sql.Text:
return 'string';
default:
return 'unknown';
}
});
from node-mssql.
The undefined fields probably shouldn't be getting returned either.
All part of the same problem, I expect.
from node-mssql.
This is all working as intended.
Do you have any specific questions as I'm not really sure what solution you're looking for here?
from node-mssql.
Displaying my lack of expertise with JS I expect.
However I was using res.send(JSON.stringify(result)) to send this back to the client, which does not stringify the type field.
My workround was to replace the type value with the type.declaration value which gives me the JS type.
Not sure how I would get the '[sql.VarChar]' value though.
from node-mssql.
The result
certainly is not intended to be exposed to a front end in that way. The object doesn't implement a toJSON()
method and it could contain all sorts of things that you wouldn't want exposed publicly.
It's never good practice just to dump backend data to the frontend without first sanitising it first. You'd want to whitelist and format the data in a predictable way for the frontend otherwise you aren't in control of your API contract and you're delegating that responsibility to this library instead.
from node-mssql.
I'm writing a generic read-only data viewer which will build the table based on column info, rows (returned and calculated). It will need the datatype to allow column searches to be smart.
I will limit what is sent eventually, but I'm in dev mode at the moment 😁
Am I right in thinking that I need
result.columns[0][0].type[Symbol.for('nodejs.util.inspect.custom')]()
to get the '[sql.VarChar]' info out of the type?
from node-mssql.
Related Issues (20)
- mssql 6 incompatible with node v12 HOT 1
- IN clause parametrize issue HOT 1
- How to connect to SQL Server using tedious (Windows Authentication) HOT 1
- Issue connecting to MSSQL DB in Linux environment HOT 3
- How to use the user-defined data types?
- you have a typo in your readme sql.query`some query` HOT 1
- ConnectionError: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified HOT 1
- Potential impact of disabling connection validation when released from the pool HOT 1
- RequestError: Incorrect syntax near '='. Unable to query to table when values containing equal sign '=', HOT 7
- The "config.server" property is required and must be of type string. HOT 1
- @azure/core-rest-pipeline breaking support for node.js 14 HOT 2
- Does node-mssql support multiSubnetFailover? HOT 9
- Suspected memory leak when streaming data HOT 4
- Problem with Persian/Arabic characters when using input() HOT 4
- Testing library-using code in Jest results in SyntaxError: Unexpected token 'export' HOT 1
- Request timeouts in mssql/msnodesqlv8 when using default Pool size HOT 4
- Bulk Insert row lock not supported HOT 1
- Committing a transaction early, within a transaction ? HOT 4
- [Question] Does node-mssql support Kerberos authentication HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-mssql.