diff --git a/apps/tauri/src-tauri/Cargo.lock b/apps/tauri/src-tauri/Cargo.lock index 9c74f817..6e01866d 100644 --- a/apps/tauri/src-tauri/Cargo.lock +++ b/apps/tauri/src-tauri/Cargo.lock @@ -44,6 +44,12 @@ dependencies = [ "alloc-no-stdlib", ] +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + [[package]] name = "android_system_properties" version = "0.1.6" @@ -213,6 +219,15 @@ dependencies = [ "system-deps", ] +[[package]] +name = "atoi" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" +dependencies = [ + "num-traits", +] + [[package]] name = "atomic-waker" version = "1.1.2" @@ -231,12 +246,24 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "base64" version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5" +[[package]] +name = "base64ct" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" + [[package]] name = "bit-set" version = "0.8.0" @@ -512,6 +539,12 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + [[package]] name = "cookie" version = "0.18.2" @@ -571,6 +604,21 @@ dependencies = [ "libc", ] +[[package]] +name = "crc" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eb8a2a1cd12ab0d987a5d5e825195d372001a4094a0376319d5a0ad71c1ba0d" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "217698eaf96b4a3f0bc4f3662aaa55bdf913cd54d7204591faa790070c6d0853" + [[package]] name = "crc32fast" version = "1.5.5" @@ -589,6 +637,15 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "crossbeam-queue" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03e8bd762f7479489c70ed6c768ddca99d7296857de437a68dcb2a94365b3fae" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.23" @@ -695,6 +752,17 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "der" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] + [[package]] name = "deranged" version = "0.5.9" @@ -732,7 +800,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", + "const-oid", "crypto-common", + "subtle", ] [[package]] @@ -831,7 +901,7 @@ checksum = "fac5fca71e65e94cc718a6e2af65d6e0f9c6027751c2aa562fbb5087fda639bc" dependencies = [ "bit-set 0.8.0", "cssparser 0.37.0", - "foldhash", + "foldhash 0.2.0", "html5ever 0.39.0", "precomputed-hash", "selectors 0.38.0", @@ -846,13 +916,19 @@ checksum = "498c698ac51127148a3984450e51fca7f01805a91d7a1f7a24af0a5f761e3385" dependencies = [ "bit-set 0.11.1", "cssparser 0.38.0", - "foldhash", + "foldhash 0.2.0", "html5ever 0.40.1", "precomputed-hash", "selectors 0.41.0", "tendril", ] +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + [[package]] name = "dpi" version = "0.1.2" @@ -889,6 +965,15 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" +[[package]] +name = "either" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be" +dependencies = [ + "serde", +] + [[package]] name = "embed-resource" version = "3.0.12" @@ -963,6 +1048,17 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "etcetera" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" +dependencies = [ + "cfg-if", + "home", + "windows-sys 0.48.0", +] + [[package]] name = "event-listener" version = "5.4.2" @@ -1037,12 +1133,29 @@ dependencies = [ "zlib-rs", ] +[[package]] +name = "flume" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0e4dd2a88388a1f4ccc7c9ce104604dab68d9f408dc34cd45823d5a9069095" +dependencies = [ + "futures-core", + "futures-sink", + "spin", +] + [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + [[package]] name = "foldhash" version = "0.2.0" @@ -1092,6 +1205,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -1111,6 +1225,17 @@ dependencies = [ "futures-util", ] +[[package]] +name = "futures-intrusive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot", +] + [[package]] name = "futures-io" version = "0.3.34" @@ -1475,6 +1600,17 @@ dependencies = [ "ahash", ] +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash 0.1.5", +] + [[package]] name = "hashbrown" version = "0.17.1" @@ -1490,6 +1626,15 @@ dependencies = [ "hashbrown 0.14.5", ] +[[package]] +name = "hashlink" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" +dependencies = [ + "hashbrown 0.15.5", +] + [[package]] name = "heck" version = "0.4.1" @@ -1514,6 +1659,33 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "home" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d" +dependencies = [ + "windows-sys 0.61.2", +] + [[package]] name = "html5ever" version = "0.39.0" @@ -1986,6 +2158,15 @@ dependencies = [ "serde", ] +[[package]] +name = "lazy_static" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20870f649af7073d53e38067b2a84312175d56ea15217e1b15bc83506ec50afb" +dependencies = [ + "spin", +] + [[package]] name = "libappindicator" version = "0.9.0" @@ -2035,13 +2216,22 @@ dependencies = [ "winapi", ] +[[package]] +name = "libm" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" + [[package]] name = "libredox" version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61ff90caf6077a803a240f62fdbe88645a890bbca49ef8174c3cb0404362171d" dependencies = [ + "bitflags 2.13.2", "libc", + "plain", + "redox_syscall 0.9.5", ] [[package]] @@ -2110,6 +2300,16 @@ dependencies = [ "web_atoms 0.3.0", ] +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + [[package]] name = "memchr" version = "2.8.3" @@ -2219,12 +2419,47 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" +[[package]] +name = "num-bigint-dig" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e661dda6640fad38e827a6d4a310ff4763082116fe217f279885c97f511bb0b7" +dependencies = [ + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand", + "smallvec", + "zeroize", +] + [[package]] name = "num-conv" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441" +[[package]] +name = "num-integer" +version = "0.1.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ce2d95d4b3734dc35aa2f45e1aa22cd416814592a4f9d9205e11affd5b8e10b" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c92800bd69a1eac91786bcfe9da64a897eb72911b8dc3095decbd07429e8048b" +dependencies = [ + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -2232,6 +2467,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", + "libm", ] [[package]] @@ -2535,11 +2771,20 @@ checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.5.18", "smallvec", "windows-link", ] +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + [[package]] name = "percent-encoding" version = "2.3.2" @@ -2669,12 +2914,39 @@ dependencies = [ "futures-io", ] +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + [[package]] name = "pkg-config" version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "plist" version = "1.10.3" @@ -2745,6 +3017,15 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a6394b9e965e73d0a289ee54f589087e2c676aedf60885baf52c76b771e4958" +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + [[package]] name = "precomputed-hash" version = "0.1.1" @@ -2817,14 +3098,18 @@ dependencies = [ name = "querya_desktop_tauri" version = "0.1.0" dependencies = [ + "chrono", "dirs 5.0.1", + "futures-util", "rusqlite", "serde", "serde_json", + "sqlx", "tauri", "tauri-build", "tauri-plugin-dialog", "tauri-plugin-opener", + "tokio", "uuid", ] @@ -2858,6 +3143,36 @@ version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" +[[package]] +name = "rand" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e058c7de0b26af77780c769414d6257830bb240f3c38477dbc2c16e5f54d6d4c" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[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", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.17", +] + [[package]] name = "raw-window-handle" version = "0.6.2" @@ -2873,6 +3188,15 @@ dependencies = [ "bitflags 2.13.2", ] +[[package]] +name = "redox_syscall" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "580c875845b41ecb1564ad1ae4703044cef774145e3d7a94dc2b3fa7c97868fd" +dependencies = [ + "bitflags 2.13.2", +] + [[package]] name = "redox_users" version = "0.4.6" @@ -3003,6 +3327,26 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "rsa" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8573f03f5883dcaebdfcf4725caa1ecb9c15b2ef50c43a07b816e06799bb12d" +dependencies = [ + "const-oid", + "digest", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core", + "signature", + "spki", + "subtle", + "zeroize", +] + [[package]] name = "rusqlite" version = "0.32.1" @@ -3012,7 +3356,7 @@ dependencies = [ "bitflags 2.13.2", "fallible-iterator", "fallible-streaming-iterator", - "hashlink", + "hashlink 0.9.1", "libsqlite3-sys", "smallvec", ] @@ -3051,6 +3395,12 @@ version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + [[package]] name = "same-file" version = "1.0.6" @@ -3258,6 +3608,18 @@ dependencies = [ "serde_core", ] +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + [[package]] name = "serde_with" version = "3.24.0" @@ -3331,6 +3693,17 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "sha1" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a978451301f4db1d02937a4ab3ccce137717b81826e79b7d49ffe3244a13c3b8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "sha2" version = "0.10.9" @@ -3358,6 +3731,16 @@ dependencies = [ "libc", ] +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + [[package]] name = "simd-adler32" version = "0.3.10" @@ -3381,6 +3764,9 @@ name = "smallvec" version = "1.16.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "149309498a5f7334b12ddae0cad8aba81ce785fe91755068867e017cf98fee46" +dependencies = [ + "serde", +] [[package]] name = "socket2" @@ -3407,7 +3793,7 @@ dependencies = [ "objc2-foundation", "objc2-quartz-core", "raw-window-handle", - "redox_syscall", + "redox_syscall 0.5.18", "tracing", "wasm-bindgen", "web-sys", @@ -3440,6 +3826,217 @@ dependencies = [ "system-deps", ] +[[package]] +name = "spin" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3763264f6b73151db08c50ff20d7d8a0b8796e021cdea7ceedad07b80155fa0e" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "sqlx" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fefb893899429669dcdd979aff487bd78f4064e5e7907e4269081e0ef7d97dc" +dependencies = [ + "sqlx-core", + "sqlx-macros", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", +] + +[[package]] +name = "sqlx-core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee6798b1838b6a0f69c007c133b8df5866302197e404e8b6ee8ed3e3a5e68dc6" +dependencies = [ + "base64 0.22.1", + "bytes", + "chrono", + "crc", + "crossbeam-queue", + "either", + "event-listener", + "futures-core", + "futures-intrusive", + "futures-io", + "futures-util", + "hashbrown 0.15.5", + "hashlink 0.10.0", + "indexmap 2.14.2", + "log", + "memchr", + "once_cell", + "percent-encoding", + "serde", + "serde_json", + "sha2", + "smallvec", + "thiserror 2.0.21", + "tokio", + "tokio-stream", + "tracing", + "url", +] + +[[package]] +name = "sqlx-macros" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2d452988ccaacfbf5e0bdbc348fb91d7c8af5bee192173ac3636b5fb6e6715d" +dependencies = [ + "proc-macro2", + "quote", + "sqlx-core", + "sqlx-macros-core", + "syn 2.0.119", +] + +[[package]] +name = "sqlx-macros-core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19a9c1841124ac5a61741f96e1d9e2ec77424bf323962dd894bdb93f37d5219b" +dependencies = [ + "dotenvy", + "either", + "heck 0.5.0", + "hex", + "once_cell", + "proc-macro2", + "quote", + "serde", + "serde_json", + "sha2", + "sqlx-core", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", + "syn 2.0.119", + "tokio", + "url", +] + +[[package]] +name = "sqlx-mysql" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa003f0038df784eb8fecbbac13affe3da23b45194bd57dba231c8f48199c526" +dependencies = [ + "atoi", + "base64 0.22.1", + "bitflags 2.13.2", + "byteorder", + "bytes", + "chrono", + "crc", + "digest", + "dotenvy", + "either", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "generic-array", + "hex", + "hkdf", + "hmac", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "percent-encoding", + "rand", + "rsa", + "serde", + "sha1", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror 2.0.21", + "tracing", + "whoami", +] + +[[package]] +name = "sqlx-postgres" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db58fcd5a53cf07c184b154801ff91347e4c30d17a3562a635ff028ad5deda46" +dependencies = [ + "atoi", + "base64 0.22.1", + "bitflags 2.13.2", + "byteorder", + "chrono", + "crc", + "dotenvy", + "etcetera", + "futures-channel", + "futures-core", + "futures-util", + "hex", + "hkdf", + "hmac", + "home", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "rand", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror 2.0.21", + "tracing", + "whoami", +] + +[[package]] +name = "sqlx-sqlite" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2d12fe70b2c1b4401038055f90f151b78208de1f9f89a7dbfd41587a10c3eea" +dependencies = [ + "atoi", + "chrono", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "libsqlite3-sys", + "log", + "percent-encoding", + "serde", + "serde_urlencoded", + "sqlx-core", + "thiserror 2.0.21", + "tracing", + "url", +] + [[package]] name = "stable_deref_trait" version = "1.2.1" @@ -3500,12 +4097,29 @@ dependencies = [ "quote", ] +[[package]] +name = "stringprep" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", + "unicode-properties", +] + [[package]] name = "strsim" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "swift-rs" version = "1.0.9" @@ -4052,9 +4666,32 @@ dependencies = [ "mio", "pin-project-lite", "socket2", + "tokio-macros", "windows-sys 0.61.2", ] +[[package]] +name = "tokio-macros" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "tokio-stream" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3d06f0b082ba57c26b79407372e57cf2a1e28124f78e9479fe80322cf53420b" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "tokio-util" version = "0.7.20" @@ -4215,6 +4852,7 @@ version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" dependencies = [ + "log", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -4291,12 +4929,33 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "unicode-bidi" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" + [[package]] name = "unicode-ident" version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" +[[package]] +name = "unicode-normalization" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75cd3fb03d5288b3ba9a1ee103ac7e9cbb59f0b03d64f8ddfcc04dd42758a85d" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "993ad287eb20e8ba755312801cfe1413e0f25d604075863acaddca10b04c1833" + [[package]] name = "unicode-segmentation" version = "1.13.3" @@ -4427,6 +5086,12 @@ dependencies = [ "wit-bindgen", ] +[[package]] +name = "wasite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" + [[package]] name = "wasm-bindgen" version = "0.2.130" @@ -4617,6 +5282,16 @@ dependencies = [ "windows-core", ] +[[package]] +name = "whoami" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d4a4db5077702ca3015d3d02d74974948aba2ad9e12ab7df718ee64ccd7e97d" +dependencies = [ + "libredox", + "wasite", +] + [[package]] name = "winapi" version = "0.3.9" @@ -5162,6 +5837,12 @@ dependencies = [ "synstructure", ] +[[package]] +name = "zeroize" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" + [[package]] name = "zerotrie" version = "0.2.5" diff --git a/apps/tauri/src-tauri/Cargo.toml b/apps/tauri/src-tauri/Cargo.toml index 060eec3d..7e38207d 100644 --- a/apps/tauri/src-tauri/Cargo.toml +++ b/apps/tauri/src-tauri/Cargo.toml @@ -21,6 +21,15 @@ serde_json = "1" uuid = { version = "1", features = ["v4", "serde"] } rusqlite = { version = "0.32", features = ["bundled"] } dirs = "5" +tokio = { version = "1", features = ["rt-multi-thread", "macros", "time"] } +sqlx = { version = "0.8", default-features = false, features = [ + "runtime-tokio", + "postgres", + "json", + "chrono", +] } +futures-util = "0.3" +chrono = { version = "0.4", default-features = false, features = ["clock", "std"] } [profile.release] codegen-units = 1 diff --git a/apps/tauri/src-tauri/src/commands.rs b/apps/tauri/src-tauri/src/commands.rs index 952f387c..4a8813c2 100644 --- a/apps/tauri/src-tauri/src/commands.rs +++ b/apps/tauri/src-tauri/src/commands.rs @@ -15,6 +15,26 @@ pub fn db_connect_sqlite( registry.connect(ConnectionConfig::Sqlite { path, id }) } +#[tauri::command] +pub fn db_connect_postgres( + host: String, + port: u16, + database: String, + user: String, + password: Option, + id: Option, + registry: State<'_, ConnectionRegistry>, +) -> Result { + registry.connect(ConnectionConfig::Postgres { + host, + port, + database, + user, + password, + id, + }) +} + #[tauri::command] pub fn profiles_list( store: State<'_, ProfileStore>, @@ -208,7 +228,7 @@ pub fn db_execute_query( registry: State<'_, ConnectionRegistry>, ) -> Result<(), ConnectionError> { let limit = limit.map(|n| n as usize); - registry.execute_sqlite_query(&id, &sql, limit, |ev| { + registry.execute_query(&id, &sql, limit, |ev| { on_event .send(ev) .map_err(|e| ConnectionError::io(format!("query channel closed: {e}"))) diff --git a/apps/tauri/src-tauri/src/connection/manager.rs b/apps/tauri/src-tauri/src/connection/manager.rs index 1c105b8a..796fb89d 100644 --- a/apps/tauri/src-tauri/src/connection/manager.rs +++ b/apps/tauri/src-tauri/src/connection/manager.rs @@ -1,5 +1,6 @@ use super::error::{ConnectionError, ConnectionResult}; use super::id::{ConnectionId, DriverKind}; +use super::postgres::PostgresSession; use super::query::QueryEvent; use super::sqlite::SqliteSession; use serde::{Deserialize, Serialize}; @@ -19,12 +20,16 @@ pub enum ConnectionConfig { #[serde(default)] id: Option, }, - /// Stub until the Postgres adapter epic wires connect. Postgres { host: String, port: u16, database: String, user: String, + /// Session-only secret — never written to ProfileStore (keyring: #1878). + #[serde(default)] + password: Option, + #[serde(default)] + id: Option, }, /// Stub until the MySQL adapter epic wires connect. Mysql { @@ -32,6 +37,10 @@ pub enum ConnectionConfig { port: u16, database: String, user: String, + #[serde(default)] + password: Option, + #[serde(default)] + id: Option, }, } @@ -82,7 +91,7 @@ impl ConnectionRegistry { Self::with_builtin_drivers() } - /// Registry with SQLite opener wired (PG/MySQL return UnsupportedDriver). + /// Registry with SQLite + Postgres openers (MySQL still UnsupportedDriver). pub fn with_builtin_drivers() -> Self { Self::with_opener(|config| match config { ConnectionConfig::Sqlite { path, id } => { @@ -94,6 +103,24 @@ impl ConnectionRegistry { }?; Ok(Arc::new(session) as SessionArc) } + ConnectionConfig::Postgres { + host, + port, + database, + user, + password, + id, + } => { + let session = super::postgres::open_postgres(super::postgres::PostgresConnectParams { + host, + port, + database, + user, + password, + id: id.filter(|s| !s.trim().is_empty()).map(ConnectionId::from), + })?; + Ok(Arc::new(session) as SessionArc) + } other => Err(ConnectionError::UnsupportedDriver { driver: other.driver_kind(), }), @@ -153,6 +180,39 @@ impl ConnectionRegistry { self.with_sqlite(id, |s| s.execute_streaming(sql, limit, emit)) } + pub fn with_postgres( + &self, + id: &ConnectionId, + f: impl FnOnce(&PostgresSession) -> ConnectionResult, + ) -> ConnectionResult { + let session = self.session_arc(id)?; + let pg = session + .as_any() + .downcast_ref::() + .ok_or(ConnectionError::UnsupportedDriver { + driver: session.driver(), + })?; + f(pg) + } + + /// Driver-aware query stream (SQLite + Postgres). + pub fn execute_query( + &self, + id: &ConnectionId, + sql: &str, + limit: Option, + emit: impl FnMut(QueryEvent) -> ConnectionResult<()>, + ) -> ConnectionResult<()> { + match self.driver_of(id) { + Some(DriverKind::Sqlite) => self.execute_sqlite_query(id, sql, limit, emit), + Some(DriverKind::Postgres) => { + self.with_postgres(id, |s| s.execute_streaming(sql, limit, emit)) + } + Some(other) => Err(ConnectionError::UnsupportedDriver { driver: other }), + None => Err(ConnectionError::NotFound { id: id.clone() }), + } + } + /// Driver-agnostic object tree for a live connection (SQLite first). pub fn object_tree( &self, @@ -300,24 +360,42 @@ mod tests { } #[test] - fn registry_postgres_is_unsupported_for_now() { + fn registry_mysql_is_unsupported_for_now() { let reg = ConnectionRegistry::with_builtin_drivers(); let err = reg - .connect(ConnectionConfig::Postgres { + .connect(ConnectionConfig::Mysql { host: "localhost".into(), - port: 5432, + port: 3306, database: "db".into(), user: "u".into(), + password: None, + id: None, }) .unwrap_err(); assert!(matches!( err, ConnectionError::UnsupportedDriver { - driver: DriverKind::Postgres + driver: DriverKind::Mysql } )); } + #[test] + fn registry_postgres_rejects_empty_host() { + let reg = ConnectionRegistry::with_builtin_drivers(); + let err = reg + .connect(ConnectionConfig::Postgres { + host: " ".into(), + port: 5432, + database: "querya".into(), + user: "querya".into(), + password: Some("querya".into()), + id: None, + }) + .unwrap_err(); + assert!(matches!(err, ConnectionError::InvalidConfig { .. })); + } + #[test] fn execute_sqlite_query_streams_via_session() { let path = std::env::temp_dir().join(format!( diff --git a/apps/tauri/src-tauri/src/connection/mod.rs b/apps/tauri/src-tauri/src/connection/mod.rs index cfe07158..c81170a2 100644 --- a/apps/tauri/src-tauri/src/connection/mod.rs +++ b/apps/tauri/src-tauri/src/connection/mod.rs @@ -5,7 +5,10 @@ mod id; mod introspect; mod manager; mod object_tree; +mod postgres; +pub(crate) mod postgres_query; mod query; +mod runtime; mod smoke_slice; mod sqlite; mod sqlite_introspect; diff --git a/apps/tauri/src-tauri/src/connection/postgres.rs b/apps/tauri/src-tauri/src/connection/postgres.rs new file mode 100644 index 00000000..1f5ee17e --- /dev/null +++ b/apps/tauri/src-tauri/src/connection/postgres.rs @@ -0,0 +1,183 @@ +//! Postgres driver via sqlx (connect + disconnect). + +use super::error::{ConnectionError, ConnectionResult}; +use super::id::{ConnectionId, DriverKind}; +use super::manager::ConnectionSession; +use super::runtime; +use sqlx::postgres::{PgConnectOptions, PgPoolOptions, PgSslMode}; +use sqlx::{Pool, Postgres}; +use std::str::FromStr; +use std::sync::{Arc, Mutex}; +use std::time::Duration; + +pub type PgPool = Pool; + +pub struct PostgresSession { + id: ConnectionId, + host: String, + port: u16, + database: String, + user: String, + pool: Arc>>, +} + +impl PostgresSession { + pub fn host(&self) -> &str { + &self.host + } + + pub fn port(&self) -> u16 { + self.port + } + + pub fn database(&self) -> &str { + &self.database + } + + pub fn user(&self) -> &str { + &self.user + } + + pub fn clone_handle(&self) -> Self { + Self { + id: self.id.clone(), + host: self.host.clone(), + port: self.port, + database: self.database.clone(), + user: self.user.clone(), + pool: Arc::clone(&self.pool), + } + } + + pub fn with_pool( + &self, + f: impl FnOnce(&PgPool) -> ConnectionResult, + ) -> ConnectionResult { + let guard = self + .pool + .lock() + .map_err(|_| ConnectionError::io("postgres pool lock poisoned"))?; + let pool = guard + .as_ref() + .ok_or_else(|| ConnectionError::Disconnected { + id: self.id.clone(), + })?; + f(pool) + } + + pub fn execute_streaming( + &self, + sql: &str, + limit: Option, + emit: impl FnMut(super::query::QueryEvent) -> ConnectionResult<()>, + ) -> ConnectionResult<()> { + self.with_pool(|pool| { + super::postgres_query::execute_streaming(pool, sql, limit, None, emit) + }) + } +} + +impl ConnectionSession for PostgresSession { + fn id(&self) -> &ConnectionId { + &self.id + } + + fn driver(&self) -> DriverKind { + DriverKind::Postgres + } + + fn disconnect(&self) -> ConnectionResult<()> { + let pool = { + let mut guard = self + .pool + .lock() + .map_err(|_| ConnectionError::io("postgres pool lock poisoned"))?; + guard.take() + }; + if let Some(pool) = pool { + runtime::block_on(pool.close()); + } + Ok(()) + } + + fn as_any(&self) -> &dyn std::any::Any { + self + } +} + +pub struct PostgresConnectParams { + pub host: String, + pub port: u16, + pub database: String, + pub user: String, + pub password: Option, + pub id: Option, +} + +/// Open a Postgres pool and return a live session. +pub fn open_postgres(params: PostgresConnectParams) -> ConnectionResult { + let host = params.host.trim(); + let database = params.database.trim(); + let user = params.user.trim(); + if host.is_empty() { + return Err(ConnectionError::invalid_config("postgres host is empty")); + } + if database.is_empty() { + return Err(ConnectionError::invalid_config("postgres database is empty")); + } + if user.is_empty() { + return Err(ConnectionError::invalid_config("postgres user is empty")); + } + if params.port == 0 { + return Err(ConnectionError::invalid_config("postgres port is 0")); + } + + // Also accept full URLs in host for power users (`postgres://…`). + let opts = if host.contains("://") { + PgConnectOptions::from_str(host).map_err(|e| { + ConnectionError::invalid_config(format!("invalid postgres url: {e}")) + })? + } else { + let mut opts = PgConnectOptions::new() + .host(host) + .port(params.port) + .username(user) + .database(database) + // No TLS feature wired yet — Disable matches local docker compose. + .ssl_mode(PgSslMode::Disable); + if let Some(pw) = params.password.as_deref() { + opts = opts.password(pw); + } + opts + }; + + let id = params + .id + .filter(|i| !i.as_str().trim().is_empty()) + .unwrap_or_else(ConnectionId::new); + + let pool = runtime::block_on(async { + PgPoolOptions::new() + .max_connections(4) + .acquire_timeout(Duration::from_secs(8)) + .connect_with(opts) + .await + }) + .map_err(|e| ConnectionError::driver(DriverKind::Postgres, e.to_string()))?; + + runtime::block_on(async { + sqlx::query("SELECT 1") + .execute(&pool) + .await + .map_err(|e| ConnectionError::driver(DriverKind::Postgres, e.to_string())) + })?; + + Ok(PostgresSession { + id, + host: host.to_owned(), + port: params.port, + database: database.to_owned(), + user: user.to_owned(), + pool: Arc::new(Mutex::new(Some(pool))), + }) +} diff --git a/apps/tauri/src-tauri/src/connection/postgres_query.rs b/apps/tauri/src-tauri/src/connection/postgres_query.rs new file mode 100644 index 00000000..55fd51e2 --- /dev/null +++ b/apps/tauri/src-tauri/src/connection/postgres_query.rs @@ -0,0 +1,295 @@ +//! Postgres execute + batched row streaming (sqlx). + +use super::error::{ConnectionError, ConnectionResult}; +use super::id::DriverKind; +use super::postgres::PgPool; +use super::query::QueryEvent; +use super::runtime; +use chrono::{DateTime, NaiveDate, NaiveDateTime, Utc}; +use futures_util::TryStreamExt; +use sqlx::postgres::PgRow; +use sqlx::{Column, Executor, Row, TypeInfo, ValueRef}; +use std::time::Instant; + +const DEFAULT_BATCH: usize = 256; +const DEFAULT_LIMIT: usize = 5_000; + +/// Run SQL and emit column / row-batch / done events. Does not buffer the full grid. +pub fn execute_streaming( + pool: &PgPool, + sql: &str, + limit: Option, + batch_size: Option, + mut emit: impl FnMut(QueryEvent) -> ConnectionResult<()>, +) -> ConnectionResult<()> { + let sql = sql.trim(); + if sql.is_empty() { + return Err(ConnectionError::invalid_config("sql is empty")); + } + + let limit = limit.unwrap_or(DEFAULT_LIMIT); + let batch_size = batch_size.unwrap_or(DEFAULT_BATCH).max(1); + let started = Instant::now(); + + runtime::block_on(async { + let mut conn = pool + .acquire() + .await + .map_err(|e| ConnectionError::driver(DriverKind::Postgres, e.to_string()))?; + + let desc = conn + .describe(sql) + .await + .map_err(|e| ConnectionError::driver(DriverKind::Postgres, e.to_string()))?; + + let columns = desc.columns(); + if columns.is_empty() { + let result = sqlx::query(sql) + .execute(&mut *conn) + .await + .map_err(|e| ConnectionError::driver(DriverKind::Postgres, e.to_string()))?; + emit(QueryEvent::Done { + row_count: 0, + truncated: false, + affected_rows: Some(result.rows_affected()), + elapsed_ms: elapsed_ms(started), + })?; + return Ok(()); + } + + let names: Vec = columns.iter().map(|c| c.name().to_owned()).collect(); + let col_count = names.len(); + emit(QueryEvent::Columns { names })?; + + let mut stream = sqlx::query(sql).fetch(&mut *conn); + let mut batch: Vec> = Vec::with_capacity(batch_size); + let mut offset: u64 = 0; + let mut row_count: u64 = 0; + let mut truncated = false; + + while let Some(row) = stream + .try_next() + .await + .map_err(|e| ConnectionError::driver(DriverKind::Postgres, e.to_string()))? + { + if row_count as usize >= limit { + truncated = true; + break; + } + batch.push(pg_row_to_json(&row, col_count)); + row_count += 1; + if batch.len() >= batch_size { + let rows_out = std::mem::take(&mut batch); + let n = rows_out.len() as u64; + emit(QueryEvent::Rows { + rows: rows_out, + offset, + })?; + offset += n; + batch.reserve(batch_size); + } + } + + if !batch.is_empty() { + emit(QueryEvent::Rows { + rows: batch, + offset, + })?; + } + + emit(QueryEvent::Done { + row_count, + truncated, + affected_rows: None, + elapsed_ms: elapsed_ms(started), + })?; + Ok(()) + }) +} + +fn pg_row_to_json(row: &PgRow, col_count: usize) -> Vec { + (0..col_count).map(|i| pg_cell(row, i)).collect() +} + +fn pg_cell(row: &PgRow, i: usize) -> serde_json::Value { + let Ok(raw) = row.try_get_raw(i) else { + return serde_json::Value::Null; + }; + if raw.is_null() { + return serde_json::Value::Null; + } + + let type_info = raw.type_info(); + let type_name = type_info.name(); + + // Typed attempts — first match wins. + if type_name == "BOOL" { + if let Ok(v) = row.try_get::(i) { + return serde_json::Value::Bool(v); + } + } + if matches!(type_name, "INT2" | "INT4" | "INT8") { + if let Ok(v) = row.try_get::(i) { + return serde_json::json!(v); + } + } + if matches!(type_name, "FLOAT4" | "FLOAT8") { + if let Ok(v) = row.try_get::(i) { + return serde_json::Number::from_f64(v) + .map(serde_json::Value::Number) + .unwrap_or(serde_json::Value::Null); + } + } + if matches!(type_name, "JSON" | "JSONB") { + if let Ok(v) = row.try_get::(i) { + return v; + } + } + if type_name == "TIMESTAMPTZ" { + if let Ok(v) = row.try_get::, _>(i) { + return serde_json::Value::String(v.to_rfc3339()); + } + } + if type_name == "TIMESTAMP" { + if let Ok(v) = row.try_get::(i) { + return serde_json::Value::String(v.format("%Y-%m-%dT%H:%M:%S%.f").to_string()); + } + } + if type_name == "DATE" { + if let Ok(v) = row.try_get::(i) { + return serde_json::Value::String(v.to_string()); + } + } + if type_name == "BYTEA" { + if let Ok(v) = row.try_get::, _>(i) { + return serde_json::Value::String(bytes_to_hex(&v)); + } + } + + if let Ok(v) = row.try_get::(i) { + return serde_json::Value::String(v); + } + if let Ok(v) = row.try_get::, _>(i) { + return serde_json::Value::String(bytes_to_hex(&v)); + } + serde_json::Value::String(format!("<{type_name}>")) +} + +fn bytes_to_hex(bytes: &[u8]) -> String { + const HEX: &[u8] = b"0123456789abcdef"; + let mut out = String::with_capacity(bytes.len() * 2); + for &b in bytes { + out.push(HEX[(b >> 4) as usize] as char); + out.push(HEX[(b & 0xf) as usize] as char); + } + out +} + +fn elapsed_ms(started: Instant) -> u64 { + started.elapsed().as_millis() as u64 +} + +#[cfg(test)] +mod tests { + use crate::connection::manager::ConnectionSession; + use crate::connection::postgres::{open_postgres, PostgresConnectParams}; + use crate::connection::query::QueryEvent; + + fn live_params() -> Option { + if std::env::var_os("QUERYA_SKIP_PG").is_some() { + return None; + } + let host = std::env::var("QUERYA_PG_HOST").unwrap_or_else(|_| "127.0.0.1".into()); + let port: u16 = std::env::var("QUERYA_PG_PORT") + .ok() + .and_then(|p| p.parse().ok()) + .unwrap_or(5432); + let database = std::env::var("QUERYA_PG_DB").unwrap_or_else(|_| "querya".into()); + let user = std::env::var("QUERYA_PG_USER").unwrap_or_else(|_| "querya".into()); + let password = std::env::var("QUERYA_PG_PASSWORD").unwrap_or_else(|_| "querya".into()); + Some(PostgresConnectParams { + host, + port, + database, + user, + password: Some(password), + id: None, + }) + } + + #[test] + fn live_postgres_streams_shop_customers() { + let Some(params) = live_params() else { + eprintln!("skip postgres live test (QUERYA_SKIP_PG)"); + return; + }; + let session = match open_postgres(params) { + Ok(s) => s, + Err(e) => { + eprintln!("skip postgres live test: {e}"); + return; + } + }; + + let mut events = Vec::new(); + session + .execute_streaming( + "SELECT id, name FROM shop.customers ORDER BY id LIMIT 5", + Some(5), + |ev| { + events.push(ev); + Ok(()) + }, + ) + .expect("stream"); + + assert!(matches!(events.first(), Some(QueryEvent::Columns { .. }))); + assert!(matches!( + events.last(), + Some(QueryEvent::Done { + row_count: 5, + truncated: false, + .. + }) + )); + let rows: usize = events + .iter() + .filter_map(|e| match e { + QueryEvent::Rows { rows, .. } => Some(rows.len()), + _ => None, + }) + .sum(); + assert_eq!(rows, 5); + session.disconnect().unwrap(); + } + + #[test] + fn live_postgres_dml_reports_affected() { + let Some(params) = live_params() else { + return; + }; + let session = match open_postgres(params) { + Ok(s) => s, + Err(_) => return, + }; + let mut events = Vec::new(); + session + .execute_streaming( + "UPDATE shop.customers SET name = name WHERE id = -1", + None, + |ev| { + events.push(ev); + Ok(()) + }, + ) + .expect("dml"); + assert!(matches!( + events.last(), + Some(QueryEvent::Done { + affected_rows: Some(0), + .. + }) + )); + session.disconnect().unwrap(); + } +} diff --git a/apps/tauri/src-tauri/src/connection/runtime.rs b/apps/tauri/src-tauri/src/connection/runtime.rs new file mode 100644 index 00000000..c91d2bcf --- /dev/null +++ b/apps/tauri/src-tauri/src/connection/runtime.rs @@ -0,0 +1,19 @@ +//! Shared Tokio runtime for sync driver entry points (sqlx Postgres/MySQL). + +use std::sync::OnceLock; +use tokio::runtime::Runtime; + +static RUNTIME: OnceLock = OnceLock::new(); + +pub fn block_on(fut: F) -> F::Output { + RUNTIME + .get_or_init(|| { + tokio::runtime::Builder::new_multi_thread() + .enable_all() + .thread_name("querya-sqlx") + .worker_threads(2) + .build() + .expect("querya tokio runtime") + }) + .block_on(fut) +} diff --git a/apps/tauri/src-tauri/src/lib.rs b/apps/tauri/src-tauri/src/lib.rs index efab3052..a8107627 100644 --- a/apps/tauri/src-tauri/src/lib.rs +++ b/apps/tauri/src-tauri/src/lib.rs @@ -10,9 +10,9 @@ pub use connection::{ pub use profiles::{ConnectionProfile, ProfileStore, ProfileStoreError}; use commands::{ - db_connect_sqlite, db_describe_object, db_disconnect, db_execute_query, db_is_connected, - db_list_children, db_list_columns, db_list_schemas, db_list_tables, db_sqlite_overview, - profiles_connect_sqlite, profiles_delete, profiles_list, profiles_upsert, + db_connect_postgres, db_connect_sqlite, db_describe_object, db_disconnect, db_execute_query, + db_is_connected, db_list_children, db_list_columns, db_list_schemas, db_list_tables, + db_sqlite_overview, profiles_connect_sqlite, profiles_delete, profiles_list, profiles_upsert, }; #[tauri::command] @@ -54,6 +54,7 @@ pub fn run() { app_info, host_platform, db_connect_sqlite, + db_connect_postgres, db_disconnect, db_is_connected, db_list_schemas, diff --git a/apps/tauri/src/api/connection.ts b/apps/tauri/src/api/connection.ts index 2954f096..02568cb0 100644 --- a/apps/tauri/src/api/connection.ts +++ b/apps/tauri/src/api/connection.ts @@ -67,6 +67,24 @@ export async function dbConnectSqlite( return invoke("db_connect_sqlite", { path, id: id ?? null }); } +export async function dbConnectPostgres(opts: { + host: string; + port: number; + database: string; + user: string; + password?: string | null; + id?: string | null; +}): Promise { + return invoke("db_connect_postgres", { + host: opts.host, + port: opts.port, + database: opts.database, + user: opts.user, + password: opts.password ?? null, + id: opts.id ?? null, + }); +} + export async function profilesList(): Promise { return invoke("profiles_list"); }