LNXSDK/leenkx/Sources/leenkx/logicnode/DatabaseConnectNode.hx
2025-01-22 16:18:30 +01:00

48 lines
1.1 KiB
Haxe

package leenkx.logicnode;
class DatabaseConnectNode extends LogicNode {
#if sys
public var property0: String;
public var connection: sys.db.Connection;
public function new(tree:LogicTree) {
super(tree);
}
override function run(from:Int) {
var user = inputs[1].get();
if (user == null) return;
var password = inputs[2].get();
if (password == null) return;
var socket = inputs[3].get();
var host = inputs[4].get();
if (host == null) return;
var port = inputs[5].get();
if (port == null) return;
var database = inputs[6].get();
if (database == null) return;
try {
connection = sys.db.Mysql.connect({
user: inputs[1].get(),
pass: inputs[2].get(),
socket: inputs[3].get(),
host: inputs[4].get(),
port: inputs[5].get(),
database: inputs[6].get(),
});
if(connection != null){
runOutput(0);
}
} catch(error){
trace('Error durring database connection: ' + error);
}
}
override function get(from: Int): Dynamic {
return switch (from) {
case 1: connection;
default: throw "Unreachable";
}
}
#end
}