Skip to main content

get

The get method is used to retrieve stored data according to a Key.

async function get(key: string): Promise<Entry<T>>;

Reference

Overview

You can use the get method to retrieve data stored in the Database Element.

import { User } from "#elements";

...

await User.get("user-1");
...

Parameters

  • key: A unique identifier corresponding to the data.

Returns

The return value is a data object formed by merging the fields defined in the Database Element and the key.

Caveats

  • The data returned by calling get filters out fields not defined in the Database Element. If you need the originally stored data, use getAsAny.

Examples

get data from Database Element

The User Database Element defines two fields, name and actived. Here's an example of using the Database Element in a Function Element.

import { User } from "#elements";

export default async function () {
return await User.get("user-1")
}

return value:

{
"key": "user-1",
"name": "user-1",
"actived": true
}