stoolap-python 0.4.2__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.
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/Cargo.lock +2 -209
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/Cargo.toml +2 -2
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/PKG-INFO +1 -1
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/pyproject.toml +1 -1
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/src/database.rs +3 -11
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/src/statement.rs +17 -30
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/src/transaction.rs +19 -29
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/tests/test_named_params.py +14 -1
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/tests/test_types.py +10 -10
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/.github/workflows/ci.yml +0 -0
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/.github/workflows/publish.yml +0 -0
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/.gitignore +0 -0
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/LICENSE +0 -0
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/README.md +0 -0
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/benchmark.py +0 -0
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/python/stoolap/__init__.py +0 -0
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/python/stoolap/__init__.pyi +0 -0
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/src/error.rs +0 -0
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/src/lib.rs +0 -0
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/src/value.rs +0 -0
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/tests/test_async.py +0 -0
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/tests/test_basic.py +0 -0
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/tests/test_edge_cases.py +0 -0
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/tests/test_persistence.py +0 -0
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/tests/test_prepared.py +0 -0
- {stoolap_python-0.4.2 → stoolap_python-0.5.0b1}/tests/test_transactions.py +0 -0
- {stoolap_python-0.4.2 → 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"
|
|
@@ -372,16 +309,6 @@ dependencies = [
|
|
|
372
309
|
"cc",
|
|
373
310
|
]
|
|
374
311
|
|
|
375
|
-
[[package]]
|
|
376
|
-
name = "indexmap"
|
|
377
|
-
version = "2.13.0"
|
|
378
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
379
|
-
checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017"
|
|
380
|
-
dependencies = [
|
|
381
|
-
"equivalent",
|
|
382
|
-
"hashbrown 0.16.1",
|
|
383
|
-
]
|
|
384
|
-
|
|
385
312
|
[[package]]
|
|
386
313
|
name = "indoc"
|
|
387
314
|
version = "2.0.7"
|
|
@@ -407,12 +334,6 @@ dependencies = [
|
|
|
407
334
|
"wasm-bindgen",
|
|
408
335
|
]
|
|
409
336
|
|
|
410
|
-
[[package]]
|
|
411
|
-
name = "lazy_static"
|
|
412
|
-
version = "1.5.0"
|
|
413
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
414
|
-
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
|
415
|
-
|
|
416
337
|
[[package]]
|
|
417
338
|
name = "libc"
|
|
418
339
|
version = "0.2.183"
|
|
@@ -452,15 +373,6 @@ dependencies = [
|
|
|
452
373
|
"twox-hash",
|
|
453
374
|
]
|
|
454
375
|
|
|
455
|
-
[[package]]
|
|
456
|
-
name = "matchers"
|
|
457
|
-
version = "0.2.0"
|
|
458
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
459
|
-
checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9"
|
|
460
|
-
dependencies = [
|
|
461
|
-
"regex-automata",
|
|
462
|
-
]
|
|
463
|
-
|
|
464
376
|
[[package]]
|
|
465
377
|
name = "md-5"
|
|
466
378
|
version = "0.10.6"
|
|
@@ -486,15 +398,6 @@ dependencies = [
|
|
|
486
398
|
"autocfg",
|
|
487
399
|
]
|
|
488
400
|
|
|
489
|
-
[[package]]
|
|
490
|
-
name = "nu-ansi-term"
|
|
491
|
-
version = "0.50.3"
|
|
492
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
493
|
-
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
|
|
494
|
-
dependencies = [
|
|
495
|
-
"windows-sys",
|
|
496
|
-
]
|
|
497
|
-
|
|
498
401
|
[[package]]
|
|
499
402
|
name = "num-traits"
|
|
500
403
|
version = "0.2.19"
|
|
@@ -510,15 +413,6 @@ version = "1.21.4"
|
|
|
510
413
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
511
414
|
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
512
415
|
|
|
513
|
-
[[package]]
|
|
514
|
-
name = "ordered-float"
|
|
515
|
-
version = "5.1.0"
|
|
516
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
517
|
-
checksum = "7f4779c6901a562440c3786d08192c6fbda7c1c2060edd10006b05ee35d10f2d"
|
|
518
|
-
dependencies = [
|
|
519
|
-
"num-traits",
|
|
520
|
-
]
|
|
521
|
-
|
|
522
416
|
[[package]]
|
|
523
417
|
name = "parking_lot"
|
|
524
418
|
version = "0.12.5"
|
|
@@ -542,12 +436,6 @@ dependencies = [
|
|
|
542
436
|
"windows-link",
|
|
543
437
|
]
|
|
544
438
|
|
|
545
|
-
[[package]]
|
|
546
|
-
name = "pin-project-lite"
|
|
547
|
-
version = "0.2.17"
|
|
548
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
549
|
-
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
|
|
550
|
-
|
|
551
439
|
[[package]]
|
|
552
440
|
name = "portable-atomic"
|
|
553
441
|
version = "1.13.1"
|
|
@@ -842,15 +730,6 @@ dependencies = [
|
|
|
842
730
|
"digest",
|
|
843
731
|
]
|
|
844
732
|
|
|
845
|
-
[[package]]
|
|
846
|
-
name = "sharded-slab"
|
|
847
|
-
version = "0.1.7"
|
|
848
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
849
|
-
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
|
|
850
|
-
dependencies = [
|
|
851
|
-
"lazy_static",
|
|
852
|
-
]
|
|
853
|
-
|
|
854
733
|
[[package]]
|
|
855
734
|
name = "shlex"
|
|
856
735
|
version = "1.3.0"
|
|
@@ -866,28 +745,20 @@ checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
|
|
|
866
745
|
[[package]]
|
|
867
746
|
name = "stoolap"
|
|
868
747
|
version = "0.4.2"
|
|
869
|
-
source = "
|
|
870
|
-
checksum = "88932817e3bb9551486e091b0c6400323086409cca8c35a37c3a68afe089e083"
|
|
748
|
+
source = "git+https://github.com/stoolap/stoolap?branch=main#8fe13cf765ee1a0b4e2e438391296c2f78c3123a"
|
|
871
749
|
dependencies = [
|
|
872
750
|
"ahash",
|
|
873
|
-
"anyhow",
|
|
874
|
-
"bytes",
|
|
875
751
|
"chrono",
|
|
876
752
|
"crc32fast",
|
|
877
|
-
"crossbeam",
|
|
878
753
|
"csv",
|
|
879
|
-
"dashmap",
|
|
880
754
|
"getrandom 0.2.17",
|
|
881
755
|
"getrandom 0.3.4",
|
|
882
756
|
"hashbrown 0.16.1",
|
|
883
|
-
"indexmap",
|
|
884
|
-
"js-sys",
|
|
885
757
|
"libc",
|
|
886
758
|
"lru",
|
|
887
759
|
"lz4_flex",
|
|
888
760
|
"md-5",
|
|
889
761
|
"memchr",
|
|
890
|
-
"ordered-float",
|
|
891
762
|
"parking_lot",
|
|
892
763
|
"radsort",
|
|
893
764
|
"rand",
|
|
@@ -901,8 +772,6 @@ dependencies = [
|
|
|
901
772
|
"sha2",
|
|
902
773
|
"smallvec",
|
|
903
774
|
"thiserror",
|
|
904
|
-
"tracing",
|
|
905
|
-
"tracing-subscriber",
|
|
906
775
|
"wasm-bindgen",
|
|
907
776
|
"web-sys",
|
|
908
777
|
"web-time",
|
|
@@ -911,7 +780,7 @@ dependencies = [
|
|
|
911
780
|
|
|
912
781
|
[[package]]
|
|
913
782
|
name = "stoolap-python"
|
|
914
|
-
version = "0.
|
|
783
|
+
version = "0.5.0-beta.1"
|
|
915
784
|
dependencies = [
|
|
916
785
|
"chrono",
|
|
917
786
|
"pyo3",
|
|
@@ -955,76 +824,6 @@ dependencies = [
|
|
|
955
824
|
"syn",
|
|
956
825
|
]
|
|
957
826
|
|
|
958
|
-
[[package]]
|
|
959
|
-
name = "thread_local"
|
|
960
|
-
version = "1.1.9"
|
|
961
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
962
|
-
checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185"
|
|
963
|
-
dependencies = [
|
|
964
|
-
"cfg-if",
|
|
965
|
-
]
|
|
966
|
-
|
|
967
|
-
[[package]]
|
|
968
|
-
name = "tracing"
|
|
969
|
-
version = "0.1.44"
|
|
970
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
971
|
-
checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
|
|
972
|
-
dependencies = [
|
|
973
|
-
"pin-project-lite",
|
|
974
|
-
"tracing-attributes",
|
|
975
|
-
"tracing-core",
|
|
976
|
-
]
|
|
977
|
-
|
|
978
|
-
[[package]]
|
|
979
|
-
name = "tracing-attributes"
|
|
980
|
-
version = "0.1.31"
|
|
981
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
982
|
-
checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da"
|
|
983
|
-
dependencies = [
|
|
984
|
-
"proc-macro2",
|
|
985
|
-
"quote",
|
|
986
|
-
"syn",
|
|
987
|
-
]
|
|
988
|
-
|
|
989
|
-
[[package]]
|
|
990
|
-
name = "tracing-core"
|
|
991
|
-
version = "0.1.36"
|
|
992
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
993
|
-
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
|
|
994
|
-
dependencies = [
|
|
995
|
-
"once_cell",
|
|
996
|
-
"valuable",
|
|
997
|
-
]
|
|
998
|
-
|
|
999
|
-
[[package]]
|
|
1000
|
-
name = "tracing-log"
|
|
1001
|
-
version = "0.2.0"
|
|
1002
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1003
|
-
checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
|
|
1004
|
-
dependencies = [
|
|
1005
|
-
"log",
|
|
1006
|
-
"once_cell",
|
|
1007
|
-
"tracing-core",
|
|
1008
|
-
]
|
|
1009
|
-
|
|
1010
|
-
[[package]]
|
|
1011
|
-
name = "tracing-subscriber"
|
|
1012
|
-
version = "0.3.22"
|
|
1013
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1014
|
-
checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e"
|
|
1015
|
-
dependencies = [
|
|
1016
|
-
"matchers",
|
|
1017
|
-
"nu-ansi-term",
|
|
1018
|
-
"once_cell",
|
|
1019
|
-
"regex-automata",
|
|
1020
|
-
"sharded-slab",
|
|
1021
|
-
"smallvec",
|
|
1022
|
-
"thread_local",
|
|
1023
|
-
"tracing",
|
|
1024
|
-
"tracing-core",
|
|
1025
|
-
"tracing-log",
|
|
1026
|
-
]
|
|
1027
|
-
|
|
1028
827
|
[[package]]
|
|
1029
828
|
name = "twox-hash"
|
|
1030
829
|
version = "2.1.2"
|
|
@@ -1049,12 +848,6 @@ version = "0.2.4"
|
|
|
1049
848
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1050
849
|
checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
|
|
1051
850
|
|
|
1052
|
-
[[package]]
|
|
1053
|
-
name = "valuable"
|
|
1054
|
-
version = "0.1.1"
|
|
1055
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1056
|
-
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
|
|
1057
|
-
|
|
1058
851
|
[[package]]
|
|
1059
852
|
name = "version_check"
|
|
1060
853
|
version = "0.9.5"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "stoolap-python"
|
|
3
|
-
version = "0.
|
|
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 = {
|
|
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
|
|
|
@@ -157,19 +157,11 @@ impl Database {
|
|
|
157
157
|
|
|
158
158
|
// Execute without GIL
|
|
159
159
|
py.allow_threads(|| {
|
|
160
|
-
|
|
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 +=
|
|
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
|
-
|
|
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
|
|
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
|
|
47
|
-
&self.
|
|
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.
|
|
52
|
+
BindParams::Positional(p) => self.stmt.execute(p).map_err(to_py),
|
|
60
53
|
BindParams::Named(named) => {
|
|
61
|
-
self.
|
|
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.
|
|
64
|
+
BindParams::Positional(p) => self.stmt.query(p).map_err(to_py),
|
|
73
65
|
BindParams::Named(named) => {
|
|
74
|
-
self.
|
|
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.
|
|
77
|
+
BindParams::Positional(p) => self.stmt.query(p).map_err(to_py),
|
|
87
78
|
BindParams::Named(named) => {
|
|
88
|
-
self.
|
|
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.
|
|
90
|
+
BindParams::Positional(p) => self.stmt.query(p).map_err(to_py),
|
|
101
91
|
BindParams::Named(named) => {
|
|
102
|
-
self.
|
|
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 +=
|
|
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
|
-
|
|
132
|
+
self.stmt.sql()
|
|
146
133
|
}
|
|
147
134
|
|
|
148
135
|
fn __repr__(&self) -> String {
|
|
149
|
-
format!("PreparedStatement({:?})", self.
|
|
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
|
-
|
|
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 +=
|
|
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
|
|
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) =>
|
|
191
|
+
BindParams::Positional(p) => stmt.execute_in(tx, p).map_err(to_py),
|
|
199
192
|
BindParams::Named(named) => {
|
|
200
|
-
|
|
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
|
|
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) =>
|
|
211
|
+
BindParams::Positional(p) => stmt.query_in(tx, p).map_err(to_py),
|
|
220
212
|
BindParams::Named(named) => {
|
|
221
|
-
|
|
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
|
|
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) =>
|
|
232
|
+
BindParams::Positional(p) => stmt.query_in(tx, p).map_err(to_py),
|
|
242
233
|
BindParams::Named(named) => {
|
|
243
|
-
|
|
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
|
|
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) =>
|
|
253
|
+
BindParams::Positional(p) => stmt.query_in(tx, p).map_err(to_py),
|
|
264
254
|
BindParams::Named(named) => {
|
|
265
|
-
|
|
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
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|