http://www.wikihouse.com/winebarrel/index.php?rubbish-db
NativeJavaArrayを拡張してみました。
あと、名前つきパラメータもプロパティとしてつかえるようにしました。
#!/usr/bin/env rhino
importPackage(Packages.rubbish.db);
importPackage(Packages.rubbish.db.sql);
importPackage(Packages.rubbish.db.util.array);
JsArrayExtension.extend();var dbh = new RubbishDatabase();
dbh.logging = true;dbh.connect("jdbc:hsqldb:hsql://localhost", "sa", "", function(dbh) {
dbh.query("SELECT ID, NAME FROM PUBLISHER ORDER BY ID", function(row) {
print(row.id + ": " + row.get("name"));
});var rows = dbh.query("SELECT * FROM PUBLISHER");
var collected = rows.collect(function(row) {
return (row.id > 3);
});for(var i in collected) {
print(collected[i].id + ": " + collected[i].name);
}var sql = new JsStatement("SELECT * FROM PUBLISHER WHERE ID=:id");
sql.id = "01";
print(dbh.getRow(sql));
});