プログラム
フォルダー構造
$ tree -a
.
├── .env
└── server_version.ts
server_version.ts
// ---------------------------------------------------------------
// server_version.ts
//
// Feb/27/2023
//
// ---------------------------------------------------------------
import { Client } from "https://deno.land/x/mysql/mod.ts"
import { config } from "https://deno.land/x/dotenv/mod.ts"
// ---------------------------------------------------------------
console.error ("*** 開始 ***")
const config_env:any = config()
const client = await new Client().connect({
hostname: config_env.host,
username: config_env.user,
password: config_env.password,
db: config_env.data_base,
})
const command:string = "SELECT VERSION ()"
const results = await client.query(command)
console.log(results)
console.log(results[0])
console.log(results[0]["VERSION ()"])
await client.close()
console.error ("*** 終了 ***")
// ---------------------------------------------------------------
.env
host = 'localhost'
user = 'scott'
password = 'tiger123'
data_base = 'city'
実行結果
$ deno run --allow-read --allow-net server_version.ts
*** 開始 ***
INFO connecting localhost:3306
INFO connected to localhost:3306
[ { "VERSION ()": "10.11.2-MariaDB" } ]
{ "VERSION ()": "10.11.2-MariaDB" }
10.11.2-MariaDB
INFO close connection
*** 終了 ***
確認したバージョン
$ deno --version
deno 1.31.0 (release, x86_64-unknown-linux-gnu)
v8 11.0.226.13
typescript 4.9.4