Commit graph

201 commits

Author SHA1 Message Date
Pekka Enberg
96c47667ea Merge 'Add abbreviated alias for .quit and .exit' from Krishna Vishal
Accidentally found that you can quit SQLite CLI just by typing `.q`,
`.qu` and `.qui` instead of full `.quit`.
IMO this will be an improvement to the DX.
I've also found bunch of other dot commands that work with abbreviated
aliases in SQLite. If this PR is okay then I will also add them here.

Closes #1720
2025-06-16 11:11:17 +03:00
Pekka Enberg
4d6b5c2b88 Merge 'cli: fix panic of queries with less than 7 chars' from Nils Koch
Hey everyone! I think this project is really really cool and I am here
to answer @jussisaurio
[call](https://x.com/jussisaur/status/1930290889496129562).
I started tinkering around with limbo and ran into this panic. Any input
with less than 7 characters (`"explain".len()`) will trigger it. In my
case it was `show;`. The issue was introduced a week ago in #1678.
PS: As I [said on X](https://x.com/nilskch/status/1930362930605723818),
I would love to help you with Limbo. I have a lot of experience with
DSLs and LSPs, and I have recently become interested in databases. I
don't have much experience with databases yet, but I am happy to learn.
I see that you have a lot of stuff going on with DSLs at the moment, so
I would be productive straight away in that area. Happy to chat if you
need help :)

Closes #1730
2025-06-16 11:06:02 +03:00
Pekka Enberg
90c1e3fc06 Switch Connection to use Arc instead of Rc
Connection needs to be Arc so that bindings can wrap it with `Mutex` for
multi-threading.
2025-06-16 10:43:19 +03:00
Nils Koch
733c3603f2
cli: fix panic of queries with less than 7 chars 2025-06-13 20:25:47 +01:00
Krishna Vishal
3ff9af3320 Add .quit alias = .q, .qu, .qui
Add .exit alias = .ex, .exi
2025-06-12 00:07:07 +05:30
pedrocarlo
b942414bb4 add anyhow to workspace dependency 2025-06-10 10:50:39 -03:00
pedrocarlo
0f2849f7e1 serde and serde_json as workspace dependencies 2025-06-09 11:38:15 -03:00
Anton Harniakou
5944e07484 Use eq_ignore_ascii_case 2025-06-06 17:08:49 +03:00
meteorgan
ab4eda59be close conn after executing limbo in cli 2025-06-03 22:06:08 +08:00
pedrocarlo
08f415370c remove rustyline traces from cli 2025-05-30 11:33:22 -03:00
Jussi Saurio
58bff43f1f Merge 'remove detection of comments in the middle of query in cli' from Pedro Muniz
I was trying to run the TPC-H 9.sql in the CLI, but it kept truncating
my input due to a comment that is present in the query. After removing
it, I can just copy and paste the query and it works. @PThorpe92 is it
safe to remove this? Or is there a particular reason that was included
that I am not aware of?

Closes #1525
2025-05-22 09:48:13 +03:00
Diego Reis
c76387ec1b cli/fix: Apply default config for app 2025-05-21 12:06:08 -03:00
pedrocarlo
4b7e4417aa remove detection of comments in the middle of query in cli 2025-05-19 16:47:00 -03:00
pedrocarlo
b3b52f7f2f applying config in app 2025-05-17 15:51:43 -03:00
pedrocarlo
c73927729d config docs 2025-05-17 15:51:17 -03:00
pedrocarlo
a614114591 Config Definitions 2025-05-17 15:51:17 -03:00
Pekka Enberg
e3f71259d8 Rename OwnedValue -> Value
We have not had enough merge conflicts for a while so let's do a
tree-wide rename.
2025-05-15 09:59:46 +03:00
Pekka Enberg
3e6ac7c4a0 Merge 'Save history on exit' from Piotr Rżysko
Before this change, the history was only saved when the shell was
interrupted (e.g., Ctrl-C pressed twice). With this change, history is
now also saved when the `.exit` or `.quit` commands are used.
I attempted to add shell tests to cover the changes introduced in this
PR, but emulating a terminal/TTY that would work cross-platform seems to
require significant changes to `TestLimboShell` and `LimboShell`. For
example, the `pty` module [currently doesn't support
Windows](https://bugs.python.org/issue41663). I'm open to experimenting,
but I’m unsure if complicating these classes is worthwhile, as saving
history doesn't seem to be critical.
Additionally, it might be worth considering a refactor of the CLI so
that exit and cleanup operations are performed in one place.

Reviewed-by: Preston Thorpe (@PThorpe92)

Closes #1414
2025-04-29 21:50:41 +03:00
Piotr Rzysko
33d230771f Save history on exit 2025-04-28 08:59:25 +02:00
Pekka Enberg
ab841c47bc Merge 'Add the .indexes command' from Anton Harniakou
Adds ability to view database indices using the `.indexes ?TABLE?`
command.

Closes #1409
2025-04-27 20:46:02 +03:00
Anton Harniakou
6d3c63fb01 Add the .indexes command 2025-04-26 12:27:08 +03:00
Jussi Saurio
0d77ea9446 Merge 'Optimization: only initialize Rustyline if we are in a tty' from Pedro Muniz
This is small nitpick, but it will be useful for #1258. If we are
testing or just piping some sql through stdin, we can just not
initialize `Rustyline` and save some execution time.
On `Select 1` bench, I got a minor performance bump, but it starts to
become less apparent on more complex queries.
<img width="759" alt="image" src="https://github.com/user-
attachments/assets/12e22675-e081-4284-a5ed-15d53a9c5579" />

Closes #1372
2025-04-25 23:02:42 +03:00
Anton Harniakou
fdf3dd9796 Bugfix: Explain command should display syntax errors in CLI
Closes #1392
2025-04-24 13:25:00 +03:00
Anton Harniakou
5c18c1c57a Draw table if it contains any row
Some table can be headerless, for example results of PRAGMA calls
2025-04-23 16:36:43 +03:00
pedrocarlo
277f6f1083 Switch to using std::io::IsTerminal::is_terminal 2025-04-21 01:03:31 -03:00
pedrocarlo
7aaffff45f Correct for Windows 2025-04-20 18:42:01 -03:00
pedrocarlo
b550fbb3e4 Only initialize Rustyline if we are in a tty 2025-04-20 17:03:43 -03:00
pedrocarlo
4d1ecd2d50 better MalformedHexInteger 2025-04-11 09:44:02 -03:00
Pekka Enberg
17b206297e Merge 'Emit ANSI codes only when tracing is outputting to terminal' from Preston Thorpe
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #1289
2025-04-10 20:54:21 +03:00
Jussi Saurio
60a13c129f io/linux: make syscallio the default (io_uring is really slow) 2025-04-10 13:32:26 +03:00
PThorpe92
5643a0abba
Dont emit ansi codes when outputting logs to a file 2025-04-09 19:31:35 -04:00
pedrocarlo
94217319a2 Fix Explain to be case insensitive 2025-04-09 14:21:18 -03:00
Pere Diaz Bou
2316d7ebf1 add .timer command with fine grained statistics about limbo
```
Limbo v0.0.19-pre.4
Enter ".help" for usage hints.
limbo> .timer on
limbo> select count(1) from users;
┌───────────┐
│ count (1) │
├───────────┤
│     10000 │
└───────────┘
Command stats:
----------------------------
total: 35 ms (this includes parsing/coloring of cli app)

query execution stats:
----------------------------
Execution: avg=16 us, total=33 us
I/O: avg=123 ns, total=3 us
limbo> select 1;
┌───┐
│ 1 │
├───┤
│ 1 │
└───┘
Command stats:
----------------------------
total: 282 us (this includes parsing/coloring of cli app)

query execution stats:
----------------------------
Execution: avg=2 us, total=4 us
I/O: No samples available
```
2025-04-09 16:31:08 +02:00
PThorpe92
01184ec1d7
Add tracing-appender to log traces to file asyncronously 2025-04-08 19:36:38 -04:00
pedrocarlo
907794cb07 add path completion for .import 2025-04-04 19:04:42 -03:00
pedrocarlo
d5fa37ab66 remove error debug 2025-04-04 17:44:34 -03:00
pedrocarlo
57af9c71ba customize completion candidates for some args 2025-04-04 17:39:09 -03:00
pedrocarlo
fd3335908c basic autocomplete for dot commands 2025-04-04 13:01:57 -03:00
Pere Diaz Bou
70c5cf3970 Merge 'Refactor Cli Repl Commands to use clap' from Pedro Muniz
This PR changes the argument parsing and matching to use Clap instead of
our own handrolled one. This makes it much easier to add new commands
and modify existing ones by using the full power of clap's derive
macros. It also produces nice error and help messages for us. However,
there is a bug in Clap that is not correctly modifying the `display
name` in the help section. So the command would appear as `show` instead
of `.show` in the help messages. This is very minimal, but if this is a
blocker for this PR we can just overwrite the help message in its
entirety. Also using Clap would enable us to use its autocomplete crate
to generate autocompletions for these special repl commands which would
be a huge win when compared to the `sqlite3` cli.
This is the current help message:
```sh

Limbo SQL Shell Help
==============
Welcome to the Limbo SQL Shell! You can execute any standard SQL command here.
In addition to standard SQL commands, the following special commands are available:

Usage: <COMMAND>

Commands:
  exit       Exit this program with return-code CODE
  quit       Quit the shell
  open       Open a database file
  schema     Print this message or the help of the given subcommand(s) Display schema for a table
  output     Set output file (or stdout if empty)
  mode       Set output display mode
  opcodes    Show vdbe opcodes
  cd         Change the current working directory
  show       Display information about settings
  nullvalue  Set the value of NULL to be printed in 'list' mode
  echo       Toggle 'echo' mode to repeat commands before execution
  tables     Display tables
  import     Import data from FILE into TABLE
  load       Loads an extension library
  dump       Dump the current database as a list of SQL statements
  listvfs    List vfs modules available
  help       Print this message or the help of the given subcommand(s)

Usage Examples:
---------------
1. To quit the Limbo SQL Shell:
   .quit

2. To open a database file at path './employees.db':
   .open employees.db

3. To view the schema of a table named 'employees':
   .schema employees

4. To list all tables:
   .tables

5. To list all available SQL opcodes:
   .opcodes

6. To change the current output mode to 'pretty':
   .mode pretty

7. Send output to STDOUT if no file is specified:
   .output

8. To change the current working directory to '/tmp':
   .cd /tmp

9. Show the current values of settings:
   .show

10. To import csv file 'sample.csv' into 'csv_table' table:
   .import --csv sample.csv csv_table

11. To display the database contents as SQL:
   .dump

12. To load an extension library:
   .load /target/debug/liblimbo_regexp

13. To list all available VFS:
   .listvfs

Note:
- All SQL commands must end with a semicolon (;).
- Special commands start with a dot (.) and are not required to end with a semicolon.

```
If we need more information on a specific command, we can leverage CLAP
and do for instance:
```sh
.open -h
```

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #1110
2025-04-01 11:40:14 +02:00
pedrocarlo
14ed8c8c50 correct vfs command 2025-03-30 03:22:44 -03:00
pedrocarlo
a612ad193c accidently removed an Error string 2025-03-30 03:12:36 -03:00
pedrocarlo
c36dc61c92 adding listvfs to extra helpful message 2025-03-30 02:52:07 -03:00
pedrocarlo
62b866618b docs for cli 2025-03-30 02:41:48 -03:00
pedrocarlo
b7bbafd691 adjusting listvfs command 2025-03-30 01:52:16 -03:00
pedrocarlo
82db51b94f remove debug clap 2025-03-30 01:46:24 -03:00
pedrocarlo
fe25035c7c display name in clap is buggy 2025-03-30 01:46:24 -03:00
pedrocarlo
02c466cb1f start of refactor of repl to use clap 2025-03-30 01:44:58 -03:00
Pere Diaz Bou
d9f5cd870d clippy 2025-03-29 22:04:08 +01:00
Pere Diaz Bou
3317195a53 Reusable ImmutableRecord -> allocation reduction
Improve allocation usage from ImmutableRecords by reusing them.
ImmutableRecord is basically a contigous piece of memory that holds the
current record. If we move to some other record we usually deallocate
the previous one and allocate a new one -- obviously this is wasteful.
With this commit we will reuse the ImmutableRecord to allow payload to
be extended if needed or reused if we can, making it faster to iterate
records basically.
2025-03-29 22:04:08 +01:00
Pere Diaz Bou
ee55116ca6 return row as reference to registers 2025-03-29 22:04:08 +01:00