Git Product home page Git Product logo

harlequin's Introduction

Harlequin

PyPI

PyPI - Python Version Runs on Linux | MacOS | Windows

The SQL IDE for Your Terminal.

Harlequin

Installing Harlequin

After installing Python 3.8 or above, install Harlequin using pip or pipx with:

pipx install harlequin

Using Harlequin with DuckDB

From any shell, to open one or more DuckDB database files:

harlequin "path/to/duck.db" "another_duck.db"

To open an in-memory DuckDB session, run Harlequin with no arguments:

harlequin

If you want to control the version of DuckDB that Harlequin uses, see the Troubleshooting page.

Using Harlequin with SQLite and Other Adapters

Harlequin also ships with a SQLite3 adapter. You can open one or more SQLite database files with:

harlequin -a sqlite "path/to/sqlite.db" "another_sqlite.db"

Like DuckDB, you can also open an in-memory database by omitting the paths:

harlequin -a sqlite

Other adapters can be installed using pip install <adapter package> or pipx inject harlequin <adapter package>, depending on how you installed Harlequin. For a list of known adapters provided either by the Harlequin maintainers or the broader community, see the adapters page in the docs.

Getting Help

To view all command-line options for Harlequin and all installed adapters, after installation, simply type:

harlequin --help

To view a list of all key bindings (keyboard shortcuts) within the app, press F1. You can also view this list outside the app in the docs.

COLOR, KEY BINDING, OR COPY-PASTE PROBLEMS? See Troubleshooting in the docs.

More info at harlequin.sh

Visit harlequin.sh for an overview of features and full documentation.

Sponsoring Harlequin

Please consider sponsoring Harlequin's author, so he can continue to dedicate time to Harlequin.

Contributing

Thanks for your interest in Harlequin! Harlequin is primarily maintained by Ted Conbeer, but he welcomes all contributions!

Please see CONTRIBUTING.md for more information.

harlequin's People

Contributors

aaronsteers avatar bjornasm avatar code-master-ajay avatar dependabot[bot] avatar dljsjr avatar github-actions[bot] avatar joshtemple avatar mause avatar mpetazzoni avatar tconbeer avatar tylerhillery avatar vyshnav-vinod avatar wey-gu avatar zqianem 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

harlequin's Issues

multi-query handling

  • split at semicolons
  • only execute query at cursor
  • if selected more than 1 query, return results in tabs

Could be enhanced with #131 ; create a "Run All" button or checkbox? See also #155

Unexpected behavior from Windows keyboard input

Hi. I encountered two problems when I use harlequin on Windows:

  1. I can't enter even one line of code smoothly. There seems to be a problem with the formatting.
  2. Sometimes the editor exits abnormally. For example, pressing the Ctrl when there is no content.

record.webp

F1 = cheat sheet

ctrl+? doesn't work in the terminal, it's an alias for backspace (?). F1 should work!

Add multi-database support

DuckDB has support for attaching multiple databases. The catalog UI currently only takes the default DB into account. It would be great to show all databases/catalogs and their schemas on the left hand side, with the current default database highlighted.

Tracking Issue: Key bindings

Main Actions:

  • #31
  • ctrl + enter = run query
  • #94
  • ctrl + s = save
  • ctrl + o = open
  • #20
  • #149

Navigating and Editing:

  • ctrl + home = home home
  • ctrl + end = end end
  • #21
  • ctrl + x = cut
  • #22
  • ctrl + v = paste
  • #30
  • tconbeer/textual-textarea#77
  • F2 = focus on text editor
  • F5 = focus on the results viewer
  • F6 = focus on the data catalog

Tabbed editor (multiple buffers):

  • #23
  • ctrl + w = close tab
  • ctrl + j = prev tab (not doing; ctrl+j is alias for ctrl+enter to run query)
  • ctrl + k = next tab

Undo/Redo:

Find/Replace:

Goto:

Change Layout:

Not doing (key events not received):

  • #24
  • alt + down = swap line down

Cache the buffers on quit

Shouldn't be hard to store the editor's text property in a file.

Restore from cache on open, probably after we create the duckdb connection.

F10 = Full screen for focused widget

hopefully we can just push a new screen and then mount the current widget onto it.

F11 is intercepted by windows terminal, and doesn't come through as a key event; let's do f12 f10 instead.

Query perf and multiprocessing

Test thread worker vs the cli, figure out if multiprocessing would use more cores etc

The real bottleneck is loading lots of data into the table; not sure what to do about that.

Fix colors

Harlequin looks good in WSL, but not native in Windows, where the terminal displays more colors:

image

In particular, the background colors for the text editor (at least monokai theme) don't match the background colors for the data catalog and results viewer; the run query bar has a totally different (bluish) background.

Support pasting from the system clipboard

Currently Harlequin's query editor only supports pasting from text that has been already copied within the query editor. A common use case for SQL editors is copying SQL snnippets from the system clipboard, so this should be supported.

I can see from the doc string of the on_paste function in tui/components/textarea.py that this is a known limitation, but thought I'd create an issue to save others trying to work out if this is a bug or known limitation.

When I initiate a paste event I can see that the event param passed to the on_paste function has my copied text from the system clipboard in its text attribute, so hopefully that means all the ingredients are there ready to add this feature.

alt+up = swap line up

alt+up doesn't generate a key press I can listen for. It turns into this?

Key(
    key='escape',
    character=None,
    name='escape',
    is_printable=False,
    aliases=[
        'escape',
        'ctrl+left_square_brace'
    ]
)
Key(key='up', character=None, name='up', is_printable=False)

Run selection

Harlequin with latest duckdb on fedora 38.
Is it possible to run a selection from an sql scirpt file rather than the whole file?
Apologies if I am missing somehting very obvious.

ctrl + ` = format

I dropped this in the migration to textual_textarea; needs to be reimplemented

readonly does not allow multiple readers

Issue
Opening a database with --readonly should allow harlequin to open database files that are currently opened by another process for writing. Right now, harlequin attempts to lock a DB file, even when the --readonly flag is passed, resulting in an error when attempting to open a database that is concurrently open by another process.

❯ harlequin -r /tmp/mimo.db
╭─ DuckDB couldn't connect to your database. ───────────────────────────────────────────╮
│ IO Error: Could not set lock on file "/tmp/mimo.db": Resource temporarily unavailable │
╰────────────────────────────────────────────────────────────────────────── Try again? ─╯

Background
Currently the DuckDB driver allows a single writer and multiple readers to concurrently work on a single database file; see duckdb/duckdb#1330. Therefore, harlequin should open be able to open a database in 'reader' mode that is concurrently open by another process in writer mode.

Reproduction

  1. Open a DuckDB database file in writer mode with harlequin harlequin /tmp/mimo.db
  2. In another window open the same database in readonly mode harlequin -r /tmp/mimo.db
  3. The second command will fail to open the same database in read only mode.
  4. Kill the first harlequin process
  5. Running harlequin -r /tmp/mimo.db will now work fine

Feature Request: PRQL support

So, first, sorry about the PR spam on all your repos the last few days 😅

The reason I was doing that was because I've been on a personal education journey to learn both DuckDB (because I resonate w/ SQL much more than pandas) and PRQL because it's such a powerful and expressive alternative to raw SQL.

So if you look at my fork on the prql branch, I've cobbled together a janky version of this based on all my PR's to this repo and textual-textarea.

Granted that branch is definitely not ready for prime-time, but the bones are there and it actually works pretty great.

The meat of the changes are this:

  1. ℹ️ This functionality is based on this DuckDB extension: https://github.com/ywelsch/duckdb-prql
    1. PRQL works by getting compiled directly to SQL
    2. PRQL already has a duckdb dialect target built-in
    3. This plugin works by running the PRQL compiler in duckdb dialect mode on-the-fly
    4. Because of this, no changes are needed to the Python API outside of making sure the plugin is installed and loaded before passing PRQL strings to the sql() method on the connection.
  2. ℹ️ The change to textarea was just a convenience for me so that I could have some "init" scripts in my home dir that were easy to load
  3. ⚠️ Unfortunately, this extension does require that unsigned extensions be enabled, hence the PR for the -unsigned flag.
  4. ⚠️ This extension has its own release cadence, and doesn't have a 0.8.1 release yet, which is why on my personal fork I've pinned duckdb to 0.8.0 in the pyproject.toml.
    1. This is an artifact of the URL convention that duckdb uses for extension downloads even though semver kinda indicates that the extensions should remain compatible
    2. I think the fix to this would be vendoring the plugin but that would drastically complicate build and delivery of this project so I'm not sure the way you'd want to deal with that if this went forward.

Obviously, there's a lot from the above that raises questions about if this feature is worth it. But if you think it's something that would be valuable I'm more than happy to continue assisting with contributions.

And there would be more work down the road to make "prql mode" more of a 1st class citizen like including syntax support.

So I understand if it's not something you're interested in including, and it's pretty trivial to keep a patch for this going. Also, if we merge the -unsigned changes, then I don't even need the code patches, because you can load prql using regular plugin load statements.

Thanks in advance for looking at this!

Implement a new data table widget

The built-in widget is ok, but its data structures are super inefficient, which limits us to about 10k rows. It shouldn't be too bad(?) to fork the current widget and represent each row as a tuple of its data.

Support Explain output; Add Explain checkbox

Need to figure out how to handle the api/output of explain. IT's a 2-column query; the second column has multiline output, which the data table doesn't handle well. Maybe somehow detect explain and use markdown instead?

Running inside codespaces: TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

I was trying to use this inside of my nba-monte-carlo project.

I opened the codespace, ran pip install harlequin followed by cd data/data_catalog/. If I think try to open my db with harlequin mdsbox.db, I get the following error:

Traceback (most recent call last):
  File "/home/vscode/.local/bin/harlequin", line 5, in <module>
    from harlequin.cli import harlequin
  File "/home/vscode/.local/lib/python3.9/site-packages/harlequin/__init__.py", line 1, in <module>
    from harlequin.tui.app import Harlequin as Harlequin
  File "/home/vscode/.local/lib/python3.9/site-packages/harlequin/tui/app.py", line 13, in <module>
    from harlequin.tui.components import (
  File "/home/vscode/.local/lib/python3.9/site-packages/harlequin/tui/components/__init__.py", line 1, in <module>
    from harlequin.tui.components.code_editor import CodeEditor as CodeEditor
  File "/home/vscode/.local/lib/python3.9/site-packages/harlequin/tui/components/code_editor.py", line 4, in <module>
    from harlequin.tui.components.textarea import TextArea, TextInput
  File "/home/vscode/.local/lib/python3.9/site-packages/harlequin/tui/components/textarea.py", line 16, in <module>
    from harlequin.tui.components.error_modal import ErrorModal
  File "/home/vscode/.local/lib/python3.9/site-packages/harlequin/tui/components/error_modal.py", line 7, in <module>
    class ErrorModal(ModalScreen):
  File "/home/vscode/.local/lib/python3.9/site-packages/harlequin/tui/components/error_modal.py", line 13, in ErrorModal
    name: str | None = None,
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

Improve support for themes

Follow-up to #80

right now setting a theme just impacts the query editor pane, and it looks bad for most themes:

image

We could carry the theme colors throughout, with a lot of work.

Unfortunately, these are Pygments themes, which don't line up for Textual's planned support for themes (e.g., light/dark etc.)

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.