Skip to content

SqlEditor

SQL with a Run button; Ctrl/⌘+Enter runs it too. The result goes under it.

import { SqlEditor } from '@sypnia/ui/react'

On this page
  1. A query
  2. When to use it
  3. For everyone
  4. Props

A query

Ctrl or ⌘ + Enter runs it
Code
import { useState } from 'react';
import { Field, SqlEditor, toast, Toaster } from '@sypnia/ui/react';

// Press Run or Ctrl/⌘ + Enter.
export default function Query() {
  const [sql, setSql] = useState('select country, count(*)\nfrom orders\nwhere created_at > now() - interval \'7 days\'\ngroup by 1\norder by 2 desc;');
  const [running, setRunning] = useState(false);
  return (
    <>
      <Field label="Query"><SqlEditor value={sql} onChange={setSql} rows={6} running={running} onRun={() => { setRunning(true); setTimeout(() => { setRunning(false); toast('12 rows in 48 ms', { tone: 'ok' }); }, 900); }} /></Field>
      <Toaster />
    </>
  );
}

When to use it

Use it when

  • The SQL page of a database console.

Do not use it when

  • Queries people should not change: show them read-only in a CodeBlock.

For everyone

  • The shortcut is written next to the button.

Props

SqlEditorTypeDefault
onChangerequired (v: string) => void
onRunrequired () => void
valuerequired string
aria-describedby string
aria-label

The name for screen readers when there is no Field around it.

string
aria-labelledby string
className string
disabled boolean
id

Inside a Field it comes from the Field.

string
invalid

Marks the value as wrong. Inside a `<Field error>` it is set for you.

boolean
placeholder string
readOnly boolean
rows

Visible lines before it scrolls.

number
running boolean
  1. A query
  2. When to use it
  3. For everyone
  4. Props

    Search pages, sections and terms