nodejs でモジュール mysql を使用してテーブルの列を一覧表示したい
クエリを実行すると:
SHOW COLUMNS FROM tableName WHERE FIELD = columnName
正常に動作しています。列が存在するかどうかを知ることができます。
しかし、列をリストしたいのですが、オブジェクトのリストを取得しましたが、それをどうするか、そして良い結果が得られた場合はどうすればよいでしょうか。
私は試した :
SHOW COLUMNS FROM tableName
DESCRIBE tableName
両方のクエリで、オブジェクトのリストを取得します
{ catalog: 'def',
db: 'information_schema',
table: 'COLUMNS',
orgTable: 'COLUMNS',
name: 'Field',
orgName: 'COLUMN_NAME',
filler1: ,
charsetNr: 33,
length: 192,
type: 253,
flags: 1,
decimals: 0,
filler2: ,
default: undefined,
zeroFill: false,
protocol41: true }
{ catalog: 'def',
db: 'information_schema',
table: 'COLUMNS',
orgTable: 'COLUMNS',
name: 'Type',
orgName: 'COLUMN_TYPE',
filler1: ,
charsetNr: 33,
length: 589815,
type: 252,
flags: 17,
decimals: 0,
filler2: ,
default: undefined,
zeroFill: false,
protocol41: true }
{ catalog: 'def',
db: 'information_schema',
table: 'COLUMNS',
orgTable: 'COLUMNS',
name: 'Null',
orgName: 'IS_NULLABLE',
filler1: ,
charsetNr: 33,
length: 9,
type: 253,
flags: 1,
decimals: 0,
filler2: ,
default: undefined,
zeroFill: false,
protocol41: true }
{ catalog: 'def',
db: 'information_schema',
table: 'COLUMNS',
orgTable: 'COLUMNS',
name: 'Key',
orgName: 'COLUMN_KEY',
filler1: ,
charsetNr: 33,
length: 9,
type: 253,
flags: 1,
decimals: 0,
filler2: ,
default: undefined,
zeroFill: false,
protocol41: true }
{ catalog: 'def',
db: 'information_schema',
table: 'COLUMNS',
orgTable: 'COLUMNS',
name: 'Default',
orgName: 'COLUMN_DEFAULT',
filler1: ,
charsetNr: 33,
length: 589815,
type: 252,
flags: 16,
decimals: 0,
filler2: ,
default: undefined,
zeroFill: false,
protocol41: true }
{ catalog: 'def',
db: 'information_schema',
table: 'COLUMNS',
orgTable: 'COLUMNS',
name: 'Extra',
orgName: 'EXTRA',
filler1: ,
charsetNr: 33,
length: 90,
type: 253,
flags: 1,
decimals: 0,
filler2: ,
default: undefined,
zeroFill: false,
protocol41: true }
私が使用する機能は次のとおりです。
var mysql = require('mysql');
var connection = mysql.createConnection({
host : "host",
user : "user",
password : "pass",
database : "db"
});
connection.query(myQuery, function(err, rows, fields){
if(err) console.log(err);
if(fields) console.log(fields);
if(rows) console.log(rows);
});
誰かが私に解決策を持っている場合、information_schema も調べて同じ結果を得ようとしました。よろしくお願いします。
同時に、誰かが show table の使い方を教えてくれれば、同様の結果が得られます。