Commit Graph

7293 Commits

Author SHA1 Message Date
Nikita Sivukhin
405e7f56a6 small adjustments in the sync-engine 2025-08-08 15:40:57 +04:00
Pekka Enberg
ba88d17f29 Turso 0.1.4-pre.5 2025-08-08 13:49:06 +03:00
Pekka Enberg
2f77b5867a Merge 'Rename JavaScript package to ' from Pekka Enberg
Reviewed-by: Nikita Sivukhin (@sivukhin)

Closes #2508
2025-08-08 13:47:51 +03:00
Pekka Enberg
f2b2e4d4d8 Rename JavaScript package to @tursodatabase/database 2025-08-08 13:22:10 +03:00
Pekka Enberg
ad70157e74 Turso 0.1.4-pre.4 2025-08-08 11:54:26 +03:00
Pekka Enberg
5b578dd790 bindings/javascript: Fix "npm publish" to build the package 2025-08-08 11:53:58 +03:00
Pekka Enberg
8d5fb41f5d Turso 0.1.4-pre.3 2025-08-08 10:42:41 +03:00
Pekka Enberg
f7eb6c2cee Turso v0.1.4-pre.3 2025-08-08 10:42:38 +03:00
Pekka Enberg
7a09eb0d4c Merge 'Fix JavaScript bindings packaging' from Nikita Sivukhin
This PR configure `#entry-point` import alias for javascript bindings in
order to use `browser.js` napi-rs generated file in browser context.
Also, this PR forces napi-rs to emit `index.js` entrypoint using ESM and
also use typescript for writing our wrapper code around napi-rs
bindings.
In order to make behaviour consistent when lib is imported through ESM
or CommonJS this PR also replace default export of `Database` by named
on. The problem is that `export default Database` will be logically
equivalent to `modules.export.default = Database` which is not the same
thing as `modules.export = Database` and this will need to access
additional `.default` field with CommonJs style imports (e.g. `new
require('@tursodatabase/turso').default(...)`). In order to remove this
difference - I just replaced default export with named one.

Closes #2488
2025-08-08 10:42:21 +03:00
Nikita Sivukhin
eec679b00b fix package.json one more time 2025-08-08 10:34:11 +04:00
Pekka Enberg
d32b63d135 bindings/javascript: Update yarn lock file 2025-08-08 09:23:19 +03:00
Pekka Enberg
5ef58db941 bindings/javascript: Fix npm run build
Fixes the following error:

```
                This is not the tsc command you are looking for

To get access to the TypeScript compiler, tsc, from the command line either:

- Use npm install typescript to first add TypeScript to your project before using npx
- Use yarn to avoid accidentally running code from un-installed packages
```
2025-08-08 09:22:31 +03:00
Nikita Sivukhin
ba6bf7057e fix package.json 2025-08-08 09:59:52 +04:00
Pekka Enberg
e9f15bfac7 Merge 'Add query only pragma' from bit-aloo
This PR adds support for the PRAGMA `query_only` pragma, which enables
or disables write operations on a database connection. It allows
applications to mark the connection as read-only at runtime.

Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #2498
2025-08-08 08:33:29 +03:00
Pekka Enberg
0f9d0cf519 Merge branch 'main' into 2025-08-07-add-query-only-pragma 2025-08-08 07:41:38 +03:00
bit-aloo
c7f7ae32e3 review fixes 2025-08-08 08:43:15 +05:30
Preston Thorpe
850ee8fe62 Merge 'bench/insert: fix expected return value from pragma' from Jussi Saurio
CI did not fail when this panicked :]

Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #2489
2025-08-07 21:34:13 -04:00
Preston Thorpe
7a793b818d Merge 'perf: a few small insert optimizations' from Jussi Saurio
1. We spend a lot of time in `cell_get_raw_region` in the balancing
routine, and especially calling `contents.page_type()` there a lot, so
extract a version that can take some precomputed arguments so those
don't have to be redundantly computed multiple times for successive
calls where those values are going to be the same
2. Avoid calling `self.usable_space()` in a loop in
`insert_into_page()`.
3. Avoid accessing `pages_in_frames` lock if we're not going to modify
it
main improvement is to the "insert 100 rows" bench which ends up doing
balancing a lot:
```
Insert rows in batches/limbo_insert_1_rows
                        time:   [22.856 µs 24.342 µs 27.496 µs]
                        change: [-3.3579% +15.495% +67.671%] (p = 0.62 > 0.05)
                        No change in performance detected.

Benchmarking Insert rows in batches/limbo_insert_10_rows: Collecting 100 samples in estim
Insert rows in batches/limbo_insert_10_rows
                        time:   [32.196 µs 32.604 µs 32.981 µs]
                        change: [+1.3253% +2.9177% +4.5863%] (p = 0.00 < 0.05)
                        Performance has regressed.

Insert rows in batches/limbo_insert_100_rows
                        time:   [89.425 µs 92.105 µs 96.304 µs]
                        change: [-18.317% -13.605% -9.1022%] (p = 0.00 < 0.05)
                        Performance has improved.
```

Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #2483
2025-08-07 21:33:30 -04:00
Preston Thorpe
6b266e7e84 Merge 'Direct schema mutation – add instruction' from Levy A.
<img width="960" height="205" alt="image" src="https://github.com/user-
attachments/assets/f60a2133-dfe4-4411-9a7c-7283eb073875" />
<img width="944" height="504" alt="image" src="https://github.com/user-
attachments/assets/9383c8e2-4d8d-40b9-8ace-825ca3cf8682" />
```
`ALTER TABLE _ ADD COLUMN _`/limbo_add_column/
                        time:   [2.1199 ms 2.1921 ms 2.2756 ms]
                        change: [-85.983% -85.416% -84.716%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 13 outliers among 100 measurements (13.00%)
  6 (6.00%) high mild
  7 (7.00%) high severe
`ALTER TABLE _ ADD COLUMN _`/sqlite_add_column/
                        time:   [10.358 ms 10.404 ms 10.469 ms]
                        change: [-6.2566% -2.3515% +0.2046%] (p = 0.21 > 0.05)
                        No change in performance detected.
Found 14 outliers among 100 measurements (14.00%)
  2 (2.00%) high mild
  12 (12.00%) high severe
  ```

Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #2482
2025-08-07 21:31:49 -04:00
Preston Thorpe
88d49e402f Merge 'javascript: Organize test cases better' from Pekka Enberg
Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #2490
2025-08-07 21:28:27 -04:00
Preston Thorpe
fbc8a5650a Merge 'Add .clone CLI command to copy database files' from Preston Thorpe
This PR adds support for the  `.clone file.db` sqlite3 CLI command

Closes #2437
2025-08-07 20:20:49 -04:00
bit-aloo
6ffd4215a2 sort Pragma names in lexicographical order 2025-08-08 02:52:45 +05:30
Nikita Sivukhin
cbe0a7708e update tests 2025-08-08 01:21:37 +04:00
PThorpe92
bcadcb2014 Remove RefCell from copy_to method in io trait 2025-08-07 17:07:53 -04:00
Nikita Sivukhin
9b892828eb fix package.json 2025-08-08 01:01:40 +04:00
Nikita Sivukhin
cb84a75ddc remove unnecessary file 2025-08-08 01:00:32 +04:00
Nikita Sivukhin
92f95f2580 update example 2025-08-08 00:48:20 +04:00
Nikita Sivukhin
dd347fb3e3 simplify setup by emiting index.js in ESM style from napi 2025-08-08 00:47:37 +04:00
PThorpe92
98f4e5cd2d Add comment/TODO about method we use to copy the db file 2025-08-07 16:27:08 -04:00
PThorpe92
b131331673 Add shell .py tests for .clone cli command 2025-08-07 16:27:08 -04:00
PThorpe92
e32d04ea97 Use ephemeral PlatformIO for clone method to support memory io 2025-08-07 16:27:08 -04:00
PThorpe92
04b40b4cf5 Impl copy_to for Database impl in JS bindings 2025-08-07 16:27:08 -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
PThorpe92
039fe22405 Add copy_to to io::File trait to support copying DB files 2025-08-07 16:27:02 -04:00
Preston Thorpe
e23637b6ad Merge 'only allow multiples of 64 for performance in arena bitmap' from Preston Thorpe
Trying to support this is unnecessary and just adds branches and bit ops
when we could just round the allocation up or down

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

Closes #2497
2025-08-07 14:25:11 -04:00
bit-aloo
ee483ce4e9 update compat.md with query_only pragma 2025-08-07 23:50:18 +05:30
bit-aloo
aaeec4d4f3 Implement PRAGMA query_only logic 2025-08-07 23:49:07 +05:30
bit-aloo
2cf7f66a02 Enforce query_only in write operations 2025-08-07 23:46:00 +05:30
bit-aloo
ef084af42f Add getter and setter methods 2025-08-07 23:44:54 +05:30
bit-aloo
697eb35ca9 Add query_only field to Connection 2025-08-07 23:44:29 +05:30
PThorpe92
c03ca5701a Dont accept values that are not multiples of 64 for performance in page bitmap 2025-08-07 13:45:07 -04:00
Jussi Saurio
5cafa9b223 Merge 'PageContent: make read_x/write_x methods private and add dedicated methods' from Jussi Saurio
# Note: this pull request is built on top of #2491 so let's merge that
one first.
## Problem:
A very easy source of bugs is to mistakenly use e.g.
`PageContent::read_u16()` instead of
`PageContent::read_u16_no_offset()`. The difference between the two is
that `read_u16()` adds 100 bytes to the requested byte offset if and
only if the page in question is page 1, which contains a 100-byte
database header.
Case in point about this being easy to misuse: see #2491.
## Observation:
In all of the cases where we want to read from or write to a page
"header-sensitively" (taking the possible db header into account), those
reads/writes are to statically known offsets, e.g. specific known bytes
in a btree page header.
In all other cases, the "no-offset" versions, i.e. the ones taking the
absolute byte offset as parameter, should be used - the common use cases
for these are reading/writing to some absolute offset that you just read
from another location on a page, for example. Another use case is
writing to specific offsets on overflow pages and freelist pages, which
we can in the future expose more methods for, but right now they can
always use the "no offset" versions safely, because neither of those
page types can ever be page 1.
## Solution:
1. Make all the offset-sensitive versions (`read_u16()` and friends)
private methods of `PageContent`.
2. Expose dedicated public methods for things like updating rightmost
pointer, updating fragmented bytes count and so on, and use them instead
of the plain read/write methods universally.
## Follow-up:
I will perhaps follow this up with a renaming PR that renames
`read_xxx_no_offset()` to just `read_xxx()` and gives the private
header-sensitive methods new names.

Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #2493
2025-08-07 17:58:49 +03:00
Jussi Saurio
aea6d942d6 bench/insert: fix expected return value from pragma 2025-08-07 17:44:46 +03:00
Levy A.
658405d6b3 feat: add AddColumn instruction 2025-08-07 11:43:16 -03:00
Pekka Enberg
ec69f40675 Merge 'SQLite C API improvements: add basic bind and column functions' from Danawan Bimantoro
Add support for more of the SQLite C API.
Bind functions:
* bind_parameter_count
* bind_parameter_name
* bind_null
* bind_int
* bind_int64
* bind_double
Column functions:
* column_count
* column_name
* column_int
* column_double
* last_insert_rowid

Closes #2494
2025-08-07 17:32:19 +03:00
Nikita Sivukhin
b8f2ff293b set more fresh lib version 2025-08-07 18:21:29 +04:00
Jussi Saurio
1fe32dadf3 PageContent: make read_x/write_x methods private and add dedicated methods
Problem:

A very easy source of bugs is to mistakenly use e.g. PageContent::read_u16()
instead of PageContent::read_u16_no_offset(). The difference between the two
is that `read_u16()` adds 100 bytes to the requested byte offset if and only if
the page in question is page 1, which contains a 100-byte database header.

Case in point: see #2491.

Observation:

In all of the cases where we want to read from or write to a page  "header-sensitively",
those reads/writes are to so-called "well known offsets", e.g. specific bytes in a btree
page header.

In all other cases, the "no-offset" versions, i.e. the ones taking the absolute byte offset
as parameter, should be used.

Solution:

1. Make all the offset-sensitive versions (read_u16() and friends) private methods of
`PageContent`.
2. Expose dedicated methods for things like updating rightmost pointer, updating fragmented
bytes count and so on, and use them instead of the plain read/write methods universally.
2025-08-07 17:00:06 +03:00