-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathposts.ts
More file actions
35 lines (34 loc) · 950 Bytes
/
posts.ts
File metadata and controls
35 lines (34 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { builder } from '../helper'
export const postsCollection = builder.collection('posts', {
slug: 'posts',
identifierColumn: 'id',
fields: builder.fields('posts', (fb) => ({
id: fb.columns('id', {
type: 'text',
}),
title: fb.columns('title', {
type: 'text',
}),
content: fb.columns('content', {
type: 'text',
}),
authorId: fb.relations('author', (fb) => ({
type: 'connect',
fields: fb.fields('user', (fb) => ({
id: fb.columns('id', {
type: 'text',
}),
name: fb.columns('name', {
type: 'text',
}),
email: fb.columns('email', {
type: 'text',
}),
})),
options: builder.options(async ({ db }) => {
const result = await db.query.user.findMany({ columns: { id: true, name: true } })
return result.map((user) => ({ label: user.name, value: user.id }))
}),
})),
})),
})