Skip to content

Commit 8b5120b

Browse files
committed
Updated README.md and clarified comments.
1 parent 25b4c71 commit 8b5120b

3 files changed

Lines changed: 15 additions & 15 deletions

File tree

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# JoinJS
22

3-
JoinJS is a JavaScript library to map complex database joins to nested objects. It's a simpler alternative to a full-blown Object-Relation Mapper (ORM), but gives you direct control over your database interactions.
3+
JoinJS is a JavaScript library to map complex database joins to nested objects. It's a simpler alternative to a full-blown Object-Relation Mapper (ORM), and gives you direct control over your database interactions.
44

55
## Motivation
6-
ORMs generally introduce a thick layer of abstraction between objects and database tables. This usually hinders rather than helps developer productivity. In complex use cases, it is difficult enough to devise efficient queries, but with ORMs, you also have to *teach* them to generate the same query. It takes extra time to do this and you may not be able to produce the same query. In the worst case scenario, the ORM may hit the database multiple times for something that you were able to do in a single query.
6+
ORMs generally introduce a thick layer of abstraction between objects and database tables. This usually hinders, rather than helps, developer productivity. In complex use cases, it is difficult enough to devise efficient queries, but with ORMs you also have to *teach* them to generate the same query. It takes extra time to do this and you may not be able to produce the same query. In the worst case scenario, the ORM may hit the database multiple times for something that you were able to do in a single query.
77

8-
JoinJS takes a much simple and straightforward approach inspired by a Java library called [MyBatis](http://mybatis.github.io/mybatis-3/). You can use any database driver or query builder (such as [Kenx.js](http://knexjs.org/)) to query your database, however you use JoinJS to convert the returned results to a hierarchy of nested objects.
8+
JoinJS takes a much simpler and straightforward approach inspired by a Java library called [MyBatis](http://mybatis.github.io/mybatis-3/). You can use any database driver or query builder (such as [Knex.js](http://knexjs.org/)) to query your database, however you use JoinJS to convert the returned results to a hierarchy of nested objects.
99

1010
## Example
1111
Suppose you have a one-to-many relationship between a `Team` and its `Players`. You want to retrieve all teams along with their players. Here's the query for to do this:
@@ -48,8 +48,8 @@ You can use JoinJS to convert this result set in to an array of teams with neste
4848
id: 2,
4949
name: 'New York Jets'
5050
players: [
51-
{ id: 1, name: 'Tom Brady' },
52-
{ id: 2, name: 'Rob Gronkowski' }
51+
{ id: 3, name: 'Geno Smith' },
52+
{ id: 4, name: 'Darrelle Revis' }
5353
]
5454
}
5555
]
@@ -96,11 +96,11 @@ $ npm install join-js
9696
## Documentation
9797

9898
### ResultMap
99-
ResulpMaps are used to teach JoinJS how to map database results to objects. Each result map focuses on a single object. The properties of a ResultMap are described below. You can find several examples in the [test suite](https://github.com/archfirst/joinjs/tree/master/test).
99+
ResultMaps are used to teach JoinJS how to map database results to objects. Each result map focuses on a single object. The properties of a ResultMap are described below. You can find several examples in the [test suite](https://github.com/archfirst/joinjs/tree/master/test).
100100

101101
- `mapId {String}` - A unique identifier for the map
102102

103-
- `createNew {function} (optional)` - A function that returns a blank new instance of the mapped object. Use this property to construct a custom object instead of generic JavaScript `Object`.
103+
- `createNew {function} (optional)` - A function that returns a blank new instance of the mapped object. Use this property to construct a custom object instead of a generic JavaScript `Object`.
104104

105105
- `idProperty {Object} (optional)` - specifies the name of the id property in the mapped object and in the result set. Default is `{name: 'id', column: 'id'}`.
106106
- `name` - property that identifies the mapped object
@@ -112,12 +112,12 @@ ResulpMaps are used to teach JoinJS how to map database results to objects. Each
112112

113113
- `associations {Array} (optional)` - mappings for associations to other objects. Each mapping contains:
114114
- `name` - property name of the association in the mapped object
115-
- `mapId` - identifier of the map for the associated object
115+
- `mapId` - identifier of the result map of the associated object
116116
- `columnPrefix (optional)` - a prefix to apply to every column of the associated object. Default is an empty string.
117117

118118
- `collections {Array} (optional)` - mappings for collections of other objects. Each mapping contains:
119119
- `name` - property name of the collection in the mapped object
120-
- `mapId` - identifier of the map for the associated objects
120+
- `mapId` - identifier of the result map of the associated objects
121121
- `columnPrefix (optional)` - a prefix to apply to every column of the associated object. Default is an empty string.
122122

123123
### API
@@ -138,11 +138,11 @@ Returns an array of mapped objects.
138138

139139
#### mapOne(resultSet, maps, mapId, columnPrefix, isRequired)
140140

141-
This is a convenience method that maps a resultSet to a single object.
141+
This is a convenience method that maps a resultSet to a single object. It is used when your select query is expected to return only one result (e.g. `SELECT * FROM table WHERE id = 1234`).
142142

143143
- `resultSet {Array}` - an array of database results
144144
- `maps {Array}` - an array of result maps
145-
- `mapId {String}` - mapId of the top-level objects in the resultSet
145+
- `mapId {String}` - mapId of the top-level object in the resultSet
146146
- `columnPrefix {String} (optional)` - prefix that should be applied to the column names of the top-level objects
147147
- `isRequired {boolean} (optional)` - is it required to have a mapped object as a return value? Default is `true`.
148148

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "join-js",
33
"description": "A library to map complex database joins to nested objects.",
4-
"version": "0.2.0",
4+
"version": "0.3.0",
55
"author": "Naresh Bhatia",
66
"license": "MIT",
77
"homepage": "https://github.com/archfirst/joinjs",

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ function map(resultSet, maps, mapId, columnPrefix) {
3333
*
3434
* @param {Array} resultSet - an array of database results
3535
* @param {Array} maps - an array of result maps
36-
* @param {String} mapId - mapId of the top-level objects in the resultSet
37-
* @param {String} [columnPrefix] - prefix that should be applied to the column names of the top-level objects
38-
* @param {boolean} [isRequired] - is a mapped object required to be returned, default is true
36+
* @param {String} mapId - mapId of the top-level object in the resultSet
37+
* @param {String} [columnPrefix] - prefix that should be applied to the column names of the top-level object
38+
* @param {boolean} [isRequired] - is it required to have a mapped object as a return value? Default is true.
3939
* @returns {Object} one mapped object or null
4040
* @throws {NotFoundError} if object is not found and isRequired is true
4141
*/

0 commit comments

Comments
 (0)