プログラム
フォルダー構造
$ tree -a
.
├── .env
├── config_mariadb.js
├── go_delete.sh
└── maria_delete.js
Async/Await を使います。
maria_delete.js
#! /usr/bin/node
// ---------------------------------------------------------------
// maria_delete.js
//
// Feb/24/2023
//
// ---------------------------------------------------------------
'use strict'
var mysql = require('mysql2')
var config_mariadb = require('./config_mariadb')
// ---------------------------------------------------------------
async function main(id_in)
{
const [host, user, password, data_base] = config_mariadb.config_mariadb_proc()
var conn = await mysql.createConnection ({
host: 'localhost',
user: user,
password: password,
database: data_base
})
const command = "delete from cities where id = '" + id_in + "'"
await conn.execute(command)
conn.end()
console.error ("*** 終了 ***")
}
// ---------------------------------------------------------------
console.error ("*** 開始 ***")
const id_in = process.argv[2]
console.log (id_in)
main(id_in)
// ---------------------------------------------------------------
.env
config_mariadb.py
はこちら
Node.js: MariaDB のバージョンを表示
実行コマンド
go_delete.sh
export NODE_PATH=/usr/lib/node_modules
./maria_delete.js t3327
確認したバージョン
$ node -v
v19.7.0