Commit Graph

268 Commits

Author SHA1 Message Date
Glauber Costa
841296a39d add new commands to the MCP server
When playing with our MCP server with Claude Code, I realized that
having the agent pre-configured to a specific path is just not very
useful.

I am now adding two new commands, to open a database and to list
the current database. Those make our server more useful.
2025-08-16 11:00:28 -05:00
Nikita Sivukhin
6280d33b02 init tracing in CLI early
- now we miss logs from DB initialization phase
2025-08-15 13:11:38 +04:00
PThorpe92
9ccf79111a Support non-utf8 blobs in .clone command 2025-08-14 21:31:14 -04:00
PThorpe92
2b289157d0 Properly quote sequence value 2025-08-14 21:31:14 -04:00
PThorpe92
7abf071128 Conditionally emit pragma foreign_keys=off when not .cloning 2025-08-14 21:31:14 -04:00
PThorpe92
4a612c1586 Properly implement .clone method safely 2025-08-14 21:31:13 -04:00
Jussi Saurio
69d8a73028 Merge 'use virtual root page for sqlite_schema' from Mikaël Francoeur
This PR fixes a problem where `sqlite_schema` could be read before page
1 was allocated.
The fix is similar to that in SQLite. In SQLite, if `btreeCursor()` sees
that the root page is 1 and that the b-tree is empty, it sets the page
to 0 ([here](https://github.com/sqlite/sqlite/blob/master/src/btree.c#L4
691-L4696)). SQLite's `moveToRoot()` then uses this special value to
return `CURSOR_INVALID` with no rows ([here](https://github.com/sqlite/s
qlite/blob/master/src/btree.c#L5538-L5540)).
Fixes https://github.com/tursodatabase/turso/issues/2449

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #2551
2025-08-14 11:08:11 +03:00
Mikaël Francoeur
07ef47924c use virtual root page for sqlite_schema 2025-08-13 16:31:21 -04:00
PThorpe92
614a0a45a6 Relax and fix memory ordering 2025-08-13 10:09:37 -04:00
Pekka Enberg
b82d850f7a Merge 'Reset interrupt count each time a new line is entered in CLI' from
Resolves issue #1833.
**Before:**
<img width="581" height="92" alt="Screenshot 2025-08-11 at 9 07 21 PM"
src="https://github.com/user-
attachments/assets/eff4c919-ad54-4379-bbee-28eb3e4a375f" />
**After:**
<img width="563" height="118" alt="Screenshot 2025-08-11 at 9 07 27 PM"
src="https://github.com/user-
attachments/assets/f99f84a0-f5d3-4d70-9e08-1c3871fddda3" />

Closes #2554
2025-08-12 11:50:03 +03:00
rajajisai
5cc5b0bca1 Reset interrupt count each time a new line is entered in CLI 2025-08-11 21:16:43 -07:00
Pekka Enberg
e829201fdd cli: Fix .schema SQL statement some more
We need to fetch name and type too, but also sort in both places
consistently.
2025-08-11 11:52:57 +03:00
Pekka Enberg
4923d95ca3 cli: Fix schema object ordering
SQLite orders schema objects by rowid, not by name.
2025-08-11 11:43:23 +03:00
Glauber Costa
145d6eede7 Implement very basic views using DBSP
This is just the bare minimum that I needed to convince myself that this
approach will work. The only views that we support are slices of the
main table: no aggregations, no joins, no projections.

drop view is implemented.
view population is implemented.
deletes, inserts and updates are implemented.

much like indexes before, a flag must be passed to enable views.
2025-08-10 23:34:04 -05:00
Preston Thorpe
d3e6172516 Merge 'global allocator should not be set for library, only for executables' from Pedro Muniz
We should be allocator-agnostic. It is pretty limiting for us to force a
user to use a particular allocator. This is specially restricting for
`no_std` in the future.

Reviewed-by: bit-aloo (@Shourya742)
Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #2481
2025-08-08 09:45:35 -04:00
PThorpe92
f75eaee886 Rename .copy -> .clone 2025-08-07 16:27:07 -04:00
PThorpe92
7e42b97b93 Add .help output for copying db file cmd 2025-08-07 16:27:07 -04:00
PThorpe92
837278c2d0 Add .help output for copying db file cmd 2025-08-07 16:27:07 -04:00
PThorpe92
736f78de64 Add .copy CLI command 2025-08-07 16:27:07 -04:00
pedrocarlo
edae65fb5f global allocator should not be set for library, only for executables 2025-08-07 13:41:50 -03:00
Jussi Saurio
86b1232268 chore: enable indexes by default 2025-08-01 15:44:56 +03:00
PThorpe92
f78c6af51a Display error when unable to open file from within cli 2025-07-30 14:07:20 +03:00
Glauber Costa
988b16f962 Support ATTACH (read only)
Support for attaching databases. The main difference from SQLite is that
we support an arbitrary number of attached databases, and we are not
bound to just 100ish.

We for now only support read-only databases. We open them as read-only,
but also, to keep things simple, we don't patch any of the insert
machinery to resolve foreign tables.  So if an insert is tried on an
attached database, it will just fail with a "no such table" error - this
is perfect for now.

The code in core/translate/attach.rs is written by Claude, who also
played a key part in the boilerplate for stuff like the .databases
command and extending the pragma database_list, and also aided me in
the test cases.
2025-07-24 19:19:48 -05:00
meteorgan
2ec40db6b5 check if db is initialized before .import 2025-07-24 23:18:29 +08:00
meteorgan
ab2bc547cd check if datbase is initialized before display schema, index and tables 2025-07-24 23:18:29 +08:00
Glauber Costa
57a1113460 make readonly a property of the database
There's no such thing as a read-only connection.
In a normal connection, you can have many attached databases. Some
r/o, some r/w.

To properly fix that, we also need to fix the OpenWrite opcode. Right
now we are passing a name, which is the name of the table. That
parameter is not used anywhere. That is also not what the SQLite opcode
specifies. Same as OpenRead, the p3 register should be the database
index.

With that change, we can - for now - pass the index 0, which is all
we support anyway, and then use that to test if we are r/o.
2025-07-22 09:41:32 -05:00
PThorpe92
f7ba8efdbd Switch back to std::mutex because it was an unnecessary change 2025-07-21 19:20:17 -04:00
PThorpe92
5e5b3ce071 Fix leak of extension CTX in cli/app 2025-07-21 19:09:58 -04:00
Glauber Costa
0545049d59 Implement pragma database_list
And also the CLI option .databases, which is just manipulating that.

This is one step in the road to attach.
2025-07-21 08:49:35 -05:00
Pekka Enberg
fd6fda07ac Merge 'bindings/rust: Initial support for transactions API' from Diego Reis
Closes #2121
There are two important things to point out:
1. The support is incomplete since we yet don't support savepoints in
core.
2. When a txn drops we should call `_finish()` on it, but since async
drop is [unstable](https://github.com/rust-lang/rust/issues/126482) the
best solution that I came up was just forcing the user to explicitly
call `finish()` before any drops.

Closes #2151
2025-07-18 21:02:18 +03:00
Pekka Enberg
c2a8a6f178 Merge 'improve handling of double quotes' from Glauber Costa
I ended up hitting #1974 today and wanted to fix it. I worked with
Claude to generate a more comprehensive set of queries that could fail
aside from just the insert query described in the issue. He got most of
them right - lots of cases were indeed failing. The ones that were
gibberish, he told me I was absolutely right for pointing out they were
bad.
But alas. With the test cases generated, we can work on fixing it. The
place where the assertion was hit, all we need to do there is return
true (but we assert that this is indeed a string literal, it shouldn't
be anything else at this point).
There are then just a couple of places where we need to make sure we
handle double quotes correctly. We already tested for single quotes in a
couple of places, but never for double quotes.
There is one funny corner case where you can just select "col" from tbl,
and if there is no column "col" on the table, that is treated as a
string literal. We handle that too.
Fixes #1974

Closes #2152
2025-07-18 20:55:37 +03:00
Glauber Costa
523f8f9c67 add .dbconfig option
Currently ignored. The reason we are adding it is so that we have
an output that can fit in a single line. This is so we can use it in
tests, and have a predictable output pattern for both sqlite and turso.
2025-07-18 10:25:06 -05:00
Diego Reis
b3c8255032 Fix clippy warnings 2025-07-18 11:26:10 -03:00
Jussi Saurio
1f55726acf claude sonnet forgot to run clippy when implementing mcp server 2025-07-18 17:15:39 +03:00
Glauber Costa
32532b4feb Add a native MCP server
The SQLite command line has facilities to ingest things like csv, and
other formats. But here we are, in 2025, and I asked Claude if Turso's
CLI should, in the same vein, have a native MCP server.

Claude told me: "You're absolutely right!" "That's a great insight!"
"That's a fantastic idea!" and then proceeded to help me with the
boilerplate for this beautiful server.

Rust has a crate, mcp_server, that implements an mcp_server trait.
However, that depends on Tokio, and I think that would bloat our binary
too much.

I have also considered implementing an MCP server that operates on a
directory and allows to list many SQLite files, but figured that would
be a good job for a more advanced and specialized server, not for the
one that comes by default with the CLI. Let's go for simple.
2025-07-17 15:05:29 -05:00
Jussi Saurio
2fbb21fc17 cli: fix not being able to redirect traces to a file from inline query 2025-07-16 13:55:48 +03:00
Jussi Saurio
cc47bfba02 CSV import fixes
- Fix not being able to create table while importing
    * The behavior now aligns with SQLite so that if the table already
      exists, all the rows are treated as data. If the table doesn't exist,
      the first row is treated as the header from which column names for the
      new table are populated.
- Insert in batches instead of one at a time
2025-07-15 16:44:11 +03:00
Pekka Enberg
b13a0bb549 cli: Fail import command if table does not exists
SQLite creates a table if it does not exists, but we just silently
ignore the data. Let's add an error if table does not exist until we fix
this.

Refs #2079
2025-07-14 12:24:58 +03:00
Jussi Saurio
a48b6d049a Another post-rebase clippy round with 1.88.0 2025-07-12 19:10:56 +03:00
Nils Koch
828d4f5016 fix clippy errors for rust 1.88.0 (auto fix) 2025-07-12 18:58:41 +03:00
pedrocarlo
711b1ef114 make all run_once be run under statement or connection so that rollback is called 2025-07-07 11:51:25 -03:00
pedrocarlo
7ec47e90cc turn off tracing by default so that errors are not printed in the cli env is not set 2025-07-07 11:50:21 -03:00
Pekka Enberg
42c08b5bea cli: Add support for .headers command
The `.headers` command takes `on` and `off` as parameter, supported by
SQLite, which controls whether result set header is printed in list mode.
2025-07-07 13:24:45 +03:00
meteorgan
ccfee3f418 disable adaptive colors when output_mode is list 2025-07-03 23:31:51 +08:00
pedrocarlo
191f732088 from_uri was not passing mvcc and indexes flag to database creation for memory path 2025-07-02 13:46:49 -03:00
Pekka Enberg
5de904be47 Merge 'automatically select terminal colors for pretty mode' from Glauber Costa
I just tried turso and couldn't read the last column. Turns out I guess
Pekka's taste is not the best, at least not for everybody.
Auto-detect if terminal is light or dark mode and select colors
accordingly.

Closes #1922
2025-07-02 15:06:37 +03:00
Pekka Enberg
325bd80a86 Merge 'limbo -> turso' from Glauber Costa
Fix user-visible string

Closes #1918
2025-07-02 08:14:20 +03:00
Glauber Costa
808d83d34e automatically select terminal colors for pretty mode
I just tried turso and couldn't read the last column.
Turns out I guess Pekka's taste is not the best, at least not for
everybody.

Auto-detect if terminal is light or dark mode and select colors
accordingly.
2025-07-01 22:01:19 -05:00
Glauber Costa
4655b194c7 limbo -> turso
Fix user-visible string
2025-07-01 16:05:26 -05:00
PThorpe92
bbee10ba2c Add mvcc and index config to connection open api 2025-06-30 22:04:56 -04:00