1
- # Creating drivers for orm2
1
+ # Creating database adapters for orm2
2
2
3
- To add a driver to ` orm2 ` , call its ` addDriver ` method:
3
+ To add a database adapter to ` orm ` , call its ` addAdapter ` method:
4
4
5
5
``` js
6
- require (' orm2' ).addDriver (' cassandra' , CassandraDriver );
6
+ require (' orm2' ).addAdapter (' cassandra' , CassandraAdapter );
7
7
```
8
8
9
9
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');
13
13
orm .connect (' cassandra://username:password@localhost/test' , function (err , db ) { });
14
14
```
15
15
16
- The second argument is the constructor for your driver object.
16
+ The second argument is the constructor for your adapter object.
17
17
18
- ## Defining driver objects
18
+ ## Defining adapters
19
19
20
- Your driver should provide the following members.
20
+ Your adapter should provide the following members.
21
21
22
22
### Constructor(config, connection, opts)
23
23
24
- The driver object constructor should have three parameters:
24
+ The adapter object constructor should have three parameters:
25
25
26
26
* config - optional configuration for the database connection. It contains the following properties:
27
27
* timezone - optional timezone
28
28
* href - URL to use for connecting to the database if the connection argument is null
29
29
* host - The hostname of ` href `
30
30
* 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
33
33
* ssl - Boolean indicating whether queries should be sent using SSL
34
34
* strdates - Boolean indicating whether strings should be used for dates
35
35
* 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
39
39
* settings - A key/value object store. Use ` get(key) ` and ` set(key, value) ` methods to manipulate the settings. The
40
40
following settings are defined:
41
41
* 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.
48
48
49
49
### customTypes property
50
50
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
52
52
value being the options relating to the type.
53
53
54
54
### connect(cb) method (required)
@@ -118,11 +118,11 @@ For SQL databases, this executes a `Query` object from the `sql-query` package.
118
118
119
119
### aggregate_functions[ ] property (optional)
120
120
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.
122
122
123
123
### hasMany(Model, association) method (optional)
124
124
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
126
126
a one-to-many association. The return value should have the following methods:
127
127
128
128
* 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:
132
132
133
133
### sync(opts, cb) method (optional)
134
134
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:
136
136
137
137
* extension
138
138
* id
@@ -147,7 +147,7 @@ If your driver supports creating a table from a model, implement this method. Th
147
147
148
148
### drop(opts, cb) method (optional)
149
149
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:
151
151
152
152
* table - The name of the table
153
153
* properties
@@ -156,6 +156,4 @@ If your driver supports dropping a table, implement this method. The following o
156
156
157
157
### on(event, cb) method (required)
158
158
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.
0 commit comments