SQLEditor.constants.ts86 lines · main
| 1 | import { untrustedSql } from '@supabase/pg-meta' |
| 2 | import { IS_PLATFORM } from 'common' |
| 3 | |
| 4 | import type { SqlSnippets, UserContent } from '@/types' |
| 5 | |
| 6 | const SQL_SNIPPET_SCHEMA_VERSION = '1.0' |
| 7 | |
| 8 | export const NEW_SQL_SNIPPET_SKELETON: UserContent<SqlSnippets.Content> = { |
| 9 | name: 'New Query', |
| 10 | description: '', |
| 11 | type: 'sql', |
| 12 | visibility: 'user', // default to user scope |
| 13 | favorite: false, |
| 14 | content: { |
| 15 | schema_version: SQL_SNIPPET_SCHEMA_VERSION, |
| 16 | content_id: '', |
| 17 | unchecked_sql: untrustedSql(''), |
| 18 | }, |
| 19 | } |
| 20 | |
| 21 | export const sqlAiDisclaimerComment = ` |
| 22 | -- Briven AI is experimental and may produce incorrect answers |
| 23 | -- Always verify the output before executing |
| 24 | `.trim() |
| 25 | |
| 26 | // Should only be used for comparisons. If you need a new title, use generateSnippetTitle() |
| 27 | export const untitledSnippetTitle = 'Untitled query' |
| 28 | |
| 29 | /** |
| 30 | * Generates a snippet title. If the platform is self-hosted, it will return a random number to avoid conflicts. |
| 31 | */ |
| 32 | export const generateSnippetTitle = () => { |
| 33 | if (IS_PLATFORM) { |
| 34 | return untitledSnippetTitle |
| 35 | } else { |
| 36 | return `${untitledSnippetTitle} ${Math.floor(Math.random() * 900) + 100}` |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | export const destructiveSqlRegex = [ |
| 41 | /^(.*;)?\s*(drop|delete|truncate|alter\s+table\s+.*\s+drop\s+column)\s/is, |
| 42 | ] |
| 43 | |
| 44 | // Matches `UPDATE <table> SET ...` where <table> is any combination of bareword |
| 45 | // or double-quoted identifiers, optionally schema-qualified. Quoted identifiers |
| 46 | // can contain any character (including spaces) and use `""` to escape an inner |
| 47 | // quote, mirroring Postgres syntax. |
| 48 | export const updateWithoutWhereRegex = |
| 49 | /(?:^|;)\s*update\s+(?:"(?:[^"]|"")+"|[\w]+)(?:\.(?:"(?:[^"]|"")+"|[\w]+))?\s+set\s+[\w\W]+?(?!\s*where\s)/is |
| 50 | |
| 51 | export const alterDatabasePreventConnectionStatements = [ |
| 52 | 'alter database postgres connection limit 0', |
| 53 | 'alter database postgres allow_connections false', |
| 54 | ] |
| 55 | |
| 56 | export const ASSISTANT_TEMPLATES = [ |
| 57 | { |
| 58 | name: 'Twitter clone', |
| 59 | description: 'Simplified schema that mimics the Twitter application', |
| 60 | prompt: 'Create a twitter clone', |
| 61 | }, |
| 62 | { |
| 63 | name: 'Chat application', |
| 64 | description: 'Send messages through channels or direct messages', |
| 65 | prompt: |
| 66 | 'Create a chat application that supports sending messages either through channels or directly between users', |
| 67 | }, |
| 68 | { |
| 69 | name: 'User management schema', |
| 70 | description: 'With role based access control', |
| 71 | prompt: 'Create a simple user management schema that supports role based access control', |
| 72 | }, |
| 73 | { |
| 74 | name: 'Countries and Cities', |
| 75 | description: 'With each city belonging to a country', |
| 76 | prompt: |
| 77 | 'Create a table of countries and a table of cities, with each city belonging to a country', |
| 78 | }, |
| 79 | ] |
| 80 | |
| 81 | export const ROWS_PER_PAGE_OPTIONS = [ |
| 82 | { value: -1, label: 'No limit' }, |
| 83 | { value: 100, label: '100 rows' }, |
| 84 | { value: 500, label: '500 rows' }, |
| 85 | { value: 1000, label: '1,000 rows' }, |
| 86 | ] |