diff --git a/Cargo.lock b/Cargo.lock index 9c73801..b47a7ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,9 +14,9 @@ dependencies = [ [[package]] name = "aegis" -version = "0.9.0" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2a1c2f54793fee13c334f70557d3bd6a029a9d453ebffd82ba571d139064da8" +checksum = "eb210c8891f193d75feaec2704b8be91d352407dc1c1a083382e210b5a79f7be" dependencies = [ "cc", "softaes", @@ -65,6 +65,12 @@ dependencies = [ "libc", ] +[[package]] +name = "arc-swap" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" + [[package]] name = "autocfg" version = "1.5.0" @@ -113,11 +119,17 @@ dependencies = [ "syn", ] +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "cc" -version = "1.2.35" +version = "1.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "590f9024a68a8c40351881787f1934dc11afd69090f5edb6831464694d836ea3" +checksum = "35900b6c8d709fb1d854671ae27aeaa9eec2f8b01b364e1619a40da3e6fe2afe" dependencies = [ "find-msvc-tools", "jobserver", @@ -258,6 +270,12 @@ dependencies = [ "syn", ] +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + [[package]] name = "env_filter" version = "0.1.3" @@ -301,9 +319,9 @@ checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "find-msvc-tools" -version = "0.1.0" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e178e4fba8a2726903f6ba98a6d221e76f9c12c650d5dc0e6afdc50677b49650" +checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127" [[package]] name = "form_urlencoded" @@ -557,15 +575,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "julian_day_converter" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2987f71b89b85c812c8484cbf0c5d7912589e77bfdc66fd3e52f760e7859f16" -dependencies = [ - "chrono", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -858,37 +867,16 @@ version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha 0.3.1", - "rand_core 0.6.4", -] - [[package]] name = "rand" version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" dependencies = [ - "rand_chacha 0.9.0", + "rand_chacha", "rand_core 0.9.3", ] -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core 0.6.4", -] - [[package]] name = "rand_chacha" version = "0.9.0" @@ -955,6 +943,22 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "caf4aa5b0f434c91fe5c7f1ecb6a5ece2130b02ad2a590589dda5146df959001" +[[package]] +name = "roaring" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f08d6a905edb32d74a5d5737a0c9d7e950c312f3c46cb0ca0a2ca09ea11878a0" +dependencies = [ + "bytemuck", + "byteorder", +] + +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + [[package]] name = "rustix" version = "1.0.8" @@ -1027,6 +1031,15 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "simsimd" +version = "6.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b631147f2632f13d5696fb53481608187db60bd52832698ac7361aae35f34564" +dependencies = [ + "cc", +] + [[package]] name = "smallvec" version = "1.15.1" @@ -1283,24 +1296,23 @@ dependencies = [ [[package]] name = "turso_core" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ab355998396c7f77fcefc4824f478f72a2a878341fe8ce6fb798f84fadaf91" +version = "0.4.0-pre.1" +source = "git+https://github.com/tursodatabase/turso?rev=a47ac6cb96fbfcbaa19ee1d4eeb2fe8b54803901#a47ac6cb96fbfcbaa19ee1d4eeb2fe8b54803901" dependencies = [ "aegis", "aes", "aes-gcm", + "arc-swap", "bitflags", "built", "bytemuck", "cfg_block", "chrono", "crossbeam-skiplist", + "either", "fallible-iterator", - "getrandom 0.2.16", "hex", "intrusive-collections", - "julian_day_converter", "libc", "libloading", "libm", @@ -1309,11 +1321,14 @@ dependencies = [ "parking_lot", "paste", "polling", - "rand 0.8.5", + "rand", "regex", "regex-syntax", + "roaring", + "rustc-hash", "rustix", "ryu", + "simsimd", "strum", "strum_macros", "tempfile", @@ -1329,9 +1344,8 @@ dependencies = [ [[package]] name = "turso_ext" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cae23b5c335a8b41a87a1d0ec36dc6fbdd59a7762a876a9f55cf02bff1783c3" +version = "0.4.0-pre.1" +source = "git+https://github.com/tursodatabase/turso?rev=a47ac6cb96fbfcbaa19ee1d4eeb2fe8b54803901#a47ac6cb96fbfcbaa19ee1d4eeb2fe8b54803901" dependencies = [ "chrono", "getrandom 0.3.3", @@ -1340,9 +1354,8 @@ dependencies = [ [[package]] name = "turso_macros" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86389932a86a93d5a7c6e4193bd942cbc5c65b7be30a27579f2ce5a164861515" +version = "0.4.0-pre.1" +source = "git+https://github.com/tursodatabase/turso?rev=a47ac6cb96fbfcbaa19ee1d4eeb2fe8b54803901#a47ac6cb96fbfcbaa19ee1d4eeb2fe8b54803901" dependencies = [ "proc-macro2", "quote", @@ -1351,9 +1364,8 @@ dependencies = [ [[package]] name = "turso_parser" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9474726bd5570672c221ac1e90f6720979a7b43f2285d0788744c8d36a4245b" +version = "0.4.0-pre.1" +source = "git+https://github.com/tursodatabase/turso?rev=a47ac6cb96fbfcbaa19ee1d4eeb2fe8b54803901#a47ac6cb96fbfcbaa19ee1d4eeb2fe8b54803901" dependencies = [ "bitflags", "miette", @@ -1369,7 +1381,7 @@ version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ea3136b675547379c4bd395ca6b938e5ad3c3d20fad76e7fe85f9e0d011419c" dependencies = [ - "rand 0.9.2", + "rand", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 8c38e5c..f22197a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,5 +14,5 @@ path = "rs_src/lib.rs" env_logger = { version = "0.11.6", default-features = false } tracing = "0.1.41" tracing-appender = "0.2.3" -tracing-subscriber = {version = "0.3.20", features = ["env-filter"] } -turso_core = { version = "0.2.0" } +tracing-subscriber = { version = "0.3.20", features = ["env-filter"] } +turso_core = { git = "https://github.com/tursodatabase/turso", rev = "a47ac6cb96fbfcbaa19ee1d4eeb2fe8b54803901" } diff --git a/VERSION b/VERSION index df5b34b..1bf3789 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0270d9e1 \ No newline at end of file +800f49bd diff --git a/connection.go b/connection.go index 7bc253e..6937c38 100644 --- a/connection.go +++ b/connection.go @@ -447,6 +447,11 @@ func (tx *tursoTx) Commit() error { defer stmt.Close() _, err := stmt.Exec(nil) + if err != nil { + if connErr := tx.conn.getError(); connErr != nil { + err = connErr + } + } return err } diff --git a/libs/MANIFEST-SHA256.txt b/libs/MANIFEST-SHA256.txt index 8734b98..13e738b 100644 --- a/libs/MANIFEST-SHA256.txt +++ b/libs/MANIFEST-SHA256.txt @@ -1,7 +1,7 @@ -4d9eefabfbe73acd0689338b02ef0cfad60af67a698d941e55347e86b3455fef linux_amd64/libturso_go.so -79563841b65d818d4a62eecfcc56ebe26ef3d3dc26599996af48a6dddf77ccdd linux_arm64/libturso_go.so -7778ae2d0580d92cedbc00e96af8bbb86b3b88733370134b6c4788d389f3e003 darwin_amd64/libturso_go.dylib -2ec716186ea285fb2b0dfd8765b6833e62771e240c8e73ac3ee0fa77f09135d9 darwin_arm64/libturso_go.dylib -612ec40fa3115ae723047bd82bf30cba894b3b6b376ff879ab614978eab80f8b linux_musl_amd64/libturso_go.a -584ea88c65b062f58bed256717ddaddc08ca3ee2e87b6c9e4b208d8a1f7710cf linux_musl_arm64/libturso_go.a -b9eafafe344109935cace9fe026a7a03d8074c397797af46c9b3e76db9bbc114 windows_amd64/turso_go.dll +915dca7e1bf5713babda0b8f38dd64b1fa3738015d2149bf601e286bae21a850 linux_amd64/libturso_go.so +a94fb9fd2b841d964bee79feb858f37a454af2838b4ce96bef69165c1123724d linux_arm64/libturso_go.so +730c99847344c18f6fba35cf2f2930f2b26e77fb313f3c931b4ec1635a3d6d28 darwin_amd64/libturso_go.dylib +276ad2958ddbe4232abfd3a61edf934f7a3b6e176206cf7848c1b68a8597203e darwin_arm64/libturso_go.dylib +664a955dd72170c4ebd614c6cfb89dbc7a0011a185ad92c33cd08c6b8a67fa81 linux_musl_amd64/libturso_go.a +7df139930226f1d3c28eac460ba78e8bdd1ccd8c98a4443c5ba64f8ddf7eb6ff linux_musl_arm64/libturso_go.a +37fe09b13d2cd3f46c9fc6f62d2c3c3129867389f614c5d0bded328b0ee1f610 windows_amd64/turso_go.dll diff --git a/libs/darwin_amd64/libturso_go.dylib b/libs/darwin_amd64/libturso_go.dylib index 613746d..da2535e 100644 Binary files a/libs/darwin_amd64/libturso_go.dylib and b/libs/darwin_amd64/libturso_go.dylib differ diff --git a/libs/darwin_amd64/libturso_go.dylib.sha256 b/libs/darwin_amd64/libturso_go.dylib.sha256 index 9c11474..9485d14 100644 --- a/libs/darwin_amd64/libturso_go.dylib.sha256 +++ b/libs/darwin_amd64/libturso_go.dylib.sha256 @@ -1 +1 @@ -7778ae2d0580d92cedbc00e96af8bbb86b3b88733370134b6c4788d389f3e003 +730c99847344c18f6fba35cf2f2930f2b26e77fb313f3c931b4ec1635a3d6d28 diff --git a/libs/darwin_arm64/libturso_go.dylib b/libs/darwin_arm64/libturso_go.dylib index d7fbea5..75d816d 100644 Binary files a/libs/darwin_arm64/libturso_go.dylib and b/libs/darwin_arm64/libturso_go.dylib differ diff --git a/libs/darwin_arm64/libturso_go.dylib.sha256 b/libs/darwin_arm64/libturso_go.dylib.sha256 index 1d80ae6..1f88d14 100644 --- a/libs/darwin_arm64/libturso_go.dylib.sha256 +++ b/libs/darwin_arm64/libturso_go.dylib.sha256 @@ -1 +1 @@ -2ec716186ea285fb2b0dfd8765b6833e62771e240c8e73ac3ee0fa77f09135d9 +276ad2958ddbe4232abfd3a61edf934f7a3b6e176206cf7848c1b68a8597203e diff --git a/libs/linux_amd64/libturso_go.so b/libs/linux_amd64/libturso_go.so index c858f3b..38891f8 100644 Binary files a/libs/linux_amd64/libturso_go.so and b/libs/linux_amd64/libturso_go.so differ diff --git a/libs/linux_amd64/libturso_go.so.sha256 b/libs/linux_amd64/libturso_go.so.sha256 index fdb3081..293d34a 100644 --- a/libs/linux_amd64/libturso_go.so.sha256 +++ b/libs/linux_amd64/libturso_go.so.sha256 @@ -1 +1 @@ -4d9eefabfbe73acd0689338b02ef0cfad60af67a698d941e55347e86b3455fef +915dca7e1bf5713babda0b8f38dd64b1fa3738015d2149bf601e286bae21a850 diff --git a/libs/linux_arm64/libturso_go.so b/libs/linux_arm64/libturso_go.so index 0551742..f420c1c 100644 Binary files a/libs/linux_arm64/libturso_go.so and b/libs/linux_arm64/libturso_go.so differ diff --git a/libs/linux_arm64/libturso_go.so.sha256 b/libs/linux_arm64/libturso_go.so.sha256 index 942c729..761d5a8 100644 --- a/libs/linux_arm64/libturso_go.so.sha256 +++ b/libs/linux_arm64/libturso_go.so.sha256 @@ -1 +1 @@ -79563841b65d818d4a62eecfcc56ebe26ef3d3dc26599996af48a6dddf77ccdd +a94fb9fd2b841d964bee79feb858f37a454af2838b4ce96bef69165c1123724d diff --git a/libs/linux_musl_amd64/libturso_go.a b/libs/linux_musl_amd64/libturso_go.a index 48e93cb..418aa5f 100644 Binary files a/libs/linux_musl_amd64/libturso_go.a and b/libs/linux_musl_amd64/libturso_go.a differ diff --git a/libs/linux_musl_amd64/libturso_go.a.sha256 b/libs/linux_musl_amd64/libturso_go.a.sha256 index a88b507..ab3817d 100644 --- a/libs/linux_musl_amd64/libturso_go.a.sha256 +++ b/libs/linux_musl_amd64/libturso_go.a.sha256 @@ -1 +1 @@ -612ec40fa3115ae723047bd82bf30cba894b3b6b376ff879ab614978eab80f8b +664a955dd72170c4ebd614c6cfb89dbc7a0011a185ad92c33cd08c6b8a67fa81 diff --git a/libs/linux_musl_arm64/libturso_go.a b/libs/linux_musl_arm64/libturso_go.a index c684524..d271a0d 100644 Binary files a/libs/linux_musl_arm64/libturso_go.a and b/libs/linux_musl_arm64/libturso_go.a differ diff --git a/libs/linux_musl_arm64/libturso_go.a.sha256 b/libs/linux_musl_arm64/libturso_go.a.sha256 index 5b3e5b5..64e2ca1 100644 --- a/libs/linux_musl_arm64/libturso_go.a.sha256 +++ b/libs/linux_musl_arm64/libturso_go.a.sha256 @@ -1 +1 @@ -584ea88c65b062f58bed256717ddaddc08ca3ee2e87b6c9e4b208d8a1f7710cf +7df139930226f1d3c28eac460ba78e8bdd1ccd8c98a4443c5ba64f8ddf7eb6ff diff --git a/libs/windows_amd64/turso_go.dll b/libs/windows_amd64/turso_go.dll index 92ec9ca..68b4e0a 100644 Binary files a/libs/windows_amd64/turso_go.dll and b/libs/windows_amd64/turso_go.dll differ diff --git a/libs/windows_amd64/turso_go.dll.sha256 b/libs/windows_amd64/turso_go.dll.sha256 index 9630fae..9ee7b77 100644 --- a/libs/windows_amd64/turso_go.dll.sha256 +++ b/libs/windows_amd64/turso_go.dll.sha256 @@ -1 +1 @@ -b9eafafe344109935cace9fe026a7a03d8074c397797af46c9b3e76db9bbc114 +37fe09b13d2cd3f46c9fc6f62d2c3c3129867389f614c5d0bded328b0ee1f610 diff --git a/rows.go b/rows.go index 8f3d8de..87242fc 100644 --- a/rows.go +++ b/rows.go @@ -139,6 +139,25 @@ func (r *tursoRows) Close() error { } r.mu.Lock() r.closed = true + if r.err == nil { + for { + rc := ResultCode(rowsNext(r.ctx)) + if rc == Row { + continue + } else if rc == Done { + break + } else if rc == ConstraintViolation { + r.err = errors.New("constraint violation") + } else { + if e := r.getError(); e != nil { + r.err = e + } else { + r.err = fmt.Errorf("query failed: %s", rc.String()) + } + } + break + } + } closeRows(r.ctx) r.ctx = 0 r.mu.Unlock() diff --git a/rs_src/lib.rs b/rs_src/lib.rs index 664b774..8f99bf1 100644 --- a/rs_src/lib.rs +++ b/rs_src/lib.rs @@ -7,8 +7,8 @@ use std::{ sync::{Arc, OnceLock}, }; extern crate turso_core; -use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; -use turso_core::{Connection, LimboError}; +use tracing_subscriber::{EnvFilter, layer::SubscriberExt, util::SubscriberInitExt}; +use turso_core::{Connection, DatabaseOpts, LimboError}; use crate::types::ResultCode; @@ -27,13 +27,10 @@ pub unsafe extern "C" fn db_open(path: *const c_char) -> *mut c_void { let path = unsafe { std::ffi::CStr::from_ptr(path) }; let path = path.to_str().unwrap(); let _ = init_tracing(); - let indexes = true; - let mvcc = false; - let encryption = false; - let views = false; - let strict = false; - let Ok((io, conn)) = Connection::from_uri(path, indexes, mvcc, views, strict, encryption) - else { + let opts = DatabaseOpts::new() + .with_indexes(true) + .with_index_method(true); + let Ok((io, conn)) = Connection::from_uri(path, opts) else { panic!("Failed to open connection with path: {path}"); }; TursoConn::new(conn, io).to_ptr() diff --git a/turso_test.go b/turso_test.go index a97bb4d..71042f9 100644 --- a/turso_test.go +++ b/turso_test.go @@ -1022,6 +1022,30 @@ func TestUpsertReturning_databaseSQL_Prepared(t *testing.T) { } } +func TestInsertReturning(t *testing.T) { + db := openMem(t) + _, err := db.Exec(`CREATE TABLE IF NOT EXISTS t (x)`) + if err != nil { + t.Fatalf("create table: %v", err) + } + + var returnedID int64 + if err := db.QueryRow("INSERT INTO t VALUES (1) RETURNING x").Scan(&returnedID); err != nil { + t.Fatalf("queryrow/scan: %v", err) + } + if returnedID != 1 { + t.Fatalf("unexpected returnedId: %v", err) + } + t.Log(returnedID) + if err := db.QueryRow("SELECT * FROM t").Scan(&returnedID); err != nil { + t.Fatalf("queryrow/scan (conflict): %v", err) + } + if returnedID != 1 { + t.Fatalf("unexpected returnedId: %v", err) + } + t.Log(returnedID) +} + func TestUpsertReturning_databaseSQL_Prepared_ArgCountMismatch(t *testing.T) { db := openMem(t) createDatabasesTable(t, db) @@ -1061,7 +1085,6 @@ func TestUpsertReturning_databaseSQL_Prepared_ArgCountMismatch(t *testing.T) { t.Fatal("expected argument count error, got nil") } } - func TestMultiStatementExecution(t *testing.T) { db := openMem(t) @@ -1213,3 +1236,41 @@ func TestMultiStatementExecution(t *testing.T) { } }) } + +func TestIndexMethod(t *testing.T) { + db := openMem(t) + _, err := db.Exec(`CREATE TABLE vectors (e)`) + if err != nil { + t.Fatalf("Failed to create table: %v", err) + } + _, err = db.Exec(`CREATE INDEX vectors_idx ON vectors USING toy_vector_sparse_ivf (e)`) + if err != nil { + t.Fatalf("Failed to create index: %v", err) + } + rows, err := db.Query("EXPLAIN SELECT vector_distance_jaccard(e, x'') as d FROM vectors ORDER BY d LIMIT 10") + if err != nil { + t.Fatalf("Failed to explain query: %v", err) + } + opcodes := make([]string, 0) + for rows.Next() { + var columns [8]any + err = rows.Scan( + &columns[0], + &columns[1], + &columns[2], + &columns[3], + &columns[4], + &columns[5], + &columns[6], + &columns[7], + ) + if err != nil { + t.Fatalf("Failed to read explain row: %v", err) + } + opcodes = append(opcodes, columns[1].(string)) + } + t.Log(opcodes) + if !slices.Contains(opcodes, "IndexMethodQuery") { + t.Fatalf("IndexMethod wasn't used for the query %v: %v", opcodes, err) + } +}