Commit Graph

2308 Commits

Author SHA1 Message Date
김선우
94dff512c9 Add makefile commands to build for mac and windows 2025-02-02 12:24:04 +09:00
Pekka Enberg
51f0c9e8a3 Merge 'Full flake overhaul' from Levy A.
Improvements:
- Use [rust-overlay](https://github.com/oxalica/rust-overlay), better
maintained than fenix and allows for:
- Use `rust-toolchain.toml` as the source of truth for the current rust
version, instead of tracking with stable. Preventing conflicting
versions with non-nix users.
- Add flake checks, could be useful for CI in the future, together with
crane and cachix.
- Add package, allow people to add limbo as a regular nix package. Now
we can `nix build .#`, `nix run .#` and `nix shell .#` (this one adds
`limbo` to the current `PATH`)
- Use [new `apple-sdk` pattern](https://discourse.nixos.org/t/the-
darwin-sdks-have-been-updated/55295), no need to declare each framework
now.

Closes #835
2025-02-01 10:34:21 +02:00
Pekka Enberg
a450b5cd39 Update README.md 2025-02-01 09:46:21 +02:00
Pekka Enberg
8c4ef098ef Update README.md 2025-02-01 09:42:13 +02:00
Pekka Enberg
e7f18c4736 Merge 'bindings/go: Progress on Go driver, add sync primitives, prevent crashing on concurrent connections' from Preston Thorpe
This PR continues work on the Go bindings.
- Register all symbols from the library at load time to prevent any
repeated `dlsym` calls.
- Add locks to prevent multiple concurrent FFI calls to functions that
act on the same state.
- Adds documentation/example in the go module `README`.
- Fixes memory access issue causing segfault due to passing pointer to
array of strings, that is difficult to work with in Go without the right
primitives. In place, simply return the amount of ResultColumns and Go
can provide the index to receive the column name, similar to
`rowsGetValue`
On next limbo release, I'll add the example to the main `README` next to
the other language examples. Until then, `go get
github.com/tursodatabase/limbo` will not work so the example will remain
in the bindings readme.

Closes #845
2025-02-01 09:25:52 +02:00
Pekka Enberg
43d6c2760d Merge 'update compat list' from Glauber Costa
Those two expr seem to be supported

Closes #846
2025-02-01 09:24:27 +02:00
Pekka Enberg
db29f43d5c Merge 'Simplify bytecode emitters' from Glauber Costa
Instead of always having the caller specify all instructions, this
    work introduces convenience functions into the program builder,
    making the code a lot cleaner.
    Draft for now, as this is done on top of #841

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

Closes #844
2025-02-01 09:24:11 +02:00
Pekka Enberg
76535d1224 Merge 'github: Configure labeler workflow environment' from Pekka Enberg
This fix was suggested by @seonWKim.

Closes #848
2025-02-01 09:23:53 +02:00
Pekka Enberg
a3ecc69bbb github: Configure labeler workflow environment
This fix was suggested by @seonWKim.
2025-02-01 09:22:17 +02:00
PThorpe92
7ee52fca4d bindings/go: update readme with example, change module name 2025-01-31 19:22:21 -05:00
Glauber Costa
7e8b190b9a update compat list
Those two expr seem to be supported
2025-01-31 16:56:19 -05:00
PThorpe92
8d93130809 bindings/go: enable multiple connections, register all symbols at library load 2025-01-31 13:28:05 -05:00
PThorpe92
950f29daab bindings/go: Adjust tests for multiple concurrent connections 2025-01-31 13:28:05 -05:00
Pekka Enberg
98579ab2e4 Merge 'Implement Noop bytecode' from Pedro Muniz
This PR implements Noop. I really don't know what else to say. This
bytecode according to sqlite does: _Do nothing. Continue downward to the
next opcode._ I advanced the program counter to account for continuing
to the next instruction.

Closes #795
2025-01-31 18:49:54 +02:00
Pekka Enberg
44e5402464 Merge branch 'main' into feature/noop 2025-01-31 18:49:39 +02:00
Glauber Costa
7aa3cc26ad simplify the writing of bytecode programs
Instead of always having the caller specify all instructions, this
work introduces convenience functions into the program builder,
making the code a lot cleaner.
2025-01-31 11:35:51 -05:00
Glauber Costa
b37317f68b avoid allocations during pragma_list
If we keep the pragma list sorted when declaring it, we can avoid
a vector allocation when printing the pragma_list.
2025-01-31 11:35:51 -05:00
Pekka Enberg
d8a9c57d3a Merge 'Fix table with single column PRIMARY KEY to not create extra btree' from Krishna Vishal
The error is due to comparing the PRIMARY KEY's name to INTEGER when in
it was all in lowercase. This was causing `needs_auto_index` to be set
to `true`.
After the fix:
```
/limbo /tmp/sc2-limbo.db
Limbo v0.0.13
Enter ".help" for usage hints.
limbo> CREATE TABLE temp (t1 integer, primary key (t1));

hexdump -s 28 -n 4 /tmp/sc2-limbo.db
000001c 0000 0200 -- matches SQLite
0000020
```
Closes https://github.com/tursodatabase/limbo/issues/824

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

Closes #830
2025-01-31 18:33:28 +02:00
Pekka Enberg
c05b81fdbd Merge 'Pragma list' from Glauber Costa
Closes #841
2025-01-31 18:32:21 +02:00
Glauber Costa
a7cc367c1f implement pragma pragma_list
List all available pragmas (Except pragma_list)
2025-01-31 06:44:56 -05:00
Glauber Costa
62efbde661 use strum package to simplify PragmaName enum management
The pragma list will only grow. The strum crate can be used to:
* automatically convert to string from enum
* automatically convert to enum from string
* implement an iterator over all elements of the enum
2025-01-31 06:44:56 -05:00
Pekka Enberg
e96b649a1a Merge 'github: Use only Python 3.13 for pull request runs' from Pekka Enberg
...speeds up PR cycle time by not running on all the possible Python
configurations all the time.

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

Closes #840
2025-01-31 11:41:26 +02:00
Pekka Enberg
3398252ca0 github: Use only Python 3.13 for pull request runs
...speeds up PR cycle time by not running on all the possible Python
configurations all the time.
2025-01-31 11:31:04 +02:00
Pekka Enberg
7f0274e48f Merge 'Table info' from Glauber Costa
This implements the table_info pragma, allowing us to fetch information
about columns present in a table.

Closes #837
2025-01-31 08:46:27 +02:00
Pekka Enberg
053a1acef1 Merge 'Refactor cursor to support multiple state machines' from Alex Miller
This is mostly refactoring Cursor.write_info to instead be an enum,
where one of the options is a WriteInfo.  This permits one to add other
state machines to Cursor, and I added the state needed for Count as an
example, but all the testing for count's implementation depends on
ANALYZE #656 working end-to-end (to some degree) so that one can write a
SQL test for it.
But this code seems conflict-prone, so it seems better to get it in
sooner than later.
I also finally understood what the point of RefCell is from fighting
with rust on this, so that was nice.

Closes #836
2025-01-31 08:45:01 +02:00
Pekka Enberg
a94cd03dfb Merge 'Performance test side by side comparison with rusqlite' from Levy A.
More convenient side by side comparison with sqlite.  Got this idea from
[criterion's documentation](https://bheisler.github.io/criterion.rs/book
/user_guide/comparing_functions.html). Some examples:
<img width="1010" alt="image" src="https://github.com/user-
attachments/assets/1cb400f6-f6a5-44af-a429-8e09a42dcd0d" />
<img width="1002" alt="image" src="https://github.com/user-
attachments/assets/ef35dfa6-6474-4fec-9b78-d81b274f2ca1" />

Closes #839
2025-01-31 08:44:07 +02:00
Pekka Enberg
de45ca82e4 github: Switch labeler to use GH_TOKEN
GITHUB_TOKEN is restricted to read-only by organization rules.
2025-01-31 08:42:24 +02:00
Levy A.
5acd7a5ea8 side by side comparison with sqlite 2025-01-31 03:11:07 -03:00
krishvishal
8b2393fcef Check for if a column is in descending order to add an automatic primary key index. 2025-01-31 08:25:54 +05:30
Glauber Costa
016b815b59 implement pragma table_info
Both () and = variants covered. It is important to make sure that
the transaction is a read transaction, so we cannot hide all that logic
inside update_pragma, and have to make our decision before that.
2025-01-30 20:00:20 -05:00
Glauber Costa
249a8cf8d2 keep type information as a string in column metadata
SQLite holds on to it deeply, for example:

sqlite> create table a(a int);
sqlite> create table b(b integer);
sqlite> create table c(c glauber);

sqlite> pragma table_info=a;
0|a|INT|0||0
sqlite> pragma table_info=b;
0|b|INTEGER|0||0
sqlite> pragma table_info=c;
0|c|glauber|0||0

So we'll keep it as well so we can produce the same responses.
2025-01-30 19:53:36 -05:00
Glauber Costa
f1df43633a change type Display implementation to not show null
This is the behavior that things like pragma table_info seem to
expect.
2025-01-30 19:53:36 -05:00
Alex Miller
9ac52b66d9 Refactor cursor to support multiple state machines 2025-01-30 14:08:44 -08:00
Glauber Costa
69d3fbc797 keep track of notnull constraint on column creation 2025-01-30 17:04:12 -05:00
Glauber Costa
42f93e9bea add default type to Column definition 2025-01-30 16:45:57 -05:00
Levy A.
04c4cbe3e0 refator+feat: full flake overhaul 2025-01-30 18:24:19 -03:00
Pekka Enberg
d25ccf0e06 Merge 'bindings/go Support blob types in query arguments, free non-gc allocations' from Preston Thorpe
This PR fixes/adds support for the Blob type and adds the appropriate
tests.
Types created on the Go side will be cleaned up rather quickly if
nothing is referencing them, so this approach uses `runtime.Pinner` to
pin the bytes in memory so the pointers will be valid when Rust uses
`from_raw_parts` and then owns a new vec. They are then cleaned up after
the FFI call with `pinner.Unpin`.

Closes #822
2025-01-30 21:12:22 +02:00
Pekka Enberg
c7c3461daa Merge 'add compat statement about CreateBTree opcode' from Glauber Costa
It is partially supported - only on the existing database.

Closes #833
2025-01-30 21:11:41 +02:00
Pekka Enberg
d558f6aca8 Merge 'Make query_pragma use enum instead of &str' from Glauber Costa
Fixes #823

Closes #834
2025-01-30 21:11:18 +02:00
Glauber Costa
7a972318a8 Make query_pragma use enum instead of &str
Fixes #823
2025-01-30 14:06:17 -05:00
Glauber Costa
598f793581 add compat statement about CreateBTree opcode
It is partially supported - only on the existing database.
2025-01-30 12:52:04 -05:00
krishvishal
6f32344efb Make comparison of type_name case insensitive by converting to uppercase 2025-01-30 17:05:14 +05:30
Pekka Enberg
3a4cb34606 Merge 'Fix memory leaks, make extension types more efficient' from Preston Thorpe
I was baffled previously, because any time that `free` was called on a
type from an extension, it would hang even when I knew it wasn't in use
any longer, and hadn't been double free'd.
After #737 was merged, I tried it again and noticed that it would no
longer hang... but only for extensions that were staticly linked.
Then I realized that we are using a global allocator, that likely wasn't
getting used in the shared library that is built separately that won't
inherit from our global allocator in core, causing some symbol mismatch
and the subsequent hanging on calls to `free`.
This PR adds the global allocator to extensions behind a feature flag in
the macro that will prevent it from being used in `wasm` and staticly
linked environments where it would conflict with limbos normal global
allocator. This allows us to properly free the memory from returning
extension functions over FFI.
This PR also changes the Extension type to a union field so we can store
int + float values inline without boxing them.
any additional tips or thoughts anyone else has on improving this would
be appreciated 👍

Closes #803
2025-01-30 13:31:17 +02:00
Pekka Enberg
c779537f2f Merge 'Strftime compatibility solved' from Pedro Muniz
This PR closes #787. Chrono offers to format the string from an iterator
of Format Items. I created a custom iterator that only allows formatters
specified by sqlite. This approach however does not address the
inefficient way that julianday is calculated. Also, with this
implementation we avoid having to maintain a separate vendored package
for strftime that may become incompatible with Chrono in the future.

Closes #792
2025-01-30 13:30:11 +02:00
Pekka Enberg
e66648beb8 Merge 'Add support for offset in select queries' from Ben Li
#739
Started adding support for `LIMIT...OFFSET...`
- New `OffsetLimit` opcode
- `OFFSET` is now supported for:
    - `SELECT...LIMIT...OFFSET`
    - `SELECT...GROUP BY...LIMIT...OFFSET`
    - `SELECT...ORDER BY...LIMIT...OFFSET`
    - Subqueries for `SELECT` statements
**In progress/todo**
- [x] Testing
- [x] Handle negative offset value
- **(will make in separate PR)** Add support for
`DELETE...LIMIT...OFFSET`
- **(will make in separate PR)** Use `limit + offset` sum register from
`OffsetLimit` to constrain number of records inserted into sorter

Closes #779
2025-01-30 13:29:49 +02:00
Pekka Enberg
5614a7751c Merge 'implement isnull / not null for filter expressions' from Glauber Costa
Allow us to write queries like:
        SELECT name, type, sql FROM sqlite_schema where sql isnull
and
        SELECT name, type, sql FROM sqlite_schema where sql not null

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

Closes #829
2025-01-30 13:28:53 +02:00
Pekka Enberg
a2ac3132c4 Merge 'Fix SELECT ABS(-9223372036854775808) causes limbo to panic. ' from Krishna Vishal
Now we return `RuntimeError`.  Matches SQLite behavior.
SQLite:
```sql
sqlite> SELECT ABS(-9223372036854775808);
Runtime error: integer overflow
```
Limbo after this fix:
```sql
limbo> SELECT ABS(-9223372036854775808);
Runtime error: integer overflow
```
Closes https://github.com/tursodatabase/limbo/issues/815

Closes #818
2025-01-30 13:25:39 +02:00
Pekka Enberg
4673ac969e Merge 'Fix SELECT -9223372036854775808 result differs from SQLite' from Krishna Vishal
Closes #812
`-9223372036854775808` is `MIN_INT64`. So when we extract out the minus
and try to parse the remainder it becomes greater than MAX_INT64
(9223372036854775807) and will trigger overflow, which converts the
literal into `Real`. So we have to handle it as a special case.

Reviewed-by: Kim Seon Woo (@seonWKim)

Closes #814
2025-01-30 13:25:27 +02:00
Pekka Enberg
4a0701794c Merge 'json_remove() function implementation' from Ihor Andrianov
Uses already implemented json path parser so shares limitations with
json_extract()

Closes #828
2025-01-30 13:24:59 +02:00
Pekka Enberg
c4bab1297d Merge 'Fix labeler.yml ' from Kim Seon Woo
## Changes
- labeler@v4 -> labeler@v5
- GH_TOKEN -> GITHUB_TOKEN
- add sparse checkout action(to properly read `.github/labeler.yml`)
- fix `.github/labeler.yml` which is where the configurations go
## Reference
- Tests in my forked repository
![image](https://github.com/user-
attachments/assets/49ed8e96-7bc9-419b-beca-e838c86fb2d7)
![image](https://github.com/user-
attachments/assets/cab87024-933c-4eb6-a025-c2f8faf0af2f)

Closes #825
2025-01-30 13:24:15 +02:00