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.

22nd Oct 2018, 10:10 PM
Brandon
Brandon - avatar
7 Respostas
0
what's your query to get the fields ?
22nd Oct 2018, 10:18 PM
Taste
Taste - avatar
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.
22nd Oct 2018, 10:31 PM
Brandon
Brandon - avatar
0
i'm not sure its probably based on the packages youre using you can try this query SHOW COLUMNS FROM `tablename`
22nd Oct 2018, 10:38 PM
Taste
Taste - avatar
0
I will give that a go when I get back to my computer.
22nd Oct 2018, 10:40 PM
Brandon
Brandon - avatar
0
Thanks!
22nd Oct 2018, 10:40 PM
Brandon
Brandon - avatar
22nd Oct 2018, 10:42 PM
Taste
Taste - avatar
0
That is exactly what I was looking for. there is always an easier way lol thanks again.
22nd Oct 2018, 11:04 PM
Brandon
Brandon - avatar