Wetland is a modern object-relational mapper (ORM) for node.js.
Wetland is based on the JPA-spec and therefore has some similarities to Hibernate and Doctrine. While some aspects of the ORM have been adapted to perform better in the Node.js environment and don't follow the specification to the letter for that reason, the JPA specification is a stable and well written specification that makes wetland structured and performant.
New! Take a look at our wetland tutorial.
New! Wetland CLI now has its own repository. npm i -g wetland-cli
.
New! Wetland has a nice entity generator. Let us do the heavy lifting. Repository can be found here.
The major features this ORM provides are listed below. Looking at the tests will provide more detailed information, pending full documentation.
- Unit of work
- Derived tables
- Transactions
- Entity manager
- Manager scopes
- Cascade persist
- Deep joins
- Repositories
- QueryBuilder
- Mapping
- MetaData
- Entity proxy
- Collection proxy
- Criteria parser
- More...
To install wetland run the following command:
npm i --save wetland
Typings are provided by default for TypeScript users. No additional typings need installing.
- Wetland CLI
npm i -g wetland-cli
- Express middleware
- Sails.js hook
- Trailpack
- Entity generator
Simple implementation example:
const Wetland = require('wetland').Wetland;
const Foo = require('./entity/foo').Foo;
const Bar = require('./entity/foo').Bar;
const wetland = new Wetland({
stores: {
simple: {
client : 'mysql',
connection: {
user : 'root',
database: 'testdatabase'
}
}
},
entities: [Foo, Bar]
});
// Create the tables. Async process, only here as example.
// use .getSQL() (not async) in stead of apply (async) to get the queries.
let migrator = wetland.getMigrator().create();
migrator.apply().then(() => {});
// Get a manager scope. Call this method for every context (e.g. requests).
let manager = wetland.getManager();
// Get the repository for Foo
let repository = manager.getRepository(Foo);
// Get some results, and join.
repository.find({name: 'cake'}, {populate: ['candles', 'baker', 'baker.address']})
.then(results => {
// ...
});
MIT