Commit Graph

3486 Commits

Author SHA1 Message Date
Pekka Enberg
1f29e1fe08 Add PyPI link to README 2025-03-25 09:49:44 +02:00
Pekka Enberg
b507ac401d Merge 'Fix a typo in README.md' from Tshepang Mbambo
Closes #1173
2025-03-25 09:31:05 +02:00
Pekka Enberg
93c0a29611 Merge 'Fix platform specific FFI C pointer type casts' from Preston Thorpe
Fixes #1159

Closes #1170
2025-03-25 09:10:16 +02:00
Pekka Enberg
731c3f037a Merge 'Improve Python bindings' from Diego Reis
Yet another PR to close #494.
While testing the code provided in the issue I noticed that it wasn't
closing the connection as it should, leading to lifetime issues like:
`Connection is unsendable, but is being dropped on another thread`. The
following code works fine:
```python
import limbo

def main():
    con = limbo.connect("test.db")
    cur = con.cursor()

    try:
        cur.execute("""
            CREATE TABLE IF NOT EXISTS users (
                id INTEGER PRIMARY KEY AUTOINCREMENT,
                username TEXT NOT NULL,
                email TEXT NOT NULL,
                role TEXT NOT NULL,
                created_at DATETIME NOT NULL DEFAULT (datetime('now'))
            )
        """)

        # Insert some sample data
        sample_users = [
            ("alice", "alice@example.com", "admin"),
            ("bob", "bob@example.com", "user"),
            ("charlie", "charlie@example.com", "moderator"),
            ("diana", "diana@example.com", "user")
        ]

        for username, email, role in sample_users:
            cur.execute("""
                INSERT INTO users (username, email, role)
                VALUES (?, ?, ?)
            """, (username, email, role))

        con.commit()

        # Query the table
        res = cur.execute("SELECT * FROM users")
        record = res.fetchone()
        print(record)

    finally:
        # Ensure connection is closed on the same thread <----
        con.close()
        pass

main()
```
You can test it [here](https://colab.research.google.com/drive/1NJau6Y9H
TRJrnYK_xp2AzwP_qEH8VsQx?usp=sharing)
To address these issues, this PR:
- Adds support for `with statement` a common resource management pattern
in Python;
- Close connection if it is dropped

Closes #1164
2025-03-25 09:08:01 +02:00
Tshepang Mbambo
8b48c4b7b7 readme: typo 2025-03-25 09:06:40 +02:00
PThorpe92
e9420e7d2b Fix platform specific ffi c ptr types 2025-03-24 22:48:07 -04:00
Diego Reis
160d48d34e ext/python: Workaround to file permission error
To get more info see:
https://github.com/tursodatabase/limbo/actions/runs/14039536389/job/39312362848
2025-03-24 16:39:24 -03:00
Diego Reis
6edf3dd3b1 ext/python: Makes linter happy 2025-03-24 12:40:59 -03:00
Diego Reis
9a8970b6a8 ext/python: Update example 2025-03-24 12:21:30 -03:00
Diego Reis
ab8187f4e6 ext/python: Gracefully close connection by closing it at Drop 2025-03-24 12:21:15 -03:00
Diego Reis
4ca5b11bed ext/python: Add support for Context Manager 2025-03-24 12:20:13 -03:00
Pekka Enberg
6798341b05 github: Don't close issues as stale so aggressively 2025-03-24 11:49:13 +02:00
Pekka Enberg
a9099cd6a5 Merge 'Schema translation cleanups' from Pekka Enberg
Closes #1161
2025-03-24 11:09:08 +02:00
Pekka Enberg
c5cdc859af Merge 'core: Fix Destroy opcode root page handling' from Pekka Enberg
The `p1` register points to the root page, not to a cursor.
Fixes #1136

Closes #1162
2025-03-24 11:09:00 +02:00
Pekka Enberg
65bf33023c core: Fix Destroy opcode root page handling
The `p1` register points to the root page, not to a cursor.

Fixes #1136
2025-03-24 10:54:49 +02:00
Pekka Enberg
0ec7dbc44e core: Move translate_create_table() to schema module 2025-03-24 10:44:41 +02:00
Pekka Enberg
0727f4aca6 core: Move temporary table handling to translate_create_table() 2025-03-24 10:38:55 +02:00
Pekka Enberg
7d4ac13926 core: Move translate_drop_table() to schema module 2025-03-24 10:37:02 +02:00
Pekka Enberg
31bbc5144a Merge 'Initial pass at UPDATE support' from Preston Thorpe
This PR is to support `Update` queries. Follows sqlite behavior as much
as possible.
### limbo
```console
limbo> create table t (a,b,c);
limbo> explain update t set a = 1 where b = 2;
addr  opcode             p1    p2    p3    p4             p5  comment
----  -----------------  ----  ----  ----  -------------  --  -------
0     Init               0     18    0                    0   Start at 18
1     OpenWriteAsync     0     2     0                    0
2     OpenWriteAwait     0     0     0                    0
3     RewindAsync        0     0     0                    0
4     RewindAwait        0     17    0                    0   Rewind table t
5       Column           0     1     4                    0   r[4]=t.b
6       Ne               4     5     15                   0   if r[4]!=r[5] goto 15
7       RowId            0     6     0                    0   r[6]=t.rowid
8       IsNull           6     17    0                    0   if (r[6]==NULL) goto 17
9       Integer          1     1     0                    0   r[1]=1
10      Column           0     1     2                    0   r[2]=t.b
11      Column           0     2     3                    0   r[3]=t.c
12      MakeRecord       1     3     7                    0   r[7]=mkrec(r[1..3])
13      InsertAsync      0     7     6                    0
14      InsertAwait      0     0     0                    0
15    NextAsync          0     0     0                    0
16    NextAwait          0     5     0                    0
17    Halt               0     0     0                    0
18    Transaction        0     1     0                    0   write=true
19    Integer            2     5     0                    0   r[5]=2
20    Goto               0     1     0                    0
```
### sqlite
```console
sqlite> explain update t set a = 1 where b = 2;
addr  opcode         p1    p2    p3    p4             p5  comment
----  -------------  ----  ----  ----  -------------  --  -------------
0     Init           0     15    0                    0   Start at 15
1     Null           0     1     2                    0   r[1..2]=NULL
2     Noop           1     0     1                    0
3     OpenWrite      0     2     0     2              0   root=2 iDb=0; t
4     Rewind         0     14    0                    0
5       Column         0     1     5                    0   r[5]= cursor 0 column 1
6       Ne             6     13    5     BINARY-8       81  if r[5]!=r[6] goto 13
7       Rowid          0     2     0                    0   r[2]= rowid of 0
8       IsNull         2     14    0                    0   if r[2]==NULL goto 14
9       Integer        1     3     0                    0   r[3]=1
10      Column         0     1     4                    0   r[4]= cursor 0 column 1
11      MakeRecord     3     2     1                    0   r[1]=mkrec(r[3..4])
12      Insert         0     1     2     t              7   intkey=r[2] data=r[1]
13    Next           0     5     0                    1
14    Halt           0     0     0                    0
15    Transaction    0     1     1     0              1   usesStmtJournal=0
16    Integer        2     6     0                    0   r[6]=2
17    Goto           0     1     0                    0
```

Closes #1130
2025-03-24 09:19:22 +02:00
Pekka Enberg
e8c0a6e728 Merge 'Various JSON improvements' from Ihor Andrianov
Added jsonb_object, jsonb_array, json_insert, jsonb_insert.
MongoDB is sweating now.

Closes #1160
2025-03-24 09:17:40 +02:00
Pekka Enberg
2bbc2b15bd Merge 'Fix SELECT 0.0 = 0 returning false' from lgualtieri75
Fixes #1155

Closes #1158
2025-03-24 08:49:09 +02:00
PThorpe92
a0188e5163 Use bind_col_refs to rewrite the Id expressions 2025-03-23 22:18:41 -04:00
PThorpe92
2dec7b7255 Add more test cases for update 2025-03-23 20:12:10 -04:00
PThorpe92
4067c98848 Adjust update tests, remove unsupported syntax 2025-03-23 19:20:45 -04:00
PThorpe92
1202653e76 Use normal conditional translation for update where clause 2025-03-23 19:20:14 -04:00
PThorpe92
3597b32e4b Resolve ambiguous columns in expr translator 2025-03-23 19:19:35 -04:00
PThorpe92
8455f612bd Possibly translate both sides of expr in update 2025-03-23 17:08:15 -04:00
PThorpe92
8f469f26b6 Add some additional tcl tests for update support 2025-03-23 17:08:15 -04:00
PThorpe92
a1d5797f90 Update COMPAT.md 2025-03-23 17:08:15 -04:00
PThorpe92
dbfe94d677 Add initial tests for update support 2025-03-23 17:08:15 -04:00
PThorpe92
c83cc6dff2 Small nits/clippy errors in vdbe 2025-03-23 17:08:15 -04:00
PThorpe92
676ddd4fb6 Add logic to handle overwrite cell if insert to same rowid to support update 2025-03-23 17:08:14 -04:00
PThorpe92
ef878a2e20 Begin update implementation, add translation 2025-03-23 17:08:14 -04:00
Ihor Andrianov
b7be728d64 fix copypaste typo 2025-03-23 21:15:29 +02:00
Ihor Andrianov
479dd9c35a clippy 2025-03-23 21:11:35 +02:00
Ihor Andrianov
7710081796 update compat for json functions 2025-03-23 20:59:19 +02:00
Ihor Andrianov
2cab36bfc3 add json_replace, jsonb_replace 2025-03-23 20:52:03 +02:00
Ihor Andrianov
c4549ad2cd split json traversal and mutation operation logic 2025-03-23 20:37:12 +02:00
l.gualtieri
a9ad5a56b9 fix bug #1155 2025-03-23 16:51:10 +01:00
Pekka Enberg
63630ff956 Merge 'Enable pretty mode in shell by default' from Pekka Enberg
Fixes #929

Closes #932
2025-03-22 08:20:09 +02:00
Pekka Enberg
7832ae22df Enable pretty mode in shell by default
Fixes #929
2025-03-22 08:10:26 +02:00
Pekka Enberg
669317c11e Limbo 0.18.0-pre.3 2025-03-21 20:13:00 +02:00
Pekka Enberg
2a257b4f9c Merge 'Improve CLI color scheme' from Pekka Enberg
...let's aim for a green color scheme that is easy on the eyes.

Closes #1153
2025-03-21 19:36:24 +02:00
Pekka Enberg
95abf0a9b2 Improve CLI color scheme
...let's aim for a green color scheme that is easy on the eyes.
2025-03-21 19:21:25 +02:00
Pekka Enberg
52ccc36061 Merge 'Impl Copy on some types in the pager to prevent explicit clones' from Preston Thorpe
Tried to keep this as small and focused as possible, just a few that I
ran into while debugging the page cache

Closes #1107
2025-03-21 18:40:14 +02:00
Pekka Enberg
26a9f24e2f Merge 'Syntax highlighting and hinting' from Pedro Muniz
Start of syntax highlighting and hinting. Still need to figure out how
to sublime-syntax works to produce good highlights.
Edit:
Personally, I believe there are more interesting syntax highlighting
possibilities with `reedline` crate, but currently, we cannot use it as
the our DB `Connection` would have to be `Send`. This PR is an
introduction and quality of life changes for the users of the CLI and
for us developers, as we now won't have to look at black and white text
only. I want to have a config file to personalize the color pallets,
that will be made in a following PR.

Closes #1101
2025-03-21 18:17:47 +02:00
Pekka Enberg
5f8f80fb13 Merge 'bindings/python: Fix flaky tests' from Diego Reis
Just following best practices and making each test idempotent and
independent of each other.

Closes #1152
2025-03-21 18:07:08 +02:00
Diego Reis
2ee934577f ext/python: Close connection after each test 2025-03-21 12:02:27 -03:00
Diego Reis
3c2bb6c3a8 ext/python: Fix flaky tests by creating a new db for each test and removing it after the test 2025-03-21 11:33:24 -03:00
Pekka Enberg
c77210aa63 Update COMPAT.md 2025-03-21 13:08:48 +02:00