Jump to content
Sign in to follow this  
bilcan

SQL Server Connection

Recommended Posts

Hello,

2 questions.

* We can write a Http or Websocket server software via Smart Mobile Studio. Is it possible to connect SQL Server directly? 

* Can I create a thread to handle websocket messages?

Share this post


Link to post
Share on other sites

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 :)

https://www.npmjs.com/search?q=SQLServer

 

Share this post


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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×