LoginSignup
0
0

More than 1 year has passed since last update.

Node.js: MariaDB のバージョンを表示

Posted at

プログラム

フォルダー構造

$ tree -a
.
├── .env
├── config_mariadb.js
├── go_version.sh
└── server_version.js
server_version.js
#! /usr/bin/node
// ---------------------------------------------------------------
//	server_version.js
//
//					Feb/24/2023
//
// ---------------------------------------------------------------
'use strict'

var mysql = require('mysql2/promise')
var config_mariadb = require('./config_mariadb')
// ---------------------------------------------------------------
async function main()
{
	const [host, user, password, data_base] = config_mariadb.config_mariadb_proc()
	var conn = await mysql.createConnection ({
		host: host,
		user: user,
		password: password,
		database: data_base
		})


	const sql_str = 'SELECT VERSION ()'
	const rows = await conn.query(sql_str)
	conn.end()
	console.log(rows[0][0])
	console.log(rows[0][0]['VERSION ()'])
	console.error ("*** 終了 ***")
}

// ---------------------------------------------------------------
console.error ("*** 開始 ***")
main()
// ---------------------------------------------------------------
config_mariadb.js
// ---------------------------------------------------------------
//	config_mariadb.js
//
//					Feb/24/2023
//
// ---------------------------------------------------------------
'use strict'


// ---------------------------------------------------------------
exports.config_mariadb_proc = function ()
{
	const dotenv = require('dotenv')
	dotenv.config()
	const host = `${process.env.host}`
	const user = `${process.env.user}`
	const password = `${process.env.password}`
	const data_base = `${process.env.data_base}`

	return [host, user, password, data_base]
}

// ---------------------------------------------------------------
.env
host = 'localhost'
user = 'scott'
password = 'tiger123'
data_base = 'city'

実行スクリプト

go_version.sh
export NODE_PATH=/usr/lib/node_modules
./server_version.js

実行結果

$ ./go_version.sh 
*** 開始 ***
{ 'VERSION ()': '10.11.2-MariaDB' }
10.11.2-MariaDB
*** 終了 ***
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0