Skip to content

Commit 89b0959

Browse files
committed
Improve documentation
1 parent 1124634 commit 89b0959

File tree

2 files changed

+58
-58
lines changed

2 files changed

+58
-58
lines changed

README.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ See [database-js](https://github.com/mlaanderson/database-js) for the full list
3939

4040
## Configure
4141

42-
### Configuration in CodeceptJS
43-
44-
In your `codecept.json`, include **DbHelper** in the property **helpers** :
42+
In your CodeceptJS configuration file (e.g., `codecept.conf.js`, `codecept.json`), include **DbHelper** in the property **helpers** :
4543

4644
```js
4745
...
@@ -59,7 +57,7 @@ In your `codecept.json`, include **DbHelper** in the property **helpers** :
5957

6058
### Syntax differences between CodeceptJS 2 and CodeceptJS 3
6159

62-
In CodeceptJS 2, your callbacks receive an `I` argument:
60+
In CodeceptJS 2, your callbacks receive `I` as argument:
6361

6462
```javascript
6563
Scenario('test something', async ( I ) => { // CodeceptJS 2 notation
@@ -81,24 +79,26 @@ See the [CodeceptJS docs](https://github.com/codeceptjs/CodeceptJS/wiki/Upgradin
8179

8280
> The following examples are written with **CodeceptJS 3**.
8381
84-
The object `I` of your tests and events now has to the [methods described in the API](#api).
82+
Now the object `I` (of your callbacks) has [new methods](#api).
8583

8684
#### Example 1
8785

8886
```js
8987
BeforeSuite( async( { I } ) => {
90-
// The first parameter is the key that will hold a reference to the db
88+
// Connects to a database
89+
// The first parameter is the key that will hold a reference to the database
9190
I.connect( "testdb", "mysql://root:mypassword@localhost:3306/testdb" );
9291
} );
9392

9493
AfterSuite( async( { I } ) => {
95-
await I.removeConnection( "testdb" ); // also disconnects
94+
// Disconnects and removes the reference to the database
95+
await I.removeConnection( "testdb" );
9696
} );
9797

9898

9999
Before( async( { I } ) => {
100100

101-
// Deleting all the records from the table 'user'
101+
// Deletes all the records from the table 'user'
102102
await I.run( "testdb", "DELETE FROM user" );
103103

104104
// Inserting some users
@@ -121,12 +121,12 @@ Feature( 'Foo' );
121121
Scenario( 'Bar', async( { I } ) => {
122122

123123
// Queries a user from the database
124-
const results = await I.query( "testdb", "SELECT * FROM user WHERE username = ?", "bob" );
125-
const bob = results[ 0 ];
124+
const results = await I.query( "testdb", "SELECT username, password FROM user WHERE username = ?", "bob" );
125+
const user = results[ 0 ]; // object in the first row
126126

127127
I.amOnPage( '/login' );
128-
I.fillField( '#username', bob.username );
129-
I.fillField( '#password', bob.password );
128+
I.fillField( '#username', user.username ); // bob
129+
I.fillField( '#password', user.password ); // 654321
130130
I.click( '#ok' );
131131
I.see( 'Welcome' );
132132
} );
@@ -137,47 +137,47 @@ Scenario( 'Bar', async( { I } ) => {
137137

138138
```js
139139
/**
140-
* Connects to a database by the given connection data.
140+
* Connects to the database described by the given connection string.
141141
*
142-
* @param {string|number} key Key used to identify the database
143-
* @param {string|object} conn JDBC-like connection string or a connection object accepted by `database-js`.
144-
* @param {object|undefined} driver Driver object, used by `database-js` (optional).
142+
* @param {string|number} key Identification for using in other commands.
143+
* @param {string|object} conn JDBC-like connection string or a connection object accepted by `database-js`.
144+
* @param {object|undefined} driver [OPTIONAL] Driver object, used by `database-js`.
145145
*/
146146
connect( key, conn, driver );
147147

148148
/**
149-
* Disconnects from a given database by its key.
149+
* Disconnects from the database identified by the given key.
150150
*
151-
* @param {string|number} key Key used to identify the database
151+
* @param {string|number} key Database identification key set in connect()
152152
*/
153153
async disconnect( key );
154154

155155
/**
156-
* Disconnects and removes a database connection by its key.
156+
* Disconnects and removes the database connection identified by the given key.
157157
*
158-
* @param {string|number} key Key used to identify the database
158+
* @param {string|number} key Database identification key set in connect()
159159
*/
160160
async removeConnection( key );
161161

162162
/**
163-
* Queries a database with the given key.
163+
* Performs a query.
164164
*
165-
* @param {string|number} key Key used to identify the database
166-
* @param {string} command Query
167-
* @param {any[]} params Parameters of the query
165+
* @param {string|number} key Database identification key set in connect()
166+
* @param {string} command Query to run.
167+
* @param {any[]} params [OPTIONAL] Query parameters
168168
*
169-
* @returns {Promise<any[]>} The results of the query.
169+
* @returns {Promise<any[]>} Query results.
170170
*/
171171
async query( key, command, ... params );
172172

173173
/**
174-
* Executes a command to the database with the given key.
174+
* Executes a command.
175175
*
176-
* @param {string|number} key Key used to identify the database
177-
* @param {string} command Command to execute
178-
* @param {any[]} params Parameters of the command
176+
* @param {string|number} key Database identification key set in connect()
177+
* @param {string} command Command to run.
178+
* @param {any[]} params [OPTIONAL] Command parameters
179179
*
180-
* @returns {Promise<any[]>}
180+
* @returns {Promise<any[]>} Command results.
181181
*/
182182
async run( key, command, ... params );
183183
```

index.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
let dbjs = require('database-js');
22

33
/**
4-
* Database helper
4+
* Database helper for CodeceptJS
55
*
66
* @author Thiago Delgado Pinto
77
*/
@@ -10,7 +10,7 @@ class DbHelper extends Helper {
1010
/**
1111
* Constructor
1212
*
13-
* @param {object} config Configuration declared in the CodeceptJS configuration file.
13+
* @param {object} config CodeceptJS configuration
1414
*/
1515
constructor( config ) {
1616
super( config );
@@ -21,20 +21,20 @@ class DbHelper extends Helper {
2121
}
2222

2323
/**
24-
* Connects to a database by the given connection data.
24+
* Connects to the database described by the given connection string.
2525
*
26-
* @param {string|number} key Key used to identify the database
27-
* @param {string|object} conn JDBC-like connection string or a connection object accepted by `database-js`.
28-
* @param {object|undefined} driver Driver object, used by `database-js` (optional).
26+
* @param {string|number} key Identification for using in other commands.
27+
* @param {string|object} conn JDBC-like connection string or a connection object accepted by `database-js`.
28+
* @param {object|undefined} driver [OPTIONAL] Driver object, used by `database-js`.
2929
*/
3030
connect( key, conn, driver ) {
3131
return this.connectionMap[ key ] = this.createConnection( conn, driver );
3232
}
3333

3434
/**
35-
* Disconnects from a given database by its key.
35+
* Disconnects from the database identified by the given key.
3636
*
37-
* @param {string|number} key Key used to identify the database
37+
* @param {string|number} key Database identification key set in connect()
3838
*/
3939
async disconnect( key ) {
4040
let conn = this.connectionMap[ key ];
@@ -45,9 +45,9 @@ class DbHelper extends Helper {
4545
}
4646

4747
/**
48-
* Disconnects and removes a database connection by its key.
48+
* Disconnects and removes the database connection identified by the given key.
4949
*
50-
* @param {string|number} key Key used to identify the database
50+
* @param {string|number} key Database identification key set in connect()
5151
*/
5252
async removeConnection( key ) {
5353
if ( ! this.connectionMap[ key ] ) {
@@ -64,13 +64,13 @@ class DbHelper extends Helper {
6464
}
6565

6666
/**
67-
* Queries a database with the given key.
67+
* Performs a query.
6868
*
69-
* @param {string|number} key Key used to identify the database
70-
* @param {string} command Query
71-
* @param {any[]} params Parameters of the query
69+
* @param {string|number} key Database identification key set in connect()
70+
* @param {string} command Query to run.
71+
* @param {any[]} params [OPTIONAL] Query parameters
7272
*
73-
* @returns {Promise<any[]>} The results of the query.
73+
* @returns {Promise<any[]>} Query results.
7474
*/
7575
async query( key, command, ... params ) {
7676
let conn = this.connectionMap[ key ];
@@ -85,13 +85,13 @@ class DbHelper extends Helper {
8585
}
8686

8787
/**
88-
* Executes a command to the database with the given key.
88+
* Executes a command.
8989
*
90-
* @param {string|number} key Key used to identify the database
91-
* @param {string} command Command to execute
92-
* @param {any[]} params Parameters of the command
90+
* @param {string|number} key Database identification key set in connect()
91+
* @param {string} command Command to run.
92+
* @param {any[]} params [OPTIONAL] Command parameters
9393
*
94-
* @returns {Promise<any[]>}
94+
* @returns {Promise<any[]>} Command results.
9595
*/
9696
async run( key, command, ... params ) {
9797
let conn = this.connectionMap[ key ];
@@ -108,35 +108,35 @@ class DbHelper extends Helper {
108108
/**
109109
* Creates a database connection.
110110
*
111-
* @param {string|object} conn JDBC-like connection string or a connection object accepted by `database-js`.
112-
* @param {object|undefined} driver Driver object, used by `database-js` (optional).
111+
* @param {string|object} conn JDBC-like connection string or a connection object accepted by `database-js`.
112+
* @param {object|undefined} driver [OPTIONAL] Driver object, used by `database-js`.
113113
*/
114114
createConnection( conn, driver ) {
115115
return new dbjs.Connection( conn, driver );
116116
}
117117

118118
/**
119-
* Checks whether there is a database with the given key.
119+
* Checks if there is a database connection with the given key.
120120
*
121-
* @param {string|number} key Key used to identify the database
121+
* @param {string|number} key Database identification key set in connect()
122122
*/
123123
hasConnection( key ) {
124124
return !! this.connectionMap[ key ];
125125
}
126126

127127
/**
128-
* Get the database connection with the given key.
128+
* Gets the database connection with the given key.
129129
*
130-
* @param {string|number} key Key used to identify the database
130+
* @param {string|number} key Database identification key set in connect()
131131
*/
132132
getConnection( key ) {
133133
return this.connectionMap[ key ];
134134
}
135135

136136
/**
137-
* Creates an error related to the case when the given key is not found.
137+
* Creates an error that represents a database not found.
138138
*
139-
* @param {string|number} key Key used to identify the database
139+
* @param {string|number} key Database identification key
140140
*/
141141
_keyNotFoundError( key ) {
142142
return new Error( 'Database not found with the key ' + key );

0 commit comments

Comments
 (0)