Changelog
[0.27.22] 2024-11-08
Improved support for sveltekit ssr. To configure:
To enable remult across all sveltekit route
// src/hooks.server.ts
import { api } from './server/api'
export const handle = api
To Use remult in ssr PageLoad
- this will leverage the event
's fetch to load data on the server without reloading it on the frontend, and abiding to all api rules even when it runs on the server
// src/routes/+page.ts
import { remult } from 'remult'
import type { PageLoad } from './$types'
export const load = (async (event) => {
// Instruct remult to use the special svelte fetch to fetch data on server side page load
remult.useFetch(event.fetch)
return repo(Task).find()
}) satisfies PageLoad
Changelog
[0.27.21] 2024-10-28
Added upsert
method:
The upsert
method allows inserting or updating an entity in a single operation. If an entity matching the where
condition is found, it is updated; otherwise, a new entity is created. This can be used for a single entity or for batch operations with an array of options.
Example:
// Single entity upsert
await taskRepo.upsert({
where: { title: 'task a' },
set: { completed: true },
})
// Batch upsert
await taskRepo.upsert([
{ where: { title: 'task a' }, set: { completed: true } },
{ where: { title: 'task b' }, set: { completed: true } },
])
Now you can get data and aggregate info with a single request using the query
method:
const result = await repo
.query({
where: { completed: false },
pageSize: 50,
aggregates: {
sum: ['salary'],
average: ['age'],
},
})
.paginator()
// Accessing the items from the first page
console.table(result.items)
// Accessing the aggregation results
console.log(result.aggregates.salary.sum) // Total salary sum
Added TestApiDataProvider
to use in unit tests that test api rules. see tutorial
Fixed that values that are not included will not exist in the resulting object (previously they existed with value undefined)
Fixed that relations that were not included, will not be enumerable in the resulting object (previously they were only set to undefined)
Fixed serverExpression
to run whenever we're not using a proxy
data provider (for example RestDataProvider)
Fixed issue with updateMany
where the set
had ValueListType
or relation.
Fixed issue when updating relation id and relation in the same update, the last one will win
Fixed makeTitle to handle all caps text
Added experimental api for sqlRelations & sqlRelationsFilter - see Sql Relations