seegno / Objection Unique
Unique validation for Objection.js
Stars: ✭ 42
Programming Languages
javascript
184084 projects - #8 most used programming language
Projects that are alternatives of or similar to Objection Unique
Validate
This package provides a framework for writing validations for Go applications.
Stars: ✭ 57 (+35.71%)
Mutual labels: validation, models
Hisocket
It is a lightweight client socket solution, you can used it in C# project or Unity3d
Stars: ✭ 275 (+554.76%)
Mutual labels: plugin, plugins
Vue Rawmodel
RawModel.js plugin for Vue.js v2. Form validation has never been easier!
Stars: ✭ 79 (+88.1%)
Mutual labels: validation, plugin
Betterdiscordapp
Better Discord App enhances Discord desktop app with new features.
Stars: ✭ 1,225 (+2816.67%)
Mutual labels: plugin, plugins
Bitsofbytes
Code and projects from my blog posts.
Stars: ✭ 89 (+111.9%)
Mutual labels: plugin, plugins
apple-receipt
Apple InAppPurchase Receipt - Models, Parser, Validator
Stars: ✭ 25 (-40.48%)
Mutual labels: validation, models
Node Audio
Graph-based audio api for Node.js based on LabSound and JUCE
Stars: ✭ 67 (+59.52%)
Mutual labels: plugin, plugins
Unitypluginwithwsl
Unity native plugin with WSL (Windows Subsystem for Linux)
Stars: ✭ 39 (-7.14%)
Mutual labels: plugin, plugins
Keepass Yet Another Favicon Downloader
Yet Another Favicon Downloader for KeePass 2.x
Stars: ✭ 354 (+742.86%)
Mutual labels: plugin, plugins
React Native Make
A collection of everyday React Native CLI tools
Stars: ✭ 606 (+1342.86%)
Mutual labels: plugin, plugins
Wordpress Plugin Installer
A PHP class for installing and activating WordPress plugins.
Stars: ✭ 69 (+64.29%)
Mutual labels: plugin, plugins
Glean
hotfix for go applications via plugin, supports Linux and MacOS
Stars: ✭ 125 (+197.62%)
Mutual labels: plugin, plugins
Base
Base is the foundation for creating modular, unit testable and highly pluggable, server-side node.js applications.
Stars: ✭ 67 (+59.52%)
Mutual labels: plugin, plugins
Ymate Platform V2
YMP是一个非常简单、易用的轻量级Java应用开发框架,涵盖AOP、IoC、WebMVC、ORM、Validation、Plugin、Serv、Cache等特性,让开发工作像搭积木一样轻松!
Stars: ✭ 106 (+152.38%)
Mutual labels: validation, plugin
Validate
A simple jQuery plugin to validate forms.
Stars: ✭ 298 (+609.52%)
Mutual labels: validation, plugin
Fluent Bit Go Loki
[Deprecated] The predessor of fluent-bit output plugin for Loki. https://github.com/grafana/loki
Stars: ✭ 38 (-9.52%)
Mutual labels: plugin
Unique validation for Objection.js
This plugin adds a unique validation for Objection.js models.
NOTE: Unique validation at update only works with $query
methods.
Installation
NPM
npm i objection-unique --save
Yarn
yarn add objection-unique
Usage
Mixin the plugin
// Import objection model.
const Model = require('objection').Model;
// Import the plugin.
const unique = require('objection-unique')({
fields: ['email', 'username', ['phone_prefix','phone_number']],
identifiers: ['id']
});
// Mixin the plugin.
class User extends unique(Model) {
static get tableName() {
return 'User';
}
}
Validate insert
/**
* Insert.
*/
// Insert one user.
await User.query().insert({ email: 'foo', username: 'bar' });
try {
// Try to insert another user with the same data.
await User.query().insert({ email: 'foo', username: 'bar' });
} catch (e) {
// Exception with the invalid unique fields
//
// {
// email: [{
// keyword: 'unique',
// message: 'email already in use.'
// }],
// username: [{
// keyword: 'unique',
// message: 'username already in use.'
// }
// }
}
Validate update/patch
/**
* Update/Patch.
*/
// Insert one user.
await User.query().insert({ email: 'foo', username: 'bar' });
// Insert the user that we want to update.
const user = await User.query().insertAndFetch({ email: 'biz', username: 'buz' });
try {
user.$query().update({ email: 'foo', username: 'buz' });
// user.$query().patch({ email: 'foo' });
} catch (e) {
// Exception with the invalid unique fields
//
// {
// email: [{
// keyword: 'unique',
// message: 'email already in use.'
// }]
// }
}
Options
fields: The unique fields. Compound fields can be specified as an array
identifiers: The fields that identifies the model. (Default: ['id'])
These options can be provided when instantiating the plugin:
const unique = require('objection-unique')({
fields: ['email', 'username', ['phone_prefix', 'phone_number']],
identifiers: ['id']
});
Tests
Run the tests from the root directory:
npm test
Contributing & Development
Contributing
Found a bug or want to suggest something? Take a look first on the current and closed issues. If it is something new, please submit an issue.
Develop
It will be awesome if you can help us evolve objection-unique
. Want to help?
- Fork it.
-
npm install
. - Hack away.
- Run the tests:
npm test
. - Create a Pull Request.
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].