mlaanderson / database-js

Common Database Interface for Node
MIT License
74 stars 16 forks source link

Simpler driver names #8

Closed thiagodp closed 6 years ago

thiagodp commented 6 years ago

Instead of using database-js-driver://, the project could adopt just driver://.

Examples (JDBC-like):

Other examples (for future use?):

mlaanderson commented 6 years ago

With the current implementation, the driver is loaded with a require. Since there were several packages with those names, I opted to use the longer names.

We could use a scheme like:

function loadModule(driver_name) {
    try {
        require.resolve(driver_name);
        return require(driver_name);
    } catch (e) {
       return false;
    }
}

driver = loadModule('database-js-' + driver_name) || loadModule('jsdbc-' + driver_name) || require(driver_name);

That would allow database-js-* drivers to be loaded by their simple name.

mlaanderson commented 6 years ago

Added in 8512ad58171c1b0a30ef0870ea3690d8dd7f631b, and tagged in v1.3.1

Simple names (e.g. postgres, mysql) will now resolve to database-js-simplename or jsdbc-simplename.