Define your schema, write functions, and subscribe to data. SDKs for Vue, Svelte, and vanilla JS.
export default defineSchema({
posts: {
id: text().primaryKey(),
title: text().notNull(),
content: text(),
author: text().notNull(),
},
});export const list = query({
args: z.object({
limit: z.number().optional()
}),
handler: async ({ args, db }) => {
return db.posts.findMany({
limit: args.limit ?? 20,
});
},
});const { data: posts } = useQuery(
'posts.list',
{ limit: 5 }
);
// posts updates automatically when
// data changes on the server