OSX Lionでのsilkjsの新しいWebインストール:
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/
それが機能することを確認します。
mschwartz@dionysus:~/src$ silkjs
SilkJS> console.dir(require('MySQL'));
undefined line 1 (eval):
function () {
this.queryCount = 0;
this.handle = null;
}
undefined
SilkJS>
console.dir()が関数を示していることに注意してください。関数(コンストラクター)のプロパティとして定義されている残りのメソッド。したがって、MySQL()オブジェクトを作成する必要があります。
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>
ここで、接続するには、host、user、passwd、およびdbを渡す必要があります。または、httpd環境で実行している場合は、次のようにConfig.mysqlを設定します。Config.mysql= {host:'localhost'、//またはMySQLサーバーを実行している他のホストuser:' someuser'、// username MySQLサーバーで認証するにはpasswd:'whatever'、// MySQLサーバーのユーザー名のパスワードdb:' database_name"//接続するMySQLサーバーのデータベースの名前};
次に、HTTPサーバーはリクエスト間で利用可能なグローバルSQLオブジェクトを作成します。これは自動的に行われ、SQL.getDataRows()、SQL.getScalar()などを使用できます。