Create machine-uuid-mysql.js

This commit is contained in:
Namhyeon Go 2024-07-15 00:35:00 +09:00 committed by GitHub
parent a586b7c23f
commit ace15e3248
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,35 @@
// machine-uuid-mysql.js
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 last_id = result.last_id;
console.log("LAST_ID: " + last_id);
}
exports.main = main;