Query

Use the query module to get content out of the database. It takes an object of type Record<string, string> where each key corresponds to a column name in the database, and the value corresponds to a database column value.

Say you've a structure like:

import { defineBlock, defineBlockField, defineField, defineStructure } from '@alstar/studio'

const structure = defineStructure({
  page: defineBlock({
    label: 'Pages',
    type: 'page',
    fields: {
      title: defineField({
        label: 'Title',
        type: 'text',
      }),
      slug: defineField({
        label: 'Slug',
        type: 'slug',
      }),
    },
  }),
} as const)

export default structure

Then you can query any page by running:

// ./pages/[slug].ts
import { defineEntry, html, query } from '@alstar/studio'

export default defineEntry(c => {
  const slug = c.req.param('slug')

  const content = query.root({
    name: 'slug', // name of the field
    value: slug,  // value of the field
  })

  return html`
    <h1>Hello!</h1>
    <pre><code>${JSON.stringify(content, null, 2)}</code></pre>
  `)
})