Wetland is a modern object-relational mapper (ORM) for node.js.
It allows you to get started quickly, without losing flexibility or features.
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.
Features
Some of the major features provided include:
- Unit of work
- Derived tables
- Migrations
- Transactions
- Entity manager
- Cascaded persists
- Deep joins
- Repositories
- QueryBuilder
- Entity mapping
- Optimized state manager
- Recipe based hydration
- More...
Installation
To install wetland run the following command:
npm i --save wetland
Typings are provided by default for TypeScript users. No additional typings need installing.
Plugins / essentials
Compatibility
- All operating systems
- Node.js 6.0+
Gotchas
- When using sqlite3, foreign keys are disabled (this is due to alter table not working for foreign keys with sqlite).
Usage
The following is a snippet to give you an idea what it's like to work with wetland.
For a much more detailed explanation, head to the documentation..
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]
});
let migrator = wetland.getMigrator().create();
migrator.apply().then(() => {});
let manager = wetland.getManager();
let repository = manager.getRepository(Foo);
repository.find({name: 'cake'}, {joins: ['candles', 'baker', 'baker.address']})
.then(results => {
});
Entity example
Javascript
const { UserRepository } = require('../repository/UserRepository');
class User {
static setMapping(mapping) {
mapping.autoFields();
mapping.entity({ repository: UserRepository })
mapping.field('dateOfBirth', { type: 'datetime' });
}
}
module.exports.User = User;
Typescript
import { entity, autoFields, field } from 'wetland';
import { UserRepository } from '../repository/UserRepository';
@entity({ repository: UserRepository })
@autoFields()
export class User {
@field({ type: 'datetime' })
public dateOfBirth: Date;
}
License
MIT