Code Monkey home page Code Monkey logo

kysely-playground's Introduction

Playground for Kysely, with vscode-like experiences including type checking and auto suggestions. Supports built-in dialects, various versions and unrealeased branches.

Guide

There are three panels in playground. From left to right, type-editor, query-editor and result.

In type-editor you can declare any kind of typescript types. For Kysely's type-safety and autocompletion to work, Database type must be declared with export. If you don't familiar with Kysely, checkout the official guide for more information about database types.

In query-editor you can write the query. db is pre-defined Kysely instance with Database type from type-editor. You can import any other types from type-editor: import {..} from "type-editor".

For advanced usage, you can set the result of db.*.execute() by setting $playground.result:

$playground.result = { rows: [{id:3},{id:4}] };
$playground.log(await db.selectFrom('person').select("id").execute())
// [{id:3},{id:4}]

Playground Link

For more advanced usage, you can import esm module directly from url:

// @ts-ignore
import isNumber from "https://esm.run/[email protected]/index.js"

Playground Link

API

You can embed the playground in your site. See kysely.dev

URL Fragment

Set initial State via url fragment.

const state = {
  dialect: "postgres",
  editors: {
    type: "// type editor contents",
    query: "// query editor contents",
  },
}
const fragment = "r" + encodedURIComponent(JSON.stringify(state))
const url = "https://kyse.link" + fragment

SearchParams

There are some extra flags mostly for iframe. Note that when user opens a new tab by 'open-in-new-tab' button, all SearchParams are removed.

key value description
open any show floating 'open-in-new-tab' button
theme 'light' | 'dark' override theme
nomore any hide 'More' button
notheme any hide 'switch-theme' button
nohotkey any disable all hotkeys

Example: https://kyse.link?theme=dark&open=1&theme=dark

kysely-playground's People

Contributors

igalklebanov avatar koskimas avatar wirekang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

kysely-playground's Issues

Cursor position is weird

The characters are not being typed with respect to the cursor position. They're being typed by 2-3 characters before the cursor position.

Issue with imports from 'kysely/helpers/mysql'

Hey!

I stumbled into this issue

The error usually means that there are two copies of Kysely. The SelectQueryBuilder type imported in the kysely/helpers/mysql file comes from a different copy of Kysely than the one passed to the jsonArrayFrom in the playground.

Thanks again for maintaining this awesome project!

SQL compile (parse) error when slicing an array.

Greetings, thanks for developing the playground!

I've found a weird issue, here is a minimal reproducible example. The error is on line 6 and this code in particular:

  .select(({ fn }) =>
    sql`(${fn.agg('array_agg', ['test'])})[:5]`.as('test')
  )
  // compile: Error: Parse error: Unexpected ":5] as "te" at line 1 column 28

For some reason, trying to slice an array using the colon symbol between square brackets causes this to error out. There are no issues with this code for example:

  .select(({ fn }) =>
    sql`(${fn.agg('array_agg', ['test'])})`.as('test')
  )

I should conclude by mentioning 2 things.

  1. I found that switching between postgres and mysql on the playground will error out, however if you use sqlite it will not.
  2. When running this locally on my backend, kysely does not throw any errors, and if I log the query it will produce valid SQL which I can run against my database without issues.

EDIT: Also tried using parens, but that did not work either. playground link

constatns vs constants?

I am pretty sure this is a simple typo, but just trying to confirm first ๐Ÿ™๐Ÿผ

Thanks for this cool tool!

Short link fails with firebase error

This project is really cool, thank you!

When I click on the "short link for discord" button, I see this error in the lower left:

share: FirebaseError: [code=permission-denied]: Missing or insufficient permissions.

Indentation 2 spaces instead of 4

Hi, it's me again ๐Ÿ˜…

Could the indentation be changed to 2 spaces from the current 4? I think 2 spaces is the standard in typescript/javascript world nowadays.

Rewrite

Current playground is working fine, but I haven't had enough time when I wrote it. I plan to rewrite the project in February when I have plenty of free time to let the playground handles differences between multiple kysely versions (like kysely/helpers/... and new dialects) flexibly. The new playground will be fully backward compatible so don't worry about breaking shared links. The user-side will be pretty much the same as before too.

So, if you have some good ideas or bad experiences, this is a great time to improve it. Please provide your feedbacks.

Possibly an invalid URL generated

Hi,

I might've messed something up, but I'm pretty sure kyse.link gave me this URL https://kyse.link/SH-8, which doesn't seem to work. As I said, I might've accidentally erased a part of it or something, but here it is in case you want to check if something went wrong.

kthxby

Modifying the schema doesn't re-evaluate the script

Hey!

Let's say I write a query to a non-existent table foo, there's correctly an error in the editor since that table doesn't exist. Now if I go to the schema editor and add that table, the error doesn't go away. I need to edit the script for the error to disappear. Could the script be updated also when the schema is modified? I think it used to be that way?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.