Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

NoSQL object-relational mapping for JSON:API resource objects decorated with `@tsmetadata/json-api`.

License

NotificationsYou must be signed in to change notification settings

tsmetadata/json-api-orm

Repository files navigation

@tsmetadata/json-api-orm provides a NoSQL object-relational mapping for JSON:API resource objects decorated with@tsmetadata/json-api.

🌱 Install

npm install @tsmetadata/json-api-orm@latest

🤖 Supported Drivers

  • 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.

📋 Feature Set

⚙️ Usage

Actions

Get

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)}

Put

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);

Include

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);

❓ FAQ

Q: Where can I learn more about JSON:API metadata decorators?

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

Stars

Watchers

Forks


[8]ページ先頭

©2009-2025 Movatter.jp