welsonjs/examples/machine-uuid-mysql.js
Namhyeon, Go f6f4bd673d
Some checks failed
CodeQL / Analyze (csharp) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Update machine-uuid-mysql.js
2024-07-15 00:37:24 +09:00

42 lines
1.0 KiB
JavaScript

// machine-uuid-mysql.js
// https://github.com/gnh1201/welsonjs
var SYS = require('lib/system');
var client = require('lib/catproxy');
/*
CREATE TABLE `machines` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uuid` varchar(255) NOT NULL,
`created_at` datetime NOT NULL DEFAULT current_timestamp(),
`updated_at` datetime NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (`id`),
UNIQUE KEY `uuid` (`uuid`)
)
*/
var worker = client.create("http://localhost");
worker.set_method("relay_mysql_query");
worker.set_env("mysql_username", "myusername");
worker.set_env("mysql_password", "mypassword");
worker.set_env("mysql_database", "mydatabase");
var machine_uuid = SYS.getUUID();
function register() {
return worker.exec("insert machines (uuid) values ('" + machine_uuid + "')");
}
function main(args) {
var result = register();
var status = result.status;
if (status == 200) {
var last_id = result.last_id;
console.log("LAST_ID: " + last_id);
} else {
console.error("Error code: " + status);
}
}
exports.main = main;