Fresh web install of silkjs on OSX Lion:
mschwartz@dionysus:~/src$ curl http://silkjs.org/install-osx.sh | sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1666 100 1666 0 0 3553 0 --:--:-- --:--:-- --:--:-- 79333
Installing SilkJS in /usr/local/silkjs
You may be asked to enter your password.
This is so the /usr/local directory can be made writable for the install.
Password:
Downloading SilkJS
######################################################################## 100.0%
Installation complete.
You need to add /usr/local/bin to your PATH environment variable.
This can be done by adding this line to your .bashrc file:
export PATH=/usr/local/bin:$PATH
You can run SilkJS with the following command:
$ silkjs
You can run the SilkJS HTTP Server with the following command:
$ httpd-silk.js yourapp.js
For instructions on setting up a WWW site for httpd-silk.js, see
http://silkjs.org/http-server/
Now to see it works:
mschwartz@dionysus:~/src$ silkjs
SilkJS> console.dir(require('MySQL'));
undefined line 1 (eval):
function () {
this.queryCount = 0;
this.handle = null;
}
undefined
SilkJS>
Note the console.dir() shows a function. The rest of the methods defined as properties of the function (constructor). So you must construct a MySQL() object:
SilkJS> var mysql = require('MySQL');
SilkJS> m = new mysql();
SilkJS> console.log(m.connect)
function (host, user, passwd, db) {
if (!this.handle) {
host = host || Config.mysql.host;
user = user || Config.mysql.user;
passwd = passwd !== undefined ? passwd : Config.mysql.passwd;
db = db || Config.mysql.db;
this.handle = mysql.connect(host, user, passwd, db);
}
}
undefined
SilkJS>
Now, in order to connect, you have to pass in host, user, passwd, and db. Or if you're running in the httpd environment, you set Config.mysql, something like this:
Config.mysql = {
host: 'localhost', // or some other host running MySQL server
user: 'someuser', // username to authenticate in MySQL server
passwd: 'whatever', // password of username in MySQL server
db: 'database_name" // name of database in MySQL server to connect to
};
Then the HTTP server will create a global SQL object available from request to request. This is automatic, you can just use SQL.getDataRows(), SQL.getScalar(), and so on.