Junction guide / Services
A service
A service is a named set of methods the API answers. Over a model, createService generates find, get, create, patch and remove from the schema, so a service file can be one line.
import { createClient } from '@frontierjs/litestone'
const db = await createClient({ db: ':memory:', schema: 'model Post { id Int @id title String @length(1, 200) }' })
const app = createApp({ db })
app.services.register(createService({ name: 'posts' }))
const post = await app.service('posts').create({ title: 'Hello' })
const page = await app.service('posts').find({})
if (page.data.length !== 1 || page.data[0].id !== post.id) throw new Error('unexpected rows')
What else it can do
model: 'Post'names the model when the service name does not resolve to it (postsfindsdb.post)schema:takes a JSON Schema and validatescreateandpatchfrom itsoftDelete: 'deletedAt'turnsremoveinto a timestamppaginate: { default, max }sets the page size offindallowBulkandbulkMaxpermit and bound a filteredpatchorremovehooks: { before, after, error }run around each methodGET,POST,PUT,PATCHandDELETEon/postsare mounted with no route writtenHEADruns theGETroute,OPTIONSanswers204, and a verb a path has no route for is405, each withAllow
In depth: README § Litestone ORM, § Methods the transport answers for you