Skip to content

Commit cead45e

Browse files
committed
remove duplicated docs
1 parent 7254df5 commit cead45e

File tree

1 file changed

+0
-53
lines changed

1 file changed

+0
-53
lines changed

documentation/docs/20-core-concepts/60-remote-functions.md

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -225,59 +225,6 @@ export const getWeather = query.batch(v.string(), async (cities) => {
225225
{/if}
226226
```
227227
228-
## query.batch
229-
230-
`query.batch` works like `query` except that it batches requests that happen within the same macrotask. This solves the so-called n+1 problem: rather than each query resulting in a separate database call (for example), simultaneous queries are grouped together.
231-
232-
On the server, the callback receives an array of the arguments the function was called with. It must return a function of the form `(input: Input, index: number) => Output`. SvelteKit will then call this with each of the input arguments to resolve the individual calls with their results.
233-
234-
```js
235-
/// file: weather.remote.js
236-
// @filename: ambient.d.ts
237-
declare module '$lib/server/database' {
238-
export function sql(strings: TemplateStringsArray, ...values: any[]): Promise<any[]>;
239-
}
240-
// @filename: index.js
241-
// ---cut---
242-
import * as v from 'valibot';
243-
import { query } from '$app/server';
244-
import * as db from '$lib/server/database';
245-
246-
export const getWeather = query.batch(v.string(), async (cities) => {
247-
const weather = await db.sql`
248-
SELECT * FROM weather
249-
WHERE city = ANY(${cities})
250-
`;
251-
const weatherMap = new Map(weather.map(w => [w.city, w]));
252-
253-
return (city) => weatherMap.get(city);
254-
});
255-
```
256-
257-
```svelte
258-
<!--- file: Weather.svelte --->
259-
<script>
260-
import CityWeather from './CityWeather.svelte';
261-
import { getWeather } from './weather.remote.js';
262-
263-
let { cities } = $props();
264-
let limit = $state(5);
265-
</script>
266-
267-
<h2>Weather</h2>
268-
269-
{#each cities.slice(0, limit) as city}
270-
<h3>{city.name}</h3>
271-
<CityWeather weather={await getWeather(city.id)} />
272-
{/each}
273-
274-
{#if cities.length > limit}
275-
<button onclick={() => limit += 5}>
276-
Load more
277-
</button>
278-
{/if}
279-
```
280-
281228
## query.stream
282229
283230
`query.stream` allows you to stream continuous data from the server to the client.

0 commit comments

Comments
 (0)