orm-adapter
An npm package that adapts other orms into a decorator based orm. Currently supports:
DynamoDB
1-Js-data
2-BookShelf
3-Mongoose
4-Custom
5-Supported API fields:
1- @Entity() or @Entity(OrmType.<Select_Orm>, OrmConfig): Creates the database model using the defined Orm or in case of passing the parameters it will used the configurations passed.
2- @column() or @column(params): Creates a column in the model. The params are optional and the can veary depending on the orm used.
3- @id: Creates a column as well as identifies as id for quiries and updates.
4- @key: Creates a column as well as identifies as secondary id for quiries and updates.
5- @hasMany: creates a one to many relationship. Will be fully functional next release.
6- @belongsTo: creates a one to one relationship. Will be fully functional next release.
7- @beforeCreate: runs function before saving model to database.
8- @afterCreate: runs function after saving model to database.
9- @beforeUpdate: runs function before updating model in the database.
10- @afterUpdate: runs function after updating model in the database.
11- @beforeDelete: runs function before deleting model in the database.
12- @afterDelete: runs function after deleting model in the database.
Creating models:
;@ @ username: string; @ firstName: string; @ lastName: string; @ email: string;
That will simply create a user model using any orm or custom database connector and connection.
You can also create different models using different orms:
User.ts
;@ @ username: string; @ firstName: string; @ lastName: string; @ email: string;
Nerd.ts
;;;@ @ realName: string; @ alterEgo: string; @ cursh: string;
User will be created using the global orm and Nerd will be created using js-data.
Life hooks Support?:
; @ @ realName: string; @ alterEgo: string; @ cursh: string; // lets help our friend out. @ { // Do some real work then joke a little: console; } @ { // Do real job with the data. console; } @ { // Do some real work then joke a little: console } @ { // Do real job with the data. console; } @ { // Do some real work then joke a little: console; } @ { // Do real job with the data. console; }
The api also supports multiple helpful properties:
; @ @ username: string; @ firstName: string; @ lastName: string; @ email: string; @ deepSecret: string; @ password: string; @ friends: Friend; @ bestFriend: Friend;
API usage:
; // Getting all users. // Getting a user by id = 11. // Getting a user by a param: firstName = 'sal'. // Save a user.