mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
docs: Document data.readOneBy method with usage examples
This commit is contained in:
@@ -137,6 +137,35 @@ To retrieve a single record from an entity, use the `readOne` method:
|
|||||||
const { data } = await api.data.readOne("posts", 1);
|
const { data } = await api.data.readOne("posts", 1);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `data.readOneBy([entity], [query])`
|
||||||
|
|
||||||
|
To retrieve a single record from an entity using a query (e.g., by a specific field value) instead of an ID, use the `readOneBy` method:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const { data } = await api.data.readOneBy("posts", {
|
||||||
|
where: {
|
||||||
|
slug: "hello-world",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
This is useful when you want to find a record by a unique field other than the primary key. You can also use `select`, `with`, and `join` options:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const { data } = await api.data.readOneBy("users", {
|
||||||
|
select: ["id", "email", "name"],
|
||||||
|
where: {
|
||||||
|
email: "user@example.com",
|
||||||
|
},
|
||||||
|
with: {
|
||||||
|
posts: {
|
||||||
|
limit: 5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
join: ["profile"],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
### `data.createOne([entity], [data])`
|
### `data.createOne([entity], [data])`
|
||||||
|
|
||||||
To create a single record of an entity, use the `createOne` method:
|
To create a single record of an entity, use the `createOne` method:
|
||||||
|
|||||||
Reference in New Issue
Block a user