This example demonstrates how to connect to different databases (MySQL, Firebird, MS SQL, and PostgreSQL). The files of data adapters are located in the directory with this example. You can include adapters into your projects without any changes.

First, you should connect all the required modules and data adapters, this is done using the require() standard function::
var http = require("http");
var adapter = require("stimulsoft-data-adapter");

Next, define the accept() main function that will work with adapters - load all data from the request and run the adapter to execute the received command. Define the onProcess() callback function to process the result:
function accept(request, response) {
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT");
    response.setHeader("Cache-Control", "no-cache");

    var data = "";
    request.on('data', function (buffer) {
        data += buffer;
    });

    request.on('end', function () {
        var command = adapter.getCommand(data);
        adapter.process(command, function (result) {
            var responseData = getResponse(result);
            response.end(responseData);
        });
    });
}

All is ready, start the server and specify the required port, in this case, 9615:
http.createServer(accept).listen(9615);

Auf dem Screenshot unten Sie können das Ergebnis des Beispiel-Codes ansehen:

Starting SQL Adapters from the HTTP Server

By using this website, you agree to the use of cookies for analytics and personalized content. Cookies store useful information on your computer to help us improve efficiency and usability. For more information, please read the privacy policy and cookie policy.