0
0

More than 1 year has passed since last update.

Node.js: mysql2 で MariaDB のデータを削除 (Delete)

Last updated at Posted at 2020-06-03

プログラム

フォルダー構造

$ 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
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