Home / Function/ SQLQuickstarts() — supabase Function Reference

SQLQuickstarts() — supabase Function Reference

Architecture documentation for the SQLQuickstarts() function in SQLQuickstarts.tsx from the supabase codebase.

Entity Profile

Dependency Diagram

graph TD
  884e2634_f2bf_fffb_a895_7cdf4efc7426["SQLQuickstarts()"]
  2bdac7e5_a25b_6415_051d_1503de098a7f["createSqlSnippetSkeletonV2()"]
  884e2634_f2bf_fffb_a895_7cdf4efc7426 -->|calls| 2bdac7e5_a25b_6415_051d_1503de098a7f
  style 884e2634_f2bf_fffb_a895_7cdf4efc7426 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/studio/components/interfaces/SQLEditor/SQLTemplates/SQLQuickstarts.tsx lines 18–97

const SQLQuickstarts = () => {
  const router = useRouter()
  const { ref } = useParams()
  const { profile } = useProfile()
  const { data: project } = useSelectedProjectQuery()
  const { data: org } = useSelectedOrganizationQuery()
  const [, quickStart] = partition(SQL_TEMPLATES, { type: 'template' })

  const snapV2 = useSqlEditorV2StateSnapshot()

  const { can: canCreateSQLSnippet } = useAsyncCheckPermissions(
    PermissionAction.CREATE,
    'user_content',
    {
      resource: { type: 'sql', owner_id: profile?.id },
      subject: { id: profile?.id },
    }
  )

  const { mutate: sendEvent } = useSendEventMutation()

  const handleNewQuery = async (sql: string, name: string) => {
    if (!ref) return console.error('Project ref is required')
    if (!project) return console.error('Project is required')
    if (!profile) return console.error('Profile is required')

    if (!canCreateSQLSnippet) {
      return toast('Your queries will not be saved as you do not have sufficient permissions')
    }

    try {
      const snippet = createSqlSnippetSkeletonV2({
        name,
        sql,
        owner_id: profile?.id,
        project_id: project?.id,
      })
      snapV2.addSnippet({ projectRef: ref, snippet })
      snapV2.addNeedsSaving(snippet.id)

      router.push(`/project/${ref}/sql/${snippet.id}`)
    } catch (error: any) {
      toast.error(`Failed to create new query: ${error.message}`)
    }
  }

  return (
    <div className="block h-full space-y-8 overflow-y-auto p-6 px-10 bg-dash-sidebar dark:bg-surface-100">
      <div className="mb-8">
        <div className="mb-6">
          <h2 className="mb-1">Quickstarts</h2>
          <p className="text-foreground-light text-sm">
            Click on any script to fill the query box, modify the script, then click
            <span className="text-code">Run</span>.
          </p>
        </div>
        <div className="grid gap-4 sm:grid-cols-1 lg:grid-cols-2 xl:grid-cols-3">
          {quickStart.map((x, i) => (
            <ActionCard
              title={x.title}
              description={x.description}
              bgColor="bg-alternative border"
              key={`action-card-${i}`}
              icon={<SQL_ICON className={cn('fill-foreground', 'w-4 h-4')} strokeWidth={1.5} />}
              // sql={x.sql}
              onClick={() => {
                handleNewQuery(x.sql, x.title)
                sendEvent({
                  action: 'sql_editor_quickstart_clicked',
                  properties: { quickstartName: x.title },
                  groups: { project: ref ?? 'Unknown', organization: org?.slug ?? 'Unknown' },
                })
              }}
            />
          ))}
        </div>
      </div>
    </div>
  )
}

Subdomains

Frequently Asked Questions

What does SQLQuickstarts() do?
SQLQuickstarts() is a function in the supabase codebase.
What does SQLQuickstarts() call?
SQLQuickstarts() calls 1 function(s): createSqlSnippetSkeletonV2.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free