My favorites | Sign in
Project Home Wiki Issues Source
Search
for
HigherLevelDatabaseAPI  
Proposal for two new higher-level database APIs
Deprecated
Updated Feb 4, 2010 by gears.te...@gmail.com

Problem

This proposal seeks to address two issues that affect many people using the current database API:

Solution

This can be solved by adding two new APIs:

class ResultSet {
  readonly property JsObject currentRow;
}

class Database {
  JsArray executeToArray(String sql, optional JsArray params);
}

Example usage:

var resultSet = db.execute("SELECT Name, NumCLs FROM GearsTeam");
while (resultSet.currentRow) {
  alert(resultSet.currentRow.Name + " has submitted " +
        resultSet.currentRow.NumCLs + " change lists!");
  resultset.next();
}

var rows = db.executeToArray("SELECT Name, NumCLs FROM GearsTeam");
for (var i = 0; i < rows.length; i++) {
  alert(row.Name + " has submitted " + row.NumCLs + " change lists!");
}

Details

  • currentRow is a property, not a method.
    • This makes it a little more convenient because you don't have to declare a local variable if you don't need to.
    • We should cache it in the resultset after the first access.
    • It also doubles as a way to end the loop because it is null when the resultset is empty.

Alternatives

  • Put something like toArray() on the resultset object.
    • One downside of this is that toArray() is destructive -- it closes the resultset.
  • Call executeToArray() something like select() instead.
    • This is cute, but it's a little weird that you can actually pass an INSERT statement to the select() method, or a SELECT statement to the execute() method.

Sign in to add a comment
Powered by Google Project Hosting