Skip to content

simple-orm/find-by-primary-key

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Find By Primary Key

This is a plugin for the simple ORM library that allows you to easily add in support for using just the primary key with the repository's find() method. This plugin only works with repository referencing a model that has a single primary key value.

Documentation

Generally, if you want to find a model by the primary key with the simple ORM library, you should have to do this:

var model = yield dataLayer.user.find({
  where: {s
    id: 123
  }
});

First issue that that it is a bit to type. Also if the primary key changes, you have you change your code besides in your model definition. This plugin allows you to do this:

var model = yield dataLayer.user.find(123);

This code is much more concise and wil automatically use the correct field based on the model configuration.

To enable this plugin for a repository, all you have to do is after creating the repository model, add this line:

userRepository.plugin(require('simple-orm-find-by-primary-key'));

License

MIT

About

Plugin that adds support for using the repository's find method with just passing the primary key value

Resources

License

Stars

Watchers

Forks

Packages

No packages published