The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
update codeblock
Jonathan Summers-Muir2ead012b99c1
diff --git a/apps/www/_blog/2022-06-28-partial-postgresql-data-dumps-with-rls.mdx b/apps/www/_blog/2022-06-28-partial-postgresql-data-dumps-with-rls.mdxindex efc67182e69..f62e9b2cb0b 100644--- a/apps/www/_blog/2022-06-28-partial-postgresql-data-dumps-with-rls.mdx+++ b/apps/www/_blog/2022-06-28-partial-postgresql-data-dumps-with-rls.mdx@@ -27,7 +27,6 @@ The concept is simple:For this scenario, let's imagine that you have a table called `profiles` in your database:```sql hideCopy-create table profiles (id serial primary key,name text,@@ -63,7 +62,7 @@ grant select on profiles to exporter;Let's turn on RLS for this table and limit the data which `exporter` can access:-```sql hideCopy+```sql hideCopy hideLineNumbers-- Turn on Row Level Securityalter table profilesenable row level security;@@ -83,8 +82,7 @@ Now we can use `pg_dump` to get only the data that we need.Run the dump with the `exporter` user that we created above and use the `--enable-row-security` flag to ensure that the dump succeeds.-```sh hideCopy-+```bash hideCopy hideLineNumbers# Dump all the data into a "seed.sql" file# which we can use to restore our local databases.pg_dump \@@ -98,6 +96,10 @@ pg_dump \> seed.sql```+```bash hideCopy hideLineNumbers+-h db.host.supabase.co \+```+And that's it. You can follow this same pattern for any tables that you want to dump.## Data access patternsdiff --git a/apps/www/components/CodeBlock/CodeBlock.tsx b/apps/www/components/CodeBlock/CodeBlock.tsxindex 25de64199bd..87960fa1191 100644--- a/apps/www/components/CodeBlock/CodeBlock.tsx+++ b/apps/www/components/CodeBlock/CodeBlock.tsx@@ -1,39 +1,44 @@-import { useCallback, useMemo } from 'react'-import reactSyntaxHighlighter, { Light as SyntaxHighlighter } from 'react-syntax-highlighter'-import monokaiCustomTheme from 'data/CodeEditorTheme'-import CodeBlockStyles from './CodeBlock.module.css'-import { Button, IconCopy } from '@supabase/ui'+import { Button, IconCheck, IconCopy, IconFile, IconTerminal } from '@supabase/ui'+import { useState } from 'react'import CopyToClipboard from 'react-copy-to-clipboard'-import rangeParser from 'parse-numeric-range'--import classNames from 'classnames'-+import { Light as SyntaxHighlighter } from 'react-syntax-highlighter'+import bash from 'react-syntax-highlighter/dist/cjs/languages/hljs/bash'import js from 'react-syntax-highlighter/dist/cjs/languages/hljs/javascript'-import ts from 'react-syntax-highlighter/dist/cjs/languages/hljs/typescript'import py from 'react-syntax-highlighter/dist/cjs/languages/hljs/python'import sql from 'react-syntax-highlighter/dist/cjs/languages/hljs/sql'+import monokaiCustomTheme from './CodeBlock.utils'-export interface CodeBlockProps {- lang: 'js' | 'ts' | 'sql' | 'py'+interface Props {+ lang: 'js' | 'sql' | 'py' | 'bash'startingLineNumber?: numberhideCopy?: boolean+ showLineNumbers?: booleanclassName?: stringchildren?: stringsize?: 'small' | 'medium' | 'large'- /**- * Inline styling- * Supports CSS Properties in camelcase- */- style?: React.CSSProperties | undefined- /**- * Lines to be highlighted.- * Supports individual lines: '14', multiple lines: '14,15', or a range of lines '14..19'- */- highlightLines?: string- hideBorder?: boolean}-function CodeBlock(props: CodeBlockProps) {+function CodeBlock(props: Props) {+ const [copied, setCopied] = useState(false)++ const firstLine = props.children ? props.children.split('\n')[0] : ''++ let filename = ''++ if (firstLine.includes('filename =')) {+ filename = firstLine.split('=')[1]+ }++ const content =+ props.children && filename ? props.children.replace(`${firstLine}\n\n`, '') : props.children++ const handleCopy = () => {+ setCopied(true)+ setTimeout(() => {+ setCopied(false)+ }, 1000)+ }+let lang = props.lang? props.lang: props.className@@ -41,87 +46,90 @@ function CodeBlock(props: CodeBlockProps) {: 'js'// force jsx to be js highlightedif (lang === 'jsx') lang = 'js'- if (lang === 'tsx') lang = 'ts'SyntaxHighlighter.registerLanguage('js', js)- SyntaxHighlighter.registerLanguage('ts', ts)SyntaxHighlighter.registerLanguage('py', py)SyntaxHighlighter.registerLanguage('sql', sql)+ SyntaxHighlighter.registerLanguage('bash', bash)// const large = props.size === 'large' ? true : falseconst large = false- const shouldHighlightLines = props.highlightLines !== undefined- const highlightLines = useMemo(- () => new Set(rangeParser(props.highlightLines ?? '')),- [props.highlightLines]- )-- const lineProps = useCallback(- (lineNumber: number) => {- const shouldHighlightLine = !shouldHighlightLines || highlightLines.has(lineNumber)-- const style = shouldHighlightLine ? {} : { filter: 'grayscale(75%)', opacity: 0.5 }-- return {- className: classNames(- CodeBlockStyles['code-line'],- shouldHighlightLines && shouldHighlightLine && CodeBlockStyles['code-line--flash']- ),- style,- }- },- [highlightLines]- )-return (- <div className="relative">- <SyntaxHighlighter- language={lang}- style={monokaiCustomTheme}- className={[- CodeBlockStyles['code-block'],- '!bg-scale-1200 dark:!bg-scale-100',- props.hideBorder ? '' : 'border-scale-1100 dark:border-scale-400 rounded-lg border',- ].join(' ')}- customStyle={{- padding: 0,- fontSize: large ? 18 : 12,- lineHeight: large ? 1.2 : 1.2,-- ...props.style,- }}- showLineNumbers={lang === 'cli' ? false : true}- lineNumberContainerStyle={{- paddingTop: '128px',- }}- lineNumberStyle={{- display: 'inline-flex',- justifyContent: 'flex-end',- minWidth: '48px',- // background: 'var(--colors-fixed-scale12)',- paddingLeft: '21px',- marginRight: '12px',- color: 'var(--colors-fixed-scale7)',- fontSize: large ? 14 : 12,- paddingTop: '4px',- paddingBottom: '4px',- }}- wrapLines={true}- lineProps={lineProps}- >- {props.children}- </SyntaxHighlighter>+ <div className="not-prose dark overflow-hidden">+ {filename && (+ <div+ className="+ bg-scale-200+ text-scale-900+ flex+ h-8 w-full+ items-center++ gap-1+ rounded-tr+ rounded-tl++ border-t- {!props.hideCopy && props.children ? (- <div className="dark absolute right-2 top-2">- <CopyToClipboard text={props.children}>- <Button type="default" icon={<IconCopy />}>- Copy- </Button>- </CopyToClipboard>+ border-r+ border-l+ px-4+ font-sans+ "+ >+ {lang === 'bash' ? (+ <IconTerminal size={12} strokeWidth={2} />+ ) : (+ <IconFile size={12} strokeWidth={2} />+ )}+ <span className="text-xs">{filename ?? 'index.js'}</span></div>- ) : null}+ )}+ <div className="relative">+ <SyntaxHighlighter+ language={lang}+ style={monokaiCustomTheme}+ className={[!filename && 'rounded-t-lg', 'rounded-b-lg'].join(' ')}+ customStyle={{+ padding: '21px 24px',+ fontSize: large ? 18 : '0.875rem',+ lineHeight: large ? 1.6 : 1.4,+ background: '#181818',+ }}+ showLineNumbers={props.showLineNumbers}+ lineNumberStyle={{+ padding: '0px',+ marginRight: '21px',+ minWidth: '1.5em',+ opacity: '0.3',+ fontSize: large ? 14 : '0.75rem',+ }}+ >+ {content}+ </SyntaxHighlighter>+ {!props.hideCopy && props.children ? (+ <div className="dark absolute right-2 top-2">+ <CopyToClipboard text={props.children}>+ <Button+ type="text"+ icon={+ copied ? (+ <span className="text-brand-900">+ <IconCheck strokeWidth={3} />+ </span>+ ) : (+ <IconCopy />+ )+ }+ onClick={() => handleCopy()}+ >+ {/* {copied ? 'Copied' : 'Copy'} */}+ </Button>+ </CopyToClipboard>+ </div>+ ) : null}+ </div></div>)}diff --git a/apps/www/components/CodeBlock/CodeBlock.utils.js b/apps/www/components/CodeBlock/CodeBlock.utils.jsnew file mode 100644index 00000000000..4233bf1548a--- /dev/null+++ b/apps/www/components/CodeBlock/CodeBlock.utils.js@@ -0,0 +1,116 @@+const monokaiCustomTheme = {+ hljs: {+ display: 'block',+ overflowX: 'auto',+ padding: '0.5em',+ background: '#272822',+ color: '#ddd',+ },+ 'hljs-tag': {+ color: '#569cd6',+ },+ 'hljs-keyword': {+ color: '#569cd6',+ fontWeight: 'normal',+ },+ 'hljs-selector-tag': {+ color: '#569cd6',+ fontWeight: 'normal',+ },+ 'hljs-literal': {+ color: '#569cd6',+ fontWeight: 'normal',+ },+ 'hljs-strong': {+ color: '#569cd6',+ },+ 'hljs-name': {+ color: '#569cd6',+ },+ 'hljs-code': {+ color: '#66d9ef',+ },+ 'hljs-class .hljs-title': {+ color: 'gray',+ },+ 'hljs-attribute': {+ color: '#bf79db',+ },+ 'hljs-symbol': {+ color: '#bf79db',+ },+ 'hljs-regexp': {+ color: '#bf79db',+ },+ 'hljs-link': {+ color: '#bf79db',+ },+ 'hljs-string': {+ color: '#3ECF8E',+ },+ 'hljs-bullet': {+ color: '#3ECF8E',+ },+ 'hljs-subst': {+ color: '#3ECF8E',+ },+ 'hljs-title': {+ color: '#3ECF8E',+ fontWeight: 'normal',+ },+ 'hljs-section': {+ color: '#3ECF8E',+ fontWeight: 'normal',+ },+ 'hljs-emphasis': {+ color: '#3ECF8E',+ },+ 'hljs-type': {+ color: '#3ECF8E',+ fontWeight: 'normal',+ },+ 'hljs-built_in': {+ color: '#3ECF8E',+ },+ 'hljs-builtin-name': {+ color: '#3ECF8E',+ },+ 'hljs-selector-attr': {+ color: '#3ECF8E',+ },+ 'hljs-selector-pseudo': {+ color: '#3ECF8E',+ },+ 'hljs-addition': {+ color: '#3ECF8E',+ },+ 'hljs-variable': {+ color: '#3ECF8E',+ },+ 'hljs-template-tag': {+ color: '#3ECF8E',+ },+ 'hljs-template-variable': {+ color: '#3ECF8E',+ },+ 'hljs-comment': {+ color: '#75715e',+ },+ 'hljs-quote': {+ color: '#75715e',+ },+ 'hljs-deletion': {+ color: '#75715e',+ },+ 'hljs-meta': {+ color: '#75715e',+ },+ 'hljs-doctag': {+ fontWeight: 'normal',+ },+ 'hljs-selector-id': {+ fontWeight: 'normal',+ },+}++export default monokaiCustomTheme