RDBMS

  • Revision slug: CommonJS/RDBMS
  • Revision title: RDBMS
  • Revision id: 93336
  • Created:
  • Creator: mcoquet
  • Is current revision? No
  • Comment 55 words added

Revision Content

I don't know much about API design at all but I thought I'd get something onto this page as a start...

I particuarly like the model CodeIgniter uses for the dbms interface: A common interface or abstract class that is then subclassed for each database implementation. This would allow some RDBMS implementations to be done by this project, but should allow for me (a third party) to use my own driver.

What are we gonna call our interface for connecting to a database? Options: RDBMS, DB, Connection, Database? 'DB' is short and rather to the point.

DB : Class {

DB : function (driver, host, username, password, database) // or the following constructor

DB : function (driver, connectionString) // mcoquet: I rather like better passing in an object with the arguments instead of a string like so:

DB : function (driver, connectionConfigObj) // ie: method ("mysql", {host:"bla.com",port:"3306",user:"username",pass:"mypass"})

query : function (sql) // returns a JS object

execute : function (sql)

version : function ()

close : function()

}

I haven't defined any sort of ResultSet object because I'm left to understand that a ResultSet class merely (or often) provides a pretty interface for looping through the results and getting some other minor meta data. Most of this functionality can be achieved by providing a simple structured Javascript object. For example:

myResultSet: {

meta: ['id', 'name', 'age'],

data: [

{ id: 1, name: 'Yunero', age: 22 },

{ id: 2, name: 'Abbadon', age: 45 },

{ id: 3, name: 'Luna', age: 31 }

]

}

Is there much else a recordset needs?

The DB interface is slim to say the least; Often drivers and classes have all sorts of helper methods; In the case of an RDBMS we could add all sorts of methods for update, select, delete, creating/manipulating database schema,.. but often is the case that the more that gets added - the more politics and ideals are gonna slow it down. Should there be more to this design? Perhaps the DB interface above should be more function overloaded?

The prepared statement style of querying (passing a string with "?" placeholders, and additional arguments filling in the placeholders) is a good way of preventing SQL injection. Should it support that syntax?

Revision Source

<p><em>I don't know much about API design at all but I thought I'd get something onto this page as a start...</em></p>
<p>I particuarly like the model CodeIgniter uses for the dbms interface: A common interface or abstract class that is then subclassed for each database implementation. This would allow some RDBMS implementations to be done by this project, but should allow for me (a third party) to use my own driver.</p>
<p>What are we gonna call our interface for connecting to a database? Options: RDBMS, DB, Connection, Database? 'DB' is short and rather to the point.</p>
<p style="margin-left: 40px;">DB : Class {</p>
<p style="margin-left: 80px;">DB : function (driver, host, username, password, database) // or the following constructor</p>
<p style="margin-left: 80px;">DB : function (driver, connectionString) // mcoquet: I rather like better passing in an object with the arguments instead of a string like so:</p>
<p style="margin-left: 80px;">DB : function (driver, connectionConfigObj) // ie: method ("mysql", {host:"bla.com",port:"3306",user:"username",pass:"mypass"})</p>
<p style="margin-left: 80px;">query : function (sql) // returns a JS object</p>
<p style="margin-left: 80px;">execute : function (sql)</p>
<p style="margin-left: 80px;">version : function ()</p>
<p style="margin-left: 80px;">close : function()</p>
<p style="margin-left: 40px;">}</p>
<p>I haven't defined any sort of ResultSet object because I'm left to understand that a ResultSet class merely (or often) provides a pretty interface for looping through the results and getting some other minor meta data. Most of this functionality can be achieved by providing a simple structured Javascript object. For example:</p>
<p style="margin-left: 40px;">myResultSet: {</p>
<p style="margin-left: 80px;">meta: ['id', 'name', 'age'],</p>
<p style="margin-left: 80px;">data: [</p>
<p style="margin-left: 120px;">{ id: 1, name: 'Yunero', age: 22 },</p>
<p style="margin-left: 120px;">{ id: 2, name: 'Abbadon', age: 45 },</p>
<p style="margin-left: 120px;">{ id: 3, name: 'Luna', age: 31 }</p>
<p style="margin-left: 80px;">]</p>
<p style="margin-left: 40px;">}</p>
<p>Is there much else a recordset needs?</p>
<p>The DB interface is slim to say the least; Often drivers and classes have all sorts of helper methods; In the case of an RDBMS we could add all sorts of methods for update, select, delete, creating/manipulating database schema,.. but often is the case that the more that gets added - the more politics and ideals are gonna slow it down. Should there be more to this design? Perhaps the DB interface above should be more function overloaded?</p>
<p>The prepared statement style of querying (passing a string with "?" placeholders, and additional arguments filling in the placeholders) is a good way of preventing SQL injection. Should it support that syntax?</p>
Revert to this revision