Skip to content

Commit

Permalink
Migrate to new playground (#861)
Browse files Browse the repository at this point in the history
Co-authored-by: Igal Klebanov <[email protected]>
  • Loading branch information
wirekang and igalklebanov authored Jul 14, 2024
1 parent ba71056 commit 5e60d76
Showing 1 changed file with 48 additions and 31 deletions.
79 changes: 48 additions & 31 deletions site/src/components/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@ export function Playground({
setupCode = exampleSetup,
kyselyVersion,
dialect = 'postgres',
disableIframeMode = false,
}: PlaygroundProps) {
const state: PlaygroundState = {
dialect,
editors: { query: code, type: setupCode },
hideType: true,
}
if (kyselyVersion) {
state.kysely = { type: 'tag', name: kyselyVersion }
}
const params = new URLSearchParams()
params.set('p', 'j')
params.set(
'i',
JSON.stringify({
q: code.trim(),
s: setupCode.trim(),
v: kyselyVersion,
d: dialect,
c: false,
}),
)
params.set('theme', 'dark')
if (!disableIframeMode) {
params.set('open', '1')
params.set('nomore', '1')
params.set('notheme', '1')
params.set('nohotkey', '1')
}
const hash = '#r' + encodeURIComponent(JSON.stringify(state))

return (
<iframe
Expand All @@ -25,7 +31,7 @@ export function Playground({
borderRadius: 7,
}}
allow="clipboard-write"
src={`https://kyse.link/?${params.toString()}`}
src={`https://kyse.link/?${params}${hash}`}
/>
)
}
Expand All @@ -35,32 +41,43 @@ interface PlaygroundProps {
dialect?: 'postgres'
code: string
setupCode?: string
disableIframeMode: boolean
}

export const exampleSetup = `
import { Generated } from 'kysely'
interface PlaygroundState {
dialect: 'postgres' | 'mysql' | 'mssql' | 'sqlite'
editors: {
type: string
query: string
}
hideType?: boolean
kysely?: {
type: 'tag' | 'branch'
name: string
}
}

declare global {
interface DB {
export const exampleSetup = `import { Generated } from 'kysely'
export interface Database {
person: PersonTable
pet: PetTable
}
}
interface PersonTable {
id: Generated<string>
first_name: string
last_name: string | null
created_at: Generated<Date>
age: number
}
interface PersonTable {
id: Generated<string>
first_name: string
last_name: string | null
created_at: Generated<Date>
age: number
}
interface PetTable {
id: Generated<string>
name: string
owner_id: string
species: 'cat' | 'dog'
is_favorite: boolean
}
interface PetTable {
id: Generated<string>
name: string
owner_id: string
species: 'cat' | 'dog'
is_favorite: boolean
}
`

Expand Down

0 comments on commit 5e60d76

Please sign in to comment.