stoolap-python 0.4.1__tar.gz → 0.5.0b1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/Cargo.lock +15 -213
  2. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/Cargo.toml +2 -2
  3. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/PKG-INFO +1 -1
  4. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/pyproject.toml +1 -1
  5. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/src/database.rs +3 -11
  6. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/src/statement.rs +17 -30
  7. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/src/transaction.rs +19 -29
  8. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/tests/test_named_params.py +14 -1
  9. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/tests/test_types.py +10 -10
  10. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/.github/workflows/ci.yml +0 -0
  11. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/.github/workflows/publish.yml +0 -0
  12. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/.gitignore +0 -0
  13. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/LICENSE +0 -0
  14. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/README.md +0 -0
  15. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/benchmark.py +0 -0
  16. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/python/stoolap/__init__.py +0 -0
  17. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/python/stoolap/__init__.pyi +0 -0
  18. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/src/error.rs +0 -0
  19. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/src/lib.rs +0 -0
  20. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/src/value.rs +0 -0
  21. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/tests/test_async.py +0 -0
  22. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/tests/test_basic.py +0 -0
  23. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/tests/test_edge_cases.py +0 -0
  24. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/tests/test_persistence.py +0 -0
  25. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/tests/test_prepared.py +0 -0
  26. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/tests/test_transactions.py +0 -0
  27. {stoolap_python-0.4.1 → stoolap_python-0.5.0b1}/tests/test_vector.py +0 -0
@@ -39,12 +39,6 @@ dependencies = [
39
39
  "libc",
40
40
  ]
41
41
 
42
- [[package]]
43
- name = "anyhow"
44
- version = "1.0.102"
45
- source = "registry+https://github.com/rust-lang/crates.io-index"
46
- checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"
47
-
48
42
  [[package]]
49
43
  name = "autocfg"
50
44
  version = "1.5.0"
@@ -84,12 +78,6 @@ version = "1.5.0"
84
78
  source = "registry+https://github.com/rust-lang/crates.io-index"
85
79
  checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
86
80
 
87
- [[package]]
88
- name = "bytes"
89
- version = "1.11.1"
90
- source = "registry+https://github.com/rust-lang/crates.io-index"
91
- checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
92
-
93
81
  [[package]]
94
82
  name = "cc"
95
83
  version = "1.2.56"
@@ -144,28 +132,6 @@ dependencies = [
144
132
  "cfg-if",
145
133
  ]
146
134
 
147
- [[package]]
148
- name = "crossbeam"
149
- version = "0.8.4"
150
- source = "registry+https://github.com/rust-lang/crates.io-index"
151
- checksum = "1137cd7e7fc0fb5d3c5a8678be38ec56e819125d8d7907411fe24ccb943faca8"
152
- dependencies = [
153
- "crossbeam-channel",
154
- "crossbeam-deque",
155
- "crossbeam-epoch",
156
- "crossbeam-queue",
157
- "crossbeam-utils",
158
- ]
159
-
160
- [[package]]
161
- name = "crossbeam-channel"
162
- version = "0.5.15"
163
- source = "registry+https://github.com/rust-lang/crates.io-index"
164
- checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2"
165
- dependencies = [
166
- "crossbeam-utils",
167
- ]
168
-
169
135
  [[package]]
170
136
  name = "crossbeam-deque"
171
137
  version = "0.8.6"
@@ -185,15 +151,6 @@ dependencies = [
185
151
  "crossbeam-utils",
186
152
  ]
187
153
 
188
- [[package]]
189
- name = "crossbeam-queue"
190
- version = "0.3.12"
191
- source = "registry+https://github.com/rust-lang/crates.io-index"
192
- checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115"
193
- dependencies = [
194
- "crossbeam-utils",
195
- ]
196
-
197
154
  [[package]]
198
155
  name = "crossbeam-utils"
199
156
  version = "0.8.21"
@@ -231,20 +188,6 @@ dependencies = [
231
188
  "memchr",
232
189
  ]
233
190
 
234
- [[package]]
235
- name = "dashmap"
236
- version = "6.1.0"
237
- source = "registry+https://github.com/rust-lang/crates.io-index"
238
- checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf"
239
- dependencies = [
240
- "cfg-if",
241
- "crossbeam-utils",
242
- "hashbrown 0.14.5",
243
- "lock_api",
244
- "once_cell",
245
- "parking_lot_core",
246
- ]
247
-
248
191
  [[package]]
249
192
  name = "digest"
250
193
  version = "0.10.7"
@@ -316,12 +259,6 @@ dependencies = [
316
259
  "wasm-bindgen",
317
260
  ]
318
261
 
319
- [[package]]
320
- name = "hashbrown"
321
- version = "0.14.5"
322
- source = "registry+https://github.com/rust-lang/crates.io-index"
323
- checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
324
-
325
262
  [[package]]
326
263
  name = "hashbrown"
327
264
  version = "0.16.1"
@@ -333,6 +270,15 @@ dependencies = [
333
270
  "foldhash",
334
271
  ]
335
272
 
273
+ [[package]]
274
+ name = "hashbrown"
275
+ version = "0.17.1"
276
+ source = "registry+https://github.com/rust-lang/crates.io-index"
277
+ checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
278
+ dependencies = [
279
+ "foldhash",
280
+ ]
281
+
336
282
  [[package]]
337
283
  name = "heck"
338
284
  version = "0.5.0"
@@ -363,16 +309,6 @@ dependencies = [
363
309
  "cc",
364
310
  ]
365
311
 
366
- [[package]]
367
- name = "indexmap"
368
- version = "2.13.0"
369
- source = "registry+https://github.com/rust-lang/crates.io-index"
370
- checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017"
371
- dependencies = [
372
- "equivalent",
373
- "hashbrown 0.16.1",
374
- ]
375
-
376
312
  [[package]]
377
313
  name = "indoc"
378
314
  version = "2.0.7"
@@ -398,12 +334,6 @@ dependencies = [
398
334
  "wasm-bindgen",
399
335
  ]
400
336
 
401
- [[package]]
402
- name = "lazy_static"
403
- version = "1.5.0"
404
- source = "registry+https://github.com/rust-lang/crates.io-index"
405
- checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
406
-
407
337
  [[package]]
408
338
  name = "libc"
409
339
  version = "0.2.183"
@@ -427,11 +357,11 @@ checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
427
357
 
428
358
  [[package]]
429
359
  name = "lru"
430
- version = "0.16.3"
360
+ version = "0.18.5"
431
361
  source = "registry+https://github.com/rust-lang/crates.io-index"
432
- checksum = "a1dc47f592c06f33f8e3aea9591776ec7c9f9e4124778ff8a3c3b87159f7e593"
362
+ checksum = "ef9ac18847474e638e3702b76c65d4eb93428471a74778ef0f1be711717f89b5"
433
363
  dependencies = [
434
- "hashbrown 0.16.1",
364
+ "hashbrown 0.17.1",
435
365
  ]
436
366
 
437
367
  [[package]]
@@ -443,15 +373,6 @@ dependencies = [
443
373
  "twox-hash",
444
374
  ]
445
375
 
446
- [[package]]
447
- name = "matchers"
448
- version = "0.2.0"
449
- source = "registry+https://github.com/rust-lang/crates.io-index"
450
- checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9"
451
- dependencies = [
452
- "regex-automata",
453
- ]
454
-
455
376
  [[package]]
456
377
  name = "md-5"
457
378
  version = "0.10.6"
@@ -477,15 +398,6 @@ dependencies = [
477
398
  "autocfg",
478
399
  ]
479
400
 
480
- [[package]]
481
- name = "nu-ansi-term"
482
- version = "0.50.3"
483
- source = "registry+https://github.com/rust-lang/crates.io-index"
484
- checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
485
- dependencies = [
486
- "windows-sys",
487
- ]
488
-
489
401
  [[package]]
490
402
  name = "num-traits"
491
403
  version = "0.2.19"
@@ -501,15 +413,6 @@ version = "1.21.4"
501
413
  source = "registry+https://github.com/rust-lang/crates.io-index"
502
414
  checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
503
415
 
504
- [[package]]
505
- name = "ordered-float"
506
- version = "5.1.0"
507
- source = "registry+https://github.com/rust-lang/crates.io-index"
508
- checksum = "7f4779c6901a562440c3786d08192c6fbda7c1c2060edd10006b05ee35d10f2d"
509
- dependencies = [
510
- "num-traits",
511
- ]
512
-
513
416
  [[package]]
514
417
  name = "parking_lot"
515
418
  version = "0.12.5"
@@ -533,12 +436,6 @@ dependencies = [
533
436
  "windows-link",
534
437
  ]
535
438
 
536
- [[package]]
537
- name = "pin-project-lite"
538
- version = "0.2.17"
539
- source = "registry+https://github.com/rust-lang/crates.io-index"
540
- checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
541
-
542
439
  [[package]]
543
440
  name = "portable-atomic"
544
441
  version = "1.13.1"
@@ -833,15 +730,6 @@ dependencies = [
833
730
  "digest",
834
731
  ]
835
732
 
836
- [[package]]
837
- name = "sharded-slab"
838
- version = "0.1.7"
839
- source = "registry+https://github.com/rust-lang/crates.io-index"
840
- checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
841
- dependencies = [
842
- "lazy_static",
843
- ]
844
-
845
733
  [[package]]
846
734
  name = "shlex"
847
735
  version = "1.3.0"
@@ -856,29 +744,21 @@ checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
856
744
 
857
745
  [[package]]
858
746
  name = "stoolap"
859
- version = "0.4.1"
860
- source = "registry+https://github.com/rust-lang/crates.io-index"
861
- checksum = "a7ebe4615116d74154a6b36d1699793ae43af7c7a7a78739458f99f678456f9e"
747
+ version = "0.4.2"
748
+ source = "git+https://github.com/stoolap/stoolap?branch=main#8fe13cf765ee1a0b4e2e438391296c2f78c3123a"
862
749
  dependencies = [
863
750
  "ahash",
864
- "anyhow",
865
- "bytes",
866
751
  "chrono",
867
752
  "crc32fast",
868
- "crossbeam",
869
753
  "csv",
870
- "dashmap",
871
754
  "getrandom 0.2.17",
872
755
  "getrandom 0.3.4",
873
756
  "hashbrown 0.16.1",
874
- "indexmap",
875
- "js-sys",
876
757
  "libc",
877
758
  "lru",
878
759
  "lz4_flex",
879
760
  "md-5",
880
761
  "memchr",
881
- "ordered-float",
882
762
  "parking_lot",
883
763
  "radsort",
884
764
  "rand",
@@ -892,8 +772,6 @@ dependencies = [
892
772
  "sha2",
893
773
  "smallvec",
894
774
  "thiserror",
895
- "tracing",
896
- "tracing-subscriber",
897
775
  "wasm-bindgen",
898
776
  "web-sys",
899
777
  "web-time",
@@ -902,7 +780,7 @@ dependencies = [
902
780
 
903
781
  [[package]]
904
782
  name = "stoolap-python"
905
- version = "0.4.1"
783
+ version = "0.5.0-beta.1"
906
784
  dependencies = [
907
785
  "chrono",
908
786
  "pyo3",
@@ -946,76 +824,6 @@ dependencies = [
946
824
  "syn",
947
825
  ]
948
826
 
949
- [[package]]
950
- name = "thread_local"
951
- version = "1.1.9"
952
- source = "registry+https://github.com/rust-lang/crates.io-index"
953
- checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185"
954
- dependencies = [
955
- "cfg-if",
956
- ]
957
-
958
- [[package]]
959
- name = "tracing"
960
- version = "0.1.44"
961
- source = "registry+https://github.com/rust-lang/crates.io-index"
962
- checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
963
- dependencies = [
964
- "pin-project-lite",
965
- "tracing-attributes",
966
- "tracing-core",
967
- ]
968
-
969
- [[package]]
970
- name = "tracing-attributes"
971
- version = "0.1.31"
972
- source = "registry+https://github.com/rust-lang/crates.io-index"
973
- checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da"
974
- dependencies = [
975
- "proc-macro2",
976
- "quote",
977
- "syn",
978
- ]
979
-
980
- [[package]]
981
- name = "tracing-core"
982
- version = "0.1.36"
983
- source = "registry+https://github.com/rust-lang/crates.io-index"
984
- checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
985
- dependencies = [
986
- "once_cell",
987
- "valuable",
988
- ]
989
-
990
- [[package]]
991
- name = "tracing-log"
992
- version = "0.2.0"
993
- source = "registry+https://github.com/rust-lang/crates.io-index"
994
- checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
995
- dependencies = [
996
- "log",
997
- "once_cell",
998
- "tracing-core",
999
- ]
1000
-
1001
- [[package]]
1002
- name = "tracing-subscriber"
1003
- version = "0.3.22"
1004
- source = "registry+https://github.com/rust-lang/crates.io-index"
1005
- checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e"
1006
- dependencies = [
1007
- "matchers",
1008
- "nu-ansi-term",
1009
- "once_cell",
1010
- "regex-automata",
1011
- "sharded-slab",
1012
- "smallvec",
1013
- "thread_local",
1014
- "tracing",
1015
- "tracing-core",
1016
- "tracing-log",
1017
- ]
1018
-
1019
827
  [[package]]
1020
828
  name = "twox-hash"
1021
829
  version = "2.1.2"
@@ -1040,12 +848,6 @@ version = "0.2.4"
1040
848
  source = "registry+https://github.com/rust-lang/crates.io-index"
1041
849
  checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
1042
850
 
1043
- [[package]]
1044
- name = "valuable"
1045
- version = "0.1.1"
1046
- source = "registry+https://github.com/rust-lang/crates.io-index"
1047
- checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
1048
-
1049
851
  [[package]]
1050
852
  name = "version_check"
1051
853
  version = "0.9.5"
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "stoolap-python"
3
- version = "0.4.1"
3
+ version = "0.5.0-beta.1"
4
4
  edition = "2021"
5
5
  authors = ["Stoolap Contributors"]
6
6
  license = "Apache-2.0"
@@ -16,7 +16,7 @@ name = "_stoolap"
16
16
  crate-type = ["cdylib"]
17
17
 
18
18
  [dependencies]
19
- stoolap = { version = "0.4.1", default-features = false, features = ["parallel"] }
19
+ stoolap = { git = "https://github.com/stoolap/stoolap", branch = "main", default-features = false, features = ["parallel"] }
20
20
  pyo3 = { version = "0.23", features = ["extension-module"] }
21
21
  chrono = "0.4"
22
22
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: stoolap-python
3
- Version: 0.4.1
3
+ Version: 0.5.0b1
4
4
  Classifier: Development Status :: 4 - Beta
5
5
  Classifier: Intended Audience :: Developers
6
6
  Classifier: License :: OSI Approved :: Apache Software License
@@ -4,7 +4,7 @@ build-backend = "maturin"
4
4
 
5
5
  [project]
6
6
  name = "stoolap-python"
7
- version = "0.4.1"
7
+ version = "0.5.0b1"
8
8
  description = "High-performance Python driver for Stoolap embedded SQL database"
9
9
  readme = "README.md"
10
10
  license = { text = "Apache-2.0" }
@@ -157,19 +157,11 @@ impl Database {
157
157
 
158
158
  // Execute without GIL
159
159
  py.allow_threads(|| {
160
- use stoolap::parser::Parser;
161
- let mut parser = Parser::new(&sql);
162
- let program = parser.parse_program().map_err(|e| {
163
- crate::error::StoolapError::new_err(e.to_string())
164
- })?;
165
- let stmt = program.statements.first().ok_or_else(|| {
166
- crate::error::StoolapError::new_err("No SQL statement found")
167
- })?;
168
-
160
+ let stmt = self.db.prepare(&sql).map_err(to_py)?;
169
161
  let mut tx = self.db.begin().map_err(to_py)?;
170
162
  let mut total = 0i64;
171
163
  for params in all_params {
172
- total += tx.execute_prepared(stmt, params).map_err(to_py)?;
164
+ total += stmt.execute_in(&mut tx, params).map_err(to_py)?;
173
165
  }
174
166
  tx.commit().map_err(to_py)?;
175
167
  Ok(total)
@@ -186,7 +178,7 @@ impl Database {
186
178
  /// Begin a transaction.
187
179
  fn begin(&self, py: Python<'_>) -> PyResult<Transaction> {
188
180
  let tx = py.allow_threads(|| self.db.begin().map_err(to_py))?;
189
- Ok(Transaction::from_tx(tx))
181
+ Ok(Transaction::from_tx(tx, Arc::clone(&self.db)))
190
182
  }
191
183
 
192
184
  /// Close the database connection.
@@ -16,8 +16,7 @@ use pyo3::prelude::*;
16
16
  use pyo3::types::PyList;
17
17
  use std::sync::Arc;
18
18
 
19
- use stoolap::api::Database as ApiDatabase;
20
- use stoolap::CachedPlanRef;
19
+ use stoolap::api::{Database as ApiDatabase, Statement as ApiStatement};
21
20
 
22
21
  use crate::database::{first_row_to_dict, rows_to_dicts, rows_to_raw, to_named_params};
23
22
  use crate::error::to_py;
@@ -29,22 +28,17 @@ use crate::value::{parse_params, BindParams};
29
28
  #[pyclass]
30
29
  pub struct PreparedStatement {
31
30
  db: Arc<ApiDatabase>,
32
- sql_text: String,
33
- plan: CachedPlanRef,
31
+ stmt: ApiStatement,
34
32
  }
35
33
 
36
34
  impl PreparedStatement {
37
35
  pub fn new(db: Arc<ApiDatabase>, sql: &str) -> PyResult<Self> {
38
- let plan = db.cached_plan(sql).map_err(to_py)?;
39
- Ok(Self {
40
- db,
41
- sql_text: sql.to_string(),
42
- plan,
43
- })
36
+ let stmt = db.prepare(sql).map_err(to_py)?;
37
+ Ok(Self { db, stmt })
44
38
  }
45
39
 
46
- pub(crate) fn plan(&self) -> &CachedPlanRef {
47
- &self.plan
40
+ pub(crate) fn inner(&self) -> &ApiStatement {
41
+ &self.stmt
48
42
  }
49
43
  }
50
44
 
@@ -54,11 +48,10 @@ impl PreparedStatement {
54
48
  #[pyo3(signature = (params=None))]
55
49
  fn execute(&self, py: Python<'_>, params: Option<&Bound<'_, PyAny>>) -> PyResult<i64> {
56
50
  let bind = parse_params(params)?;
57
- let plan = self.plan.clone();
58
51
  py.allow_threads(|| match bind {
59
- BindParams::Positional(p) => self.db.execute_plan(&plan, p).map_err(to_py),
52
+ BindParams::Positional(p) => self.stmt.execute(p).map_err(to_py),
60
53
  BindParams::Named(named) => {
61
- self.db.execute_named_plan(&plan, to_named_params(&named)).map_err(to_py)
54
+ self.stmt.execute_named(to_named_params(&named)).map_err(to_py)
62
55
  }
63
56
  })
64
57
  }
@@ -67,11 +60,10 @@ impl PreparedStatement {
67
60
  #[pyo3(signature = (params=None))]
68
61
  fn query(&self, py: Python<'_>, params: Option<&Bound<'_, PyAny>>) -> PyResult<PyObject> {
69
62
  let bind = parse_params(params)?;
70
- let plan = self.plan.clone();
71
63
  let rows = py.allow_threads(|| match bind {
72
- BindParams::Positional(p) => self.db.query_plan(&plan, p).map_err(to_py),
64
+ BindParams::Positional(p) => self.stmt.query(p).map_err(to_py),
73
65
  BindParams::Named(named) => {
74
- self.db.query_named_plan(&plan, to_named_params(&named)).map_err(to_py)
66
+ self.stmt.query_named(to_named_params(&named)).map_err(to_py)
75
67
  }
76
68
  })?;
77
69
  rows_to_dicts(py, rows)
@@ -81,11 +73,10 @@ impl PreparedStatement {
81
73
  #[pyo3(signature = (params=None))]
82
74
  fn query_one(&self, py: Python<'_>, params: Option<&Bound<'_, PyAny>>) -> PyResult<PyObject> {
83
75
  let bind = parse_params(params)?;
84
- let plan = self.plan.clone();
85
76
  let rows = py.allow_threads(|| match bind {
86
- BindParams::Positional(p) => self.db.query_plan(&plan, p).map_err(to_py),
77
+ BindParams::Positional(p) => self.stmt.query(p).map_err(to_py),
87
78
  BindParams::Named(named) => {
88
- self.db.query_named_plan(&plan, to_named_params(&named)).map_err(to_py)
79
+ self.stmt.query_named(to_named_params(&named)).map_err(to_py)
89
80
  }
90
81
  })?;
91
82
  first_row_to_dict(py, rows)
@@ -95,11 +86,10 @@ impl PreparedStatement {
95
86
  #[pyo3(signature = (params=None))]
96
87
  fn query_raw(&self, py: Python<'_>, params: Option<&Bound<'_, PyAny>>) -> PyResult<PyObject> {
97
88
  let bind = parse_params(params)?;
98
- let plan = self.plan.clone();
99
89
  let rows = py.allow_threads(|| match bind {
100
- BindParams::Positional(p) => self.db.query_plan(&plan, p).map_err(to_py),
90
+ BindParams::Positional(p) => self.stmt.query(p).map_err(to_py),
101
91
  BindParams::Named(named) => {
102
- self.db.query_named_plan(&plan, to_named_params(&named)).map_err(to_py)
92
+ self.stmt.query_named(to_named_params(&named)).map_err(to_py)
103
93
  }
104
94
  })?;
105
95
  rows_to_raw(py, rows)
@@ -124,15 +114,12 @@ impl PreparedStatement {
124
114
  }
125
115
  }
126
116
 
127
- let plan = self.plan.clone();
128
-
129
117
  // Execute without GIL
130
118
  py.allow_threads(|| {
131
- let stmt = plan.statement.as_ref();
132
119
  let mut tx = self.db.begin().map_err(to_py)?;
133
120
  let mut total = 0i64;
134
121
  for params in all_params {
135
- total += tx.execute_prepared(stmt, params).map_err(to_py)?;
122
+ total += self.stmt.execute_in(&mut tx, params).map_err(to_py)?;
136
123
  }
137
124
  tx.commit().map_err(to_py)?;
138
125
  Ok(total)
@@ -142,10 +129,10 @@ impl PreparedStatement {
142
129
  /// Get the SQL text of this prepared statement.
143
130
  #[getter]
144
131
  fn sql(&self) -> &str {
145
- &self.sql_text
132
+ self.stmt.sql()
146
133
  }
147
134
 
148
135
  fn __repr__(&self) -> String {
149
- format!("PreparedStatement({:?})", self.sql_text)
136
+ format!("PreparedStatement({:?})", self.stmt.sql())
150
137
  }
151
138
  }
@@ -14,9 +14,9 @@
14
14
 
15
15
  use pyo3::prelude::*;
16
16
  use pyo3::types::PyList;
17
- use std::sync::Mutex;
17
+ use std::sync::{Arc, Mutex};
18
18
 
19
- use stoolap::api::Transaction as ApiTransaction;
19
+ use stoolap::api::{Database as ApiDatabase, Transaction as ApiTransaction};
20
20
 
21
21
  use crate::database::{first_row_to_dict, rows_to_dicts, rows_to_raw, to_named_params};
22
22
  use crate::error::to_py;
@@ -34,12 +34,14 @@ use crate::value::{parse_params, BindParams};
34
34
  #[pyclass]
35
35
  pub struct Transaction {
36
36
  tx: Mutex<Option<ApiTransaction>>,
37
+ db: Arc<ApiDatabase>,
37
38
  }
38
39
 
39
40
  impl Transaction {
40
- pub fn from_tx(tx: ApiTransaction) -> Self {
41
+ pub fn from_tx(tx: ApiTransaction, db: Arc<ApiDatabase>) -> Self {
41
42
  Self {
42
43
  tx: Mutex::new(Some(tx)),
44
+ db,
43
45
  }
44
46
  }
45
47
 
@@ -163,19 +165,11 @@ impl Transaction {
163
165
 
164
166
  // Execute without GIL
165
167
  py.allow_threads(|| {
166
- use stoolap::parser::Parser;
167
- let mut parser = Parser::new(&sql);
168
- let program = parser.parse_program().map_err(|e| {
169
- crate::error::StoolapError::new_err(e.to_string())
170
- })?;
171
- let stmt = program.statements.first().ok_or_else(|| {
172
- crate::error::StoolapError::new_err("No SQL statement found")
173
- })?;
174
-
168
+ let stmt = self.db.prepare(&sql).map_err(to_py)?;
175
169
  self.with_tx(|tx| {
176
170
  let mut total = 0i64;
177
171
  for params in all_params {
178
- total += tx.execute_prepared(stmt, params).map_err(to_py)?;
172
+ total += stmt.execute_in(tx, params).map_err(to_py)?;
179
173
  }
180
174
  Ok(total)
181
175
  })
@@ -191,13 +185,12 @@ impl Transaction {
191
185
  params: Option<&Bound<'_, PyAny>>,
192
186
  ) -> PyResult<i64> {
193
187
  let bind = parse_params(params)?;
194
- let plan = stmt.plan().clone();
188
+ let stmt = stmt.inner();
195
189
  py.allow_threads(|| {
196
- let statement = plan.statement.as_ref();
197
190
  self.with_tx(|tx| match bind {
198
- BindParams::Positional(p) => tx.execute_prepared(statement, p).map_err(to_py),
191
+ BindParams::Positional(p) => stmt.execute_in(tx, p).map_err(to_py),
199
192
  BindParams::Named(named) => {
200
- tx.execute_prepared_named(statement, to_named_params(&named)).map_err(to_py)
193
+ stmt.execute_named_in(tx, to_named_params(&named)).map_err(to_py)
201
194
  }
202
195
  })
203
196
  })
@@ -212,13 +205,12 @@ impl Transaction {
212
205
  params: Option<&Bound<'_, PyAny>>,
213
206
  ) -> PyResult<PyObject> {
214
207
  let bind = parse_params(params)?;
215
- let plan = stmt.plan().clone();
208
+ let stmt = stmt.inner();
216
209
  let rows = py.allow_threads(|| {
217
- let statement = plan.statement.as_ref();
218
210
  self.with_tx(|tx| match bind {
219
- BindParams::Positional(p) => tx.query_prepared(statement, p).map_err(to_py),
211
+ BindParams::Positional(p) => stmt.query_in(tx, p).map_err(to_py),
220
212
  BindParams::Named(named) => {
221
- tx.query_prepared_named(statement, to_named_params(&named)).map_err(to_py)
213
+ stmt.query_named_in(tx, to_named_params(&named)).map_err(to_py)
222
214
  }
223
215
  })
224
216
  })?;
@@ -234,13 +226,12 @@ impl Transaction {
234
226
  params: Option<&Bound<'_, PyAny>>,
235
227
  ) -> PyResult<PyObject> {
236
228
  let bind = parse_params(params)?;
237
- let plan = stmt.plan().clone();
229
+ let stmt = stmt.inner();
238
230
  let rows = py.allow_threads(|| {
239
- let statement = plan.statement.as_ref();
240
231
  self.with_tx(|tx| match bind {
241
- BindParams::Positional(p) => tx.query_prepared(statement, p).map_err(to_py),
232
+ BindParams::Positional(p) => stmt.query_in(tx, p).map_err(to_py),
242
233
  BindParams::Named(named) => {
243
- tx.query_prepared_named(statement, to_named_params(&named)).map_err(to_py)
234
+ stmt.query_named_in(tx, to_named_params(&named)).map_err(to_py)
244
235
  }
245
236
  })
246
237
  })?;
@@ -256,13 +247,12 @@ impl Transaction {
256
247
  params: Option<&Bound<'_, PyAny>>,
257
248
  ) -> PyResult<PyObject> {
258
249
  let bind = parse_params(params)?;
259
- let plan = stmt.plan().clone();
250
+ let stmt = stmt.inner();
260
251
  let rows = py.allow_threads(|| {
261
- let statement = plan.statement.as_ref();
262
252
  self.with_tx(|tx| match bind {
263
- BindParams::Positional(p) => tx.query_prepared(statement, p).map_err(to_py),
253
+ BindParams::Positional(p) => stmt.query_in(tx, p).map_err(to_py),
264
254
  BindParams::Named(named) => {
265
- tx.query_prepared_named(statement, to_named_params(&named)).map_err(to_py)
255
+ stmt.query_named_in(tx, to_named_params(&named)).map_err(to_py)
266
256
  }
267
257
  })
268
258
  })?;
@@ -15,7 +15,7 @@
15
15
  """Named parameter tests across all APIs."""
16
16
 
17
17
  import pytest
18
- from stoolap import Database, AsyncDatabase
18
+ from stoolap import Database, AsyncDatabase, StoolapError
19
19
 
20
20
 
21
21
  @pytest.fixture
@@ -277,6 +277,19 @@ def test_tx_prepared_query_named(db):
277
277
  assert raw["rows"][0][1] == "Alice"
278
278
 
279
279
 
280
+ def test_missing_named_param_is_an_error(db):
281
+ with pytest.raises(StoolapError, match="named parameter :id has no value"):
282
+ db.query("SELECT * FROM users WHERE id = :id", {})
283
+
284
+ stmt = db.prepare("SELECT * FROM users WHERE id = :id")
285
+ with pytest.raises(StoolapError, match="named parameter :id has no value"):
286
+ stmt.query({"name": "Alice"})
287
+
288
+ with db.begin() as tx:
289
+ with pytest.raises(StoolapError, match="named parameter :id has no value"):
290
+ tx.query_prepared(stmt, {})
291
+
292
+
280
293
  def test_tx_prepared_named_rollback(db):
281
294
  stmt = db.prepare("INSERT INTO users VALUES (:id, :name, :email)")
282
295
  with pytest.raises(RuntimeError):
@@ -56,14 +56,14 @@ def test_float_types():
56
56
 
57
57
  def test_text_types():
58
58
  db = Database.open(":memory:")
59
- db.exec("CREATE TABLE t_text (val TEXT)")
59
+ db.exec("CREATE TABLE t_text (id INTEGER PRIMARY KEY, val TEXT)")
60
60
 
61
- db.execute("INSERT INTO t_text VALUES ($1)", [""])
62
- db.execute("INSERT INTO t_text VALUES ($1)", ["hello world"])
63
- db.execute("INSERT INTO t_text VALUES ($1)", ["unicode: \u00e9\u00e0\u00fc\u00f1"])
64
- db.execute("INSERT INTO t_text VALUES ($1)", ["emoji: \U0001f600"])
61
+ db.execute("INSERT INTO t_text VALUES ($1, $2)", [1, ""])
62
+ db.execute("INSERT INTO t_text VALUES ($1, $2)", [2, "hello world"])
63
+ db.execute("INSERT INTO t_text VALUES ($1, $2)", [3, "unicode: \u00e9\u00e0\u00fc\u00f1"])
64
+ db.execute("INSERT INTO t_text VALUES ($1, $2)", [4, "emoji: \U0001f600"])
65
65
 
66
- rows = db.query("SELECT val FROM t_text ORDER BY rowid")
66
+ rows = db.query("SELECT val FROM t_text ORDER BY id")
67
67
  assert rows[0]["val"] == ""
68
68
  assert rows[1]["val"] == "hello world"
69
69
  assert rows[2]["val"] == "unicode: \u00e9\u00e0\u00fc\u00f1"
@@ -73,12 +73,12 @@ def test_text_types():
73
73
 
74
74
  def test_boolean_type():
75
75
  db = Database.open(":memory:")
76
- db.exec("CREATE TABLE t_bool (val BOOLEAN)")
76
+ db.exec("CREATE TABLE t_bool (id INTEGER PRIMARY KEY, val BOOLEAN)")
77
77
 
78
- db.execute("INSERT INTO t_bool VALUES ($1)", [True])
79
- db.execute("INSERT INTO t_bool VALUES ($1)", [False])
78
+ db.execute("INSERT INTO t_bool VALUES ($1, $2)", [1, True])
79
+ db.execute("INSERT INTO t_bool VALUES ($1, $2)", [2, False])
80
80
 
81
- rows = db.query("SELECT val FROM t_bool ORDER BY rowid")
81
+ rows = db.query("SELECT val FROM t_bool ORDER BY id")
82
82
  assert rows[0]["val"] is True
83
83
  assert rows[1]["val"] is False
84
84
  db.close()
File without changes