Users: getContent()
ユーザが持つコンテンツを取得します。
この関数は非同期関数です。
構文
Users.getContent(userId) => Promise<(any | undefined)>
Users.getContent(userId, options) => Promise<(any | undefined)>
引数
-
userId
:string
ユーザの識別子です。
-
options
:{ [tableName][, projection] }?
オプション引数です。
-
tableName
:string?
registerTable()
で登録されたテーブル名です。- 既定では最初に登録されたテーブルが使用されます。
-
projection
:{ [key: string]: boolean | object }?
取得したいコンテンツを指定するためのマッピングです。
- 既定ではすべてのコンテンツが取得されます。
-
返値: Promise<(any | undefined)>
取得したコンテンツまたは undefined
のプロミスです。
解説
コンテンツは任意の型の値またはオブジェクトリテラルです。
コンテンツがオブジェクトリテラルの場合、projection
で特定のコンテンツのみを抽出することができます。projection
で値が ture
となっているキーと同じコンテンツを抽出します。
await Users.signup("user", { content: { password: "foo", secret: "bar" }});
const password = await Users.getContent("user", { projection: { secret: true }});
// => "bar"
projection
のキーが異なる場合は undefined
となります。