Node MySQL Help | Sololearn: Learn to code for FREE!

0

Node MySQL Help

I am trying to build a program that will return the tavles, fields, and field data types of a sql database. I have the tables and field names printing propery. however the field object that is returned from the connection is returning a number as the "type" ie. instead of returning VARCHAR, it is returning a number like 231. I have had no luck finding a table to tell me what the numeric value equivalent is for SQL data types. any help would be appreciated.

10/22/2018 10:10:16 PM

Brandon

7 Answers

New Answer

0

what's your query to get the fields ?

0

it loops through the tables by: for(x in tables){ connect((conn)=>{ conn.query('SELECT * FROM ${tables[x]}', (err, results, fields)=>{ console.log(fields[0].type) }); }); } thats obviously just a basic gist of what I am doing to get the fields without error handling and whatnot to have an idea of how I am getting them. the "mysql" module returns 3 objects in its callback: error object, result object, and fields object. I know there is a way to get the fields via schema, but if i could do it all in one query that would defibately be the way to go. the fields object gives a type, its just a serial number for the data type and i want to find a list of those serial numbers so that i can write a method to convert them to strings such as VARCHAR or INT. If that makes sense.

0

i'm not sure its probably based on the packages youre using you can try this query SHOW COLUMNS FROM `tablename`

0

I will give that a go when I get back to my computer.

0

Thanks!

0

sure, here's the doc https://dev.mysql.com/doc/refman/8.0/en/show-columns.html

0

That is exactly what I was looking for. there is always an easier way lol thanks again.