Skip to main content

query

The query method is used to find data in the Database Element that meets certain conditions based on field values.

async function query(queryobj: Partial<T>): Promise<Array<Entry<T>>>;

Reference

Overview

You can use query to find a specific set of data according to field values.

import { User } from "#elements";

...

await User.query({
actived: true
});
...

Returns

The return value is an array of data objects formed by merging the fields defined in the Database Element and the key. The corresponding fields in the data in this array will be equal to all the fields passed in the queryObj.

Caveats

  • The data returned by calling query filters out fields not defined in the Database Element.

Examples

get data from Database Element filter by value field

The User Database Element defines two fields, name and actived. Here's an example of finding all elements with actived equals true in a Function Element.

import { User } from "#elements";

export default async function () {
return await User.query({
actived: true
});
}

return value:

[
{
"key": "David",
"name": "David",
"actived": true
},
{
"key": "test1",
"name": "test1",
"actived": true
}
]