- Notifications
You must be signed in to change notification settings - Fork0
NoSQL object-relational mapping for JSON:API resource objects decorated with `@tsmetadata/json-api`.
License
tsmetadata/json-api-orm
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
@tsmetadata/json-api-orm provides a NoSQL object-relational mapping for JSON:API resource objects decorated with@tsmetadata/json-api.
npm install @tsmetadata/json-api-orm@latest
- DynamoDB (via.AWS SDK for JavaScript v3)
- To authenticate, please configure the global AWS SDK object or use environment variables.
- Table names match, by default, the resource type.
Theget(cls: new (..._: any[]) => any), id: string) action will get the resource with the given class and id from the underlying database.
import{Resource,Id,Attribute}from'@tsmetadata/json-api';import{get}from'@tsmetadata/json-api-orm';@Resource('users')classUser{ @Id()customerId:string; @Attribute()active:boolean;}constuser1=awaitget(User,1);if(user1!==undefined){console.log(user1.active)}
Theput(classInstance: object) action will put (create or update) the resource from the given class instance.
import{Resource,Id,Attribute}from'@tsmetadata/json-api';import{put}from'@tsmetadata/json-api-orm';@Resource('users')classUser{ @Id()customerId:string; @Attribute()active:boolean;}constuser=newUser();user.id='1';user.active=false;awaitput(user);
Theinclude(classInstance: object, relationshipKey: string, cls: new (..._: any[]) => any) will get the full resource(s) for the given relationship.
import{Resource,Id,Attribute,Relationship,typeJSONAPIResourceLinkage}from'@tsmetadata/json-api';import{include}from'@tsmetadata/json-api-orm';@Resource('users')classUser{ @Id()customerId:string; @Attribute()active:boolean; @Relationship('author')posts:Post[]|JSONAPIResourceLinkage;}@Resource('posts')classPost{ @Id()postId:string; @Attribute()description:string; @Relationship('posts')author:User|JSONAPIResourceLinkage;}constuser=awaitget(User,'1');/* user.posts is an array of `JSONAPIResourceIdentifierObject`. To turn this into an array of `Post`, we can do the following:*/awaitinclude(User,'posts',Post);
A: We have a standard library complete with serializers, deserializers, and all object typeshere.
About
NoSQL object-relational mapping for JSON:API resource objects decorated with `@tsmetadata/json-api`.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.