Jump to content

SQL Server Connection

Recommended Posts

You dont do threads in JS unless its exceptionally important.
Server side you delegate work between processes, as in shell-execute and then passing work to it via node's message channel.

So lets say you have a heavy duty server and for some reason need threading, you would write the thread code as a completely separate node application. In the server you would then start the process on demand and then pass the socket-handle (the request object) to the newly created process.

This is the same as threading but easier to build up on since you are using the outer layer of shell/os.

You can also use web-workers, which are threads, but still need to pass the request object (or whatever else you need) via messages, so most people just spawn a new process and pass in the request to handle it.

So a low down would be:

  • Server accepts request
  • Server creates a process for handling the request
  • Server pass the http/websocket request to the process
  • process does whatever its designed to do
  • Server is notified when the process is done or have failed

So its more or less the same.

I should underline that the whole point of ASYNC coding is to avoid threading as much as possible, but i realize that this mindset can be a bit alien for beginners in Smart Pascal - so you can evolve with it safely as you get more into it :)

When it comes to DB then yes, absolutely - but im not sure there is a SQL server wrapper for it. But node supports just about every DB engine out there.
Its one of the engines I will write a connection class for in our next 2 updates. SQLite is already there (actually we have 2, one via node and one we compiled to asm.js ourselves), mariadb (mysql), MSSQL, Firebird and oracle is on my list.

Simply google if node.js can do it -- if it can, we can do it also. But when importing modules like this, someone have to write a wrapper.
Its like delphi when using a dll file, you have to write defines for the methods etc. and load in the module before using it.
So its fairly identical to how you work with external code in delphi.

Visit NPM and have a look, there are quite a bit to pick from :)



Link to post
Share on other sites

Hello Lennart,

yes I am quite foreigner to NodeJS architecture, so as far as I understand, I do not need to use threads and also I should not use.

I did have a look to server examples but they are quite simple, I hope you will write more complicated examples.

As for DB, I think I have to wait for a while more for a SQL Server connection wrapper.


Thank you for your great explanation.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...