Skip to content

Commit

Permalink
fetching strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
lroal committed Mar 23, 2024
1 parent 841a9f0 commit e2c9712
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,49 @@ async function updateRows() {
```
</details>
<details id="fetching-strategies"><summary><strong>Fetching strategies</strong></summary>
<p>Efficient data retrieval is crucial for the performance and scalability of applications. The fetching strategy gives you the freedom to decide how much related data you want to pull along with your primary request. Below are examples of common fetching strategies, including fetching entire relations and subsets of columns. When no fetching strategy is present, it will fetch all columns without its relations.<p>
__Including a relation__
This example fetches orders and their corresponding delivery addresses, including all columns from both entities.
```javascript
import map from './map';
const db = map.sqlite('demo.db');

getRows();

async function getRows() {
const rows = await db.order.getAll({
deliveryAddress: true
});
}
```
__Including a subset of columns__
In scenarios where only specific fields are required, you can specify a subset of columns to include. In the example below, orderDate is explicitly excluded, so all other columns in the order table are included by default. For the deliveryAddress relation, only countryCode and name are included, excluding all other columns. If you have a mix of explicitly included and excluded columns, all other columns will be excluded from that table.
```javascript
import map from './map';
const db = map.sqlite('demo.db');

getRows();

async function getRows() {
const rows = await db.order.getAll({
orderDate: false,
deliveryAddress: {
countryCode: true,
name: true
}
});
}
```
</details>
<details id="basic-filters"><summary><strong>Basic filters</strong></summary>
<p>Filters are a versatile tool for both data retrieval and bulk deletions. They allow for precise targeting of records based on specific criteria and can be combined with operators like <i>any</i> and <i>exists</i> and even raw sql for more nuanced control. Filters can also be nested to any depth, enabling complex queries that can efficiently manage and manipulate large datasets. This dual functionality enhances database management by ensuring data relevance and optimizing performance.</p>
Expand Down

0 comments on commit e2c9712

Please sign in to comment.