mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-09 13:16:05 +00:00
Create machine-uuid-mysql.js
This commit is contained in:
parent
a586b7c23f
commit
ace15e3248
35
examples/machine-uuid-mysql.js
Normal file
35
examples/machine-uuid-mysql.js
Normal 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;
|
Loading…
Reference in New Issue
Block a user