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
A query
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
| SqlEditor | Type | Default |
|---|---|---|
onChangerequired | (v: string) => void | |
onRunrequired | () => void | |
valuerequired | string | |
aria-describedby | string | |
aria-labelThe name for screen readers when there is no Field around it. | string | |
aria-labelledby | string | |
className | string | |
disabled | boolean | |
idInside a Field it comes from the Field. | string | |
invalidMarks the value as wrong. Inside a `<Field error>` it is set for you. | boolean | |
placeholder | string | |
readOnly | boolean | |
rowsVisible lines before it scrolls. | number | |
running | boolean |