Skip to content

Commit 33a09e9

Browse files
committed
Terminology change from Driver to Adapter
Updated terminology, where third-party database adapters are now called Adapters instead of Drivers.
1 parent 44ea464 commit 33a09e9

File tree

5 files changed

+48
-50
lines changed

5 files changed

+48
-50
lines changed

Drivers.md renamed to Adapters.md

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# Creating drivers for orm2
1+
# Creating database adapters for orm2
22

3-
To add a driver to `orm2`, call its `addDriver` method:
3+
To add a database adapter to `orm`, call its `addAdapter` method:
44

55
```js
6-
require('orm2').addDriver('cassandra', CassandraDriver);
6+
require('orm2').addAdapter('cassandra', CassandraAdapter);
77
```
88

99
The first argument is the alias to register for connection URLs. For example, the above will allow you to do this:
@@ -13,29 +13,29 @@ var orm = require('orm2');
1313
orm.connect('cassandra://username:password@localhost/test', function (err, db) { });
1414
```
1515

16-
The second argument is the constructor for your driver object.
16+
The second argument is the constructor for your adapter object.
1717

18-
## Defining driver objects
18+
## Defining adapters
1919

20-
Your driver should provide the following members.
20+
Your adapter should provide the following members.
2121

2222
### Constructor(config, connection, opts)
2323

24-
The driver object constructor should have three parameters:
24+
The adapter object constructor should have three parameters:
2525

2626
* config - optional configuration for the database connection. It contains the following properties:
2727
* timezone - optional timezone
2828
* href - URL to use for connecting to the database if the connection argument is null
2929
* host - The hostname of `href`
3030
* pathname - The `path` of `href`
31-
* ssl - Boolean indicating whether the driver should use SSL when connecting to the database
32-
* query - Optional configuration for how the driver should perform queries
31+
* ssl - Boolean indicating whether the adapter should use SSL when connecting to the database
32+
* query - Optional configuration for how the adapter should perform queries
3333
* ssl - Boolean indicating whether queries should be sent using SSL
3434
* strdates - Boolean indicating whether strings should be used for dates
3535
* connection - optionally passed if reusing an existing connection
36-
* opts - optional options configuring the driver's behavior. It contains the following properties:
37-
* pool - A boolean indicating whether the driver should use connection pooling
38-
* debug - If true, whether the driver should operate in debug mode
36+
* opts - optional options configuring the adapter's behavior. It contains the following properties:
37+
* pool - A boolean indicating whether the adapter should use connection pooling
38+
* debug - If true, whether the adapter should operate in debug mode
3939
* settings - A key/value object store. Use `get(key)` and `set(key, value)` methods to manipulate the settings. The
4040
following settings are defined:
4141
* properties.primary_key - The column/field name to use for object primary keys
@@ -48,7 +48,7 @@ This should be set to `true` if your database is a SQL database.
4848

4949
### customTypes property
5050

51-
Your driver should have a `customTypes` object, with the property names being the names of the custom types, and each
51+
Your adapter should have a `customTypes` object, with the property names being the names of the custom types, and each
5252
value being the options relating to the type.
5353

5454
### connect(cb) method (required)
@@ -118,11 +118,11 @@ For SQL databases, this executes a `Query` object from the `sql-query` package.
118118

119119
### aggregate_functions[] property (optional)
120120

121-
If your driver supports SQL aggregate functions, this should be an array of supported function names.
121+
If your adapter supports SQL aggregate functions, this should be an array of supported function names.
122122

123123
### hasMany(Model, association) method (optional)
124124

125-
If your driver maintains associations in a unique (non-SQL-like) manner, return an object from this method to implement
125+
If your adapter maintains associations in a unique (non-SQL-like) manner, return an object from this method to implement
126126
a one-to-many association. The return value should have the following methods:
127127

128128
* has(Instance, Associations, conditions, cb) - tests if the associations have any objects matching the conditions
@@ -132,7 +132,7 @@ a one-to-many association. The return value should have the following methods:
132132

133133
### sync(opts, cb) method (optional)
134134

135-
If your driver supports creating a table from a model, implement this method. The following options are passed:
135+
If your adapter supports creating a table from a model, implement this method. The following options are passed:
136136

137137
* extension
138138
* id
@@ -147,7 +147,7 @@ If your driver supports creating a table from a model, implement this method. Th
147147

148148
### drop(opts, cb) method (optional)
149149

150-
If your driver supports dropping a table, implement this method. The following options are passed to this method:
150+
If your adapter supports dropping a table, implement this method. The following options are passed to this method:
151151

152152
* table - The name of the table
153153
* properties
@@ -156,6 +156,4 @@ If your driver supports dropping a table, implement this method. The following o
156156

157157
### on(event, cb) method (required)
158158

159-
Your driver should be an `EventEmitter`, and should emit the following types of events, when applicable:
160-
161-
* error
159+
Your adapter should be an `EventEmitter`, and should emit the `error` event when applicable.

Readme.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -841,13 +841,13 @@ Person(1).getPets(...);
841841
Pet(2).getOwners(...);
842842
```
843843

844-
## Adding external drivers
844+
## Adding external database adapters
845845

846-
To add an external driver to `orm2`, call the `addDriver` method, passing in the alias to use for connecting with this
847-
driver, along with the constructor for the driver object:
846+
To add an external database adapter to `orm`, call the `addAdapter` method, passing in the alias to use for connecting
847+
with this adapter, along with the constructor for the adapter:
848848

849849
```js
850-
require('orm2').addDriver('cassandra', CassandraDriver);
850+
require('orm').addAdapter('cassandra', CassandraAdapter);
851851
```
852852

853-
See [the documentation for creating drivers](./Drivers.md) for more details.
853+
See [the documentation for creating adapters](./Adapters.md) for more details.

lib/Adapters.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var aliases = require('./Drivers/aliases');
2+
3+
module.exports.add = addAdapter;
4+
module.exports.get = getAdapter;
5+
6+
7+
var adapters = {};
8+
9+
function addAdapter(name, constructor) {
10+
adapters[name] = constructor;
11+
}
12+
13+
function getAdapter(name) {
14+
if (name in aliases) {
15+
return getAdapter(aliases[name]);
16+
} else if (!(name in adapters)) {
17+
adapters[name] = require("./Drivers/DML/" + name).Driver;
18+
}
19+
20+
return adapters[name];
21+
}

lib/Drivers/drivers.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

lib/ORM.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var _ = require("lodash");
88

99
var Model = require("./Model").Model;
1010
var DriverAliases = require("./Drivers/aliases");
11-
var drivers = require("./Drivers/drivers");
11+
var adapters = require("./Adapters");
1212
var Settings = require("./Settings");
1313
var Singleton = require("./Singleton");
1414
var ORMError = require("./Error");
@@ -49,7 +49,7 @@ exports.use = function (connection, proto, opts, cb) {
4949
}
5050

5151
try {
52-
var Driver = drivers.get(proto);
52+
var Driver = adapters.get(proto);
5353
var settings = new Settings.Container(exports.settings.get('*'));
5454
var driver = new Driver(null, connection, {
5555
debug : (opts.query && opts.query.debug === 'true'),
@@ -110,7 +110,7 @@ exports.connect = function (opts, cb) {
110110
}
111111

112112
try {
113-
var Driver = drivers.get(proto);
113+
var Driver = adapters.get(proto);
114114
var settings = new Settings.Container(exports.settings.get('*'));
115115
var debug = extractOption(opts, "debug");
116116
var pool = extractOption(opts, "pool");
@@ -143,7 +143,7 @@ exports.connect = function (opts, cb) {
143143
return db;
144144
};
145145

146-
exports.addDriver = drivers.add;
146+
exports.addAdapter = adapters.add;
147147

148148
function ORM(driver_name, driver, settings) {
149149
this.validators = exports.validators;

0 commit comments

Comments
 (0)