Adding database support to aftJS (in both Server! and AFT!)

In the next version of the aftJS language (that will be included with Server! v6 and AFT! v4) you’ll find, for the first time, client objects to interact with several SQL and NoSQL databases.

At the time this article is being written, this is still work in progress. But for those of you who can’t wait, here’s an actual script that we tested successfully just moments ago:

  var cli = new SqlCli().Driver("sqlite").ConnString(":memory:");
  cli.Exec('CREATE TABLE places (place text NULL,code integer)');
  cli.Exec('INSERT INTO places (place, code) VALUES (?,?)', ['universe', 42]);
  cli.Exec('INSERT INTO places (place, code) VALUES (?,?)', ['milky way', 23]);
  var res = cli.Query('SELECT * FROM places');

And here’s the log line that proves it works:

2021-07-06 13:11:32.290 INF > nodeId="lucid-booth" sender="scripting" 
sessionId="NdhiyPt9NajTewVuegFTi8" protocol="SSH2" event="OnAuthSuccess" 
scriptId="dbtest" scriptName="My DB script" method="Log" 
[{"place":"universe","code":42},{"place":"milky way","code":23}]